diff --git a/.circleci/config.yml b/.circleci/config.yml index 57e302fb..7102f0ff 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -1,7 +1,7 @@ version: 2.1 orbs: - rok8s: fairwinds/rok8s-scripts@11 + rok8s: fairwinds/rok8s-scripts@13 oss-docs: fairwinds/oss-docs@0 references: @@ -18,7 +18,7 @@ references: e2e_configuration: &e2e_configuration pre_script: e2e/pre.sh script: e2e/test.sh - command_runner_image: quay.io/reactiveops/ci-images:v12-buster + command_runner_image: quay.io/reactiveops/ci-images:v13-buster enable_docker_layer_caching: true attach-workspace: true requires: diff --git a/e2e/pre.sh b/e2e/pre.sh index e15831c8..d53a5d1f 100644 --- a/e2e/pre.sh +++ b/e2e/pre.sh @@ -2,7 +2,7 @@ set -e -wget -O /usr/local/bin/yq "https://github.com/mikefarah/yq/releases/download/2.4.0/yq_linux_amd64" +wget -O /usr/local/bin/yq "https://github.com/mikefarah/yq/releases/download/v4.35.1/yq_linux_amd64" chmod +x /usr/local/bin/yq if [ -z "$CI_SHA1" ]; then @@ -26,8 +26,10 @@ echo "** END LOADING IMAGE **" echo "********************************************************************" printf "\n\n" -yq w -i deploy/3_deployment.yaml 'spec.template.spec.containers[0].image' "quay.io/reactiveops/rbac-manager:${CI_SHA1}-amd64" -yq w -i deploy/3_deployment.yaml 'spec.template.spec.containers[0].imagePullPolicy' "IfNotPresent" +export newImage=quay.io/reactiveops/rbac-manager:${CI_SHA1}-amd64 +yq -i '.spec.template.spec.containers[0].image = env(newImage)' deploy/3_deployment.yaml +yq -i '.spec.template.spec.containers[0].imagePullPolicy = "IfNotPresent"' deploy/3_deployment.yaml cat deploy/3_deployment.yaml docker cp deploy e2e-command-runner:/ +docker cp e2e/rbacdefinition e2e-command-runner:/ diff --git a/e2e/rbacdefinition/cluterrolebindings/cleanup.sh b/e2e/rbacdefinition/cluterrolebindings/cleanup.sh new file mode 100644 index 00000000..dc175b27 --- /dev/null +++ b/e2e/rbacdefinition/cluterrolebindings/cleanup.sh @@ -0,0 +1,2 @@ +kubectl delete clusterrole test-rbac-manager --ignore-not-found +kubectl delete RBACDefinition rbac-manager-definition --ignore-not-found \ No newline at end of file diff --git a/e2e/rbacdefinition/cluterrolebindings/main.sh b/e2e/rbacdefinition/cluterrolebindings/main.sh new file mode 100644 index 00000000..18726ef7 --- /dev/null +++ b/e2e/rbacdefinition/cluterrolebindings/main.sh @@ -0,0 +1,21 @@ +BASE_DIR=$(dirname $BASH_SOURCE) + +printf "\n\n" +echo "********************************************************************" +echo "** Test clusterrolebindings **" +echo "********************************************************************" +printf "\n\n" + +# Execute the setup, then execute the tests just if the setup contains no errors. +# Finally always execute the cleanup and return the whole error of the steps +error=$((0)) +bash "$BASE_DIR/setup.sh" +error=$(( error | $? )) + +if [ $error -eq 0 ]; then +bash "$BASE_DIR/tests.sh" +error=$(( error | $? )) +fi + +bash "$BASE_DIR/cleanup.sh" +exit $(( error | $? )) diff --git a/e2e/rbacdefinition/cluterrolebindings/setup.sh b/e2e/rbacdefinition/cluterrolebindings/setup.sh new file mode 100644 index 00000000..170df18a --- /dev/null +++ b/e2e/rbacdefinition/cluterrolebindings/setup.sh @@ -0,0 +1,16 @@ +kubectl create clusterrole test-rbac-manager --verb="create" --resource=deployment + +cat <&2 echo "error: The Service account must exists" +fi +kubectl delete -n rbac-manager serviceaccount/test-rbac-manager +kubectl get -n rbac-manager serviceaccount/test-rbac-manager +error=$(( error | $? )) +if [ "$error" -eq 1 ]; then + >&2 echo "error: The Service account must be recreated" +fi + +# ImagePullSecret is created +contents=$(kubectl get -n rbac-manager serviceaccount/test-rbac-manager -oyaml | yq 'select(.imagePullSecrets[] | .name == "robot-secret")') +if [ -z "$contents" ]; then + error=$(( error | 1 )) +fi +if [ "$error" -eq 1 ]; then + >&2 echo "error: ImagePullSecret \"robot-secret\" must exists" +fi + +# ImagePullSecret is re-created if deleted +cat <&2 echo "error: ImagePullSecret \"robot-secret\" must be re-created" +fi + +# If ImagePullSecret is added it should not be removed + +cat <&2 echo "error: ImagePullSecret \"new-secret-name\" must be kept" +fi + +exit $error \ No newline at end of file diff --git a/e2e/test.sh b/e2e/test.sh index 52a637a2..dfdabfe7 100755 --- a/e2e/test.sh +++ b/e2e/test.sh @@ -1,6 +1,6 @@ #!/bin/bash - +BASE_DIR=$(dirname $BASH_SOURCE) printf "\n\n" echo "**************************" @@ -20,36 +20,7 @@ printf "\n\n" kubectl apply -f deploy/ kubectl -n rbac-manager wait deployment/rbac-manager --timeout=120s --for condition=available - -printf "\n\n" -echo "********************************************************************" -echo "** Test rbacDefinition **" -echo "********************************************************************" -printf "\n\n" -kubectl create clusterrole test-rbac-manager --verb="create" --resource=deployment - -cat <