From ecee78036c2ec373d6729ed5b28822e483a25a84 Mon Sep 17 00:00:00 2001 From: Erhan Cagirici Date: Tue, 17 Sep 2024 17:43:53 +0300 Subject: [PATCH] enable e2e tests with server-side apply feature Signed-off-by: Erhan Cagirici --- Makefile | 13 +++++++---- cluster/test/setup.sh | 13 ++++++++++- examples/object/object-ssa-owner.yaml | 1 - examples/object/testhooks/enable-ssa.sh | 5 ---- .../{ => testhooks}/object-ssa-labeler.yaml | 0 examples/object/testhooks/validate-ssa.sh | 23 ++++++++++--------- 6 files changed, 32 insertions(+), 23 deletions(-) delete mode 100755 examples/object/testhooks/enable-ssa.sh rename examples/object/{ => testhooks}/object-ssa-labeler.yaml (100%) diff --git a/Makefile b/Makefile index e3d6a859..618f4496 100644 --- a/Makefile +++ b/Makefile @@ -36,6 +36,7 @@ GOLANGCILINT_VERSION = 1.55.2 # ==================================================================================== # Setup Kubernetes tools KIND_VERSION = v0.22.0 +KUBECTL_VERSION = v1.29.8 UP_VERSION = v0.28.0 UP_CHANNEL = stable USE_HELM3 = true @@ -89,13 +90,15 @@ CROSSPLANE_NAMESPACE = crossplane-system -include build/makelib/local.xpkg.mk -include build/makelib/controlplane.mk -# TODO(turkenh): Add "examples/object/object-ssa-owner.yaml" to the list to test the SSA functionality as part of the e2e tests. -# The test is disabled for now because uptest clears the package cache when the provider restarted with the SSA flag. -# Enable after https://github.com/crossplane/uptest/issues/17 is fixed. +UPTEST_VERSION = v1.1.2 UPTEST_EXAMPLE_LIST ?= "examples/object/object.yaml,examples/object/object-watching.yaml" -uptest: $(UPTEST) $(KUBECTL) $(KUTTL) +UPTEST_SSA_EXAMPLE_LIST ?= "examples/object/object-ssa-owner.yaml" +uptest: $(UPTEST) $(KUBECTL) $(CHAINSAW) $(CROSSPLANE_CLI) @$(INFO) running automated tests - @KUBECTL=$(KUBECTL) KUTTL=$(KUTTL) CROSSPLANE_NAMESPACE=${CROSSPLANE_NAMESPACE} $(UPTEST) e2e "$(UPTEST_EXAMPLE_LIST)" --setup-script=cluster/test/setup.sh || $(FAIL) + @E2E_SSA_ENABLED="false" KUBECTL=$(KUBECTL) CHAINSAW=$(CHAINSAW) CROSSPLANE_CLI=$(CROSSPLANE_CLI) CROSSPLANE_NAMESPACE=${CROSSPLANE_NAMESPACE} $(UPTEST) e2e "$(UPTEST_EXAMPLE_LIST)" --setup-script=cluster/test/setup.sh || $(FAIL) + @$(INFO) running SSA-enabled tests + @E2E_SSA_ENABLED="true" KUBECTL=$(KUBECTL) CHAINSAW=$(CHAINSAW) CROSSPLANE_CLI=$(CROSSPLANE_CLI) CROSSPLANE_NAMESPACE=${CROSSPLANE_NAMESPACE} $(UPTEST) e2e "$(UPTEST_SSA_EXAMPLE_LIST)" --setup-script=cluster/test/setup.sh || $(FAIL) + @$(OK) running SSA-enabled tests @$(OK) running automated tests local-dev: controlplane.up diff --git a/cluster/test/setup.sh b/cluster/test/setup.sh index e22dcef1..e82e4ff9 100755 --- a/cluster/test/setup.sh +++ b/cluster/test/setup.sh @@ -15,4 +15,15 @@ metadata: spec: credentials: source: InjectedIdentity -EOF \ No newline at end of file +EOF + +if [ "${E2E_SSA_ENABLED:-false}" == "true" ]; then + echo "Enabling ssa feature for the provider" + ${KUBECTL} patch deploymentruntimeconfig runtimeconfig-provider-kubernetes --type='json' \ + -p='[{"op":"replace","path":"/spec/deploymentTemplate/spec/template/spec/containers/0/args", "value":["--debug", "--enable-server-side-apply"]}]' + PROVIDER_DEPLOYMENT_NAME="$(${KUBECTL} -n crossplane-system get deployment -o name | grep provider-kubernetes)" + ${KUBECTL} -n crossplane-system wait --for=jsonpath='{.spec.template.spec.containers[0].args[?(@=="--enable-server-side-apply")]}' "$PROVIDER_DEPLOYMENT_NAME" + ${KUBECTL} -n crossplane-system rollout status "$PROVIDER_DEPLOYMENT_NAME" + ${KUBECTL} -n crossplane-system wait --for=jsonpath='{.status.replicas}'="1" "$PROVIDER_DEPLOYMENT_NAME" + ${KUBECTL} -n crossplane-system get pods +fi \ No newline at end of file diff --git a/examples/object/object-ssa-owner.yaml b/examples/object/object-ssa-owner.yaml index 23592b10..da896fe9 100644 --- a/examples/object/object-ssa-owner.yaml +++ b/examples/object/object-ssa-owner.yaml @@ -5,7 +5,6 @@ kind: Object metadata: name: sample-service-owner annotations: - uptest.upbound.io/pre-assert-hook: testhooks/enable-ssa.sh uptest.upbound.io/post-assert-hook: testhooks/validate-ssa.sh uptest.upbound.io/timeout: "60" spec: diff --git a/examples/object/testhooks/enable-ssa.sh b/examples/object/testhooks/enable-ssa.sh deleted file mode 100755 index 1905f941..00000000 --- a/examples/object/testhooks/enable-ssa.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/usr/bin/env bash -set -aeuo pipefail - -echo "Enabling ssa feature for the provider" -${KUBECTL} patch deploymentruntimeconfig runtimeconfig-provider-kubernetes --type='json' -p='[{"op":"replace","path":"/spec/deploymentTemplate/spec/template/spec/containers/0/args", "value":["--debug", "--enable-server-side-apply"]}]' diff --git a/examples/object/object-ssa-labeler.yaml b/examples/object/testhooks/object-ssa-labeler.yaml similarity index 100% rename from examples/object/object-ssa-labeler.yaml rename to examples/object/testhooks/object-ssa-labeler.yaml diff --git a/examples/object/testhooks/validate-ssa.sh b/examples/object/testhooks/validate-ssa.sh index 3b227086..7cadc07c 100755 --- a/examples/object/testhooks/validate-ssa.sh +++ b/examples/object/testhooks/validate-ssa.sh @@ -4,22 +4,23 @@ set -aeuo pipefail # This script is used to validate the ssa feature, triggered by the # uptest framework via `uptest.upbound.io/post-assert-hook`: https://github.com/crossplane/uptest/tree/e64457e2cce153ada54da686c8bf96143f3f6329?tab=readme-ov-file#hooks -LABELER_OBJECT="examples/object/object-ssa-labeler.yaml" -${KUBECTL} apply -f ${LABELER_OBJECT} -${KUBECTL} wait -f ${LABELER_OBJECT} --for condition=ready --timeout=1m +# gets the directory of the this test hook script (POSIX-compliant) +# workaround for determining the filepath of the LABELER_OBJECT +# in chainsaw-based uptest v1.x versions +script_dir=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd -P) -if ! ${KUBECTL} get service sample-service -o jsonpath='{.metadata.annotations}' | grep -v "last-applied-configuration"; then # This annotation should not be present when SSA is enabled +LABELER_OBJECT="$script_dir/object-ssa-labeler.yaml" +${KUBECTL} apply -f "${LABELER_OBJECT}" +${KUBECTL} wait -f "${LABELER_OBJECT}" --for condition=ready --timeout=1m + +if ${KUBECTL} get service sample-service -o jsonpath='{.metadata.annotations}' | grep "last-applied-configuration"; then # This annotation should not be present when SSA is enabled echo "SSA validation failed! Annotation 'last-applied-configuration' should not exist when SSA is enabled!" - #exit 1 + exit 1 fi if ! (${KUBECTL} get service sample-service -o jsonpath='{.metadata.labels.some-key}' | grep -q "some-value" && ${KUBECTL} get service sample-service -o jsonpath='{.metadata.labels.another-key}' | grep -q "another-value"); then echo "SSA validation failed! Labels 'some-key' and 'another-key' from both Objects should exist with values 'some-value' and 'another-value' respectively!" - #exit 1 + exit 1 fi echo "Successfully validated the SSA feature!" -${KUBECTL} delete -f ${LABELER_OBJECT} - -echo "Disabling SSA feature for the provider" -${KUBECTL} patch deploymentruntimeconfig runtimeconfig-provider-kubernetes --type='json' -p='[{"op":"replace","path":"/spec/deploymentTemplate/spec/template/spec/containers/0/args", "value":["--debug"]}]' - +${KUBECTL} delete -f "${LABELER_OBJECT}"