Skip to content

Commit

Permalink
enable e2e tests with server-side apply feature
Browse files Browse the repository at this point in the history
Signed-off-by: Erhan Cagirici <[email protected]>
  • Loading branch information
erhancagirici committed Sep 17, 2024
1 parent c5b4b82 commit ecee780
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 23 deletions.
13 changes: 8 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
13 changes: 12 additions & 1 deletion cluster/test/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,15 @@ metadata:
spec:
credentials:
source: InjectedIdentity
EOF
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
1 change: 0 additions & 1 deletion examples/object/object-ssa-owner.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
5 changes: 0 additions & 5 deletions examples/object/testhooks/enable-ssa.sh

This file was deleted.

File renamed without changes.
23 changes: 12 additions & 11 deletions examples/object/testhooks/validate-ssa.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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}"

0 comments on commit ecee780

Please sign in to comment.