Skip to content

Commit

Permalink
Refactor in e2e script and pre-apply func
Browse files Browse the repository at this point in the history
Created a function to run secure sidecar registry with cert
and calling that function from all tests to remove duplication
  • Loading branch information
piyush-garg committed Apr 8, 2021
1 parent 5edf40d commit 3688c2b
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 38 deletions.
14 changes: 1 addition & 13 deletions task/buildah/0.2/tests/pre-apply-task-hook.sh
Original file line number Diff line number Diff line change
@@ -1,18 +1,6 @@
#!/usr/bin/env bash

TMD=$(mktemp -d)

# Generate SSL Certificate
openssl req -newkey rsa:4096 -nodes -sha256 -keyout "${TMD}"/ca.key -x509 -days 365 \
-addext "subjectAltName = DNS:registry" \
-out "${TMD}"/ca.crt -subj "/C=FR/ST=IDF/L=Paris/O=Tekton/OU=Catalog/CN=registry"

# Create a configmap from these certs
kubectl create -n "${tns}" configmap sslcert \
--from-file=ca.crt="${TMD}"/ca.crt --from-file=ca.key="${TMD}"/ca.key

# Add a secure internal registry as sidecar
kubectl create -n "${tns}" -f task/buildah/0.2/tests/internal-registry/internal-registry.yaml
add_sidecar_secure_registry

# Add git-clone
add_task git-clone latest
14 changes: 1 addition & 13 deletions task/jib-maven/0.3/tests/pre-apply-task-hook.sh
Original file line number Diff line number Diff line change
@@ -1,18 +1,6 @@
#!/usr/bin/env bash

TMD=$(mktemp -d)

# Generate SSL Certificate
openssl req -newkey rsa:4096 -nodes -sha256 -keyout "${TMD}"/ca.key -x509 -days 365 \
-addext "subjectAltName = DNS:registry" \
-out "${TMD}"/ca.crt -subj "/C=FR/ST=IDF/L=Paris/O=Tekton/OU=Catalog/CN=registry"

# Create a configmap from these certs
kubectl create -n "${tns}" configmap sslcert \
--from-file=ca.crt="${TMD}"/ca.crt --from-file=ca.key="${TMD}"/ca.key

# Add a secure internal registry as sidecar
kubectl create -n "${tns}" -f task/jib-maven/0.3/tests/internal-registry/internal-registry.yaml
add_sidecar_secure_registry

# Add git-clone
add_task git-clone latest
13 changes: 1 addition & 12 deletions task/s2i/0.2/tests/pre-apply-task-hook.sh
Original file line number Diff line number Diff line change
@@ -1,17 +1,6 @@
#!/usr/bin/env bash

TMD=$(mktemp -d)

# Generate SSL Certificate
openssl req -newkey rsa:4096 -nodes -sha256 -keyout "${TMD}"/ca.key -x509 -days 365 \
-out "${TMD}"/ca.crt -subj "/C=FR/ST=IDF/L=Paris/O=Tekton/OU=Catalog/CN=registry"

# Create a configmap from these certs
kubectl create -n "${tns}" configmap sslcert \
--from-file=ca.crt="${TMD}"/ca.crt --from-file=ca.key="${TMD}"/ca.key

# Add a secure internal registry as sidecar
kubectl create -n "${tns}" -f task/buildah/0.2/tests/internal-registry/internal-registry.yaml
add_sidecar_secure_registry

# Add git-clone
add_task git-clone latest
17 changes: 17 additions & 0 deletions test/e2e-common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,22 @@ function add_sidecar_registry() {
add_sidecars ${1} '{"image":"registry", "name": "registry"}'
}

function add_sidecar_secure_registry() {
TMD=$(mktemp -d)

# Generate SSL Certificate
openssl req -newkey rsa:4096 -nodes -sha256 -keyout "${TMD}"/ca.key -x509 -days 365 \
-addext "subjectAltName = DNS:registry" \
-out "${TMD}"/ca.crt -subj "/C=FR/ST=IDF/L=Paris/O=Tekton/OU=Catalog/CN=registry"

# Create a configmap from these certs
kubectl create -n "${tns}" configmap sslcert \
--from-file=ca.crt="${TMD}"/ca.crt --from-file=ca.key="${TMD}"/ca.key

# Add a secure internal registry as sidecar
kubectl create -n "${tns}" -f ${taskdir}/tests/internal-registry/internal-registry.yaml
}

function add_task() {
local array path_version task
task=${1}
Expand Down Expand Up @@ -210,6 +226,7 @@ function test_task_creation() {

# In case of rerun it's fine to ignore this error
${KUBECTL_CMD} create namespace ${tns} >/dev/null 2>/dev/null || :
${KUBECTL_CMD} label namespace ${tns} operator.tekton.dev/disable-proxy=true

# Install the task itself first. We can only have one YAML file
yaml=$(printf ${taskdir}/*.yaml)
Expand Down

0 comments on commit 3688c2b

Please sign in to comment.