diff --git a/test/kubernetes/run.sh b/test/kubernetes/run.sh index 03fad0fc..8487a225 100755 --- a/test/kubernetes/run.sh +++ b/test/kubernetes/run.sh @@ -10,3 +10,8 @@ DIR="$(cd "$(dirname "$0")" && pwd)" "$REPO_ROOT"/test/workloads/init.sh "$DIR"/test-deployment.sh "$DIR"/test-daemonset.sh + +kubectl -n test delete deploy podinfo +kubectl -n test delete svc podinfo-svc +kubectl apply -f ${REPO_ROOT}/test/workloads/deployment.yaml -n test +"$DIR"/test-hpa.sh diff --git a/test/kubernetes/test-hpa.sh b/test/kubernetes/test-hpa.sh new file mode 100755 index 00000000..7b3773df --- /dev/null +++ b/test/kubernetes/test-hpa.sh @@ -0,0 +1,165 @@ +#!/usr/bin/env bash + +set -o errexit + +REPO_ROOT=$(git rev-parse --show-toplevel) + +cat <>> Waiting for primary to be ready' +retries=50 +count=0 +ok=false +until ${ok}; do + kubectl -n test get canary/podinfo | grep 'Initialized' && ok=true || ok=false + sleep 5 + count=$(($count + 1)) + if [[ ${count} -eq ${retries} ]]; then + kubectl -n flagger-system logs deployment/flagger + echo "No more retries left" + exit 1 + fi +done + +echo '✔ Canary initialization test passed' + +echo '>>> Waiting for primary HPA to be created' +retries=10 +count=0 +ok=false +until ${ok}; do + kubectl -n test get hpa podinfo-primary && ok=true || ok=false + sleep 2 + count=$(($count + 1)) + if [[ ${count} -eq ${retries} ]]; then + kubectl -n flagger-system logs deployment/flagger + echo "No more retries left" + echo '⨯ Primary HPA not found' + exit 1 + fi +done + +echo '✔ Primary HPA successfully reconciled' + +# update the target hpa resource utilization +kubectl -n test patch hpa podinfo --type json --patch='[ { "op": "replace", "path": "/spec/metrics/0/resource/target/averageUtilization", "value": 50 } ]' + +echo '>>> Triggering canary deployment' +kubectl -n test set image deployment/podinfo podinfod=ghcr.io/stefanprodan/podinfo:6.0.1 + +echo '>>> Waiting for canary promotion' +retries=50 +count=0 +ok=false +until ${ok}; do + kubectl -n test describe deployment/podinfo-primary | grep '6.0.1' && ok=true || ok=false + sleep 10 + kubectl -n flagger-system logs deployment/flagger --tail 1 + count=$(($count + 1)) + if [[ ${count} -eq ${retries} ]]; then + kubectl -n test describe deployment/podinfo + kubectl -n test describe deployment/podinfo-primary + kubectl -n flagger-system logs deployment/flagger + echo "No more retries left" + exit 1 + fi +done + +echo '✔ Canary promotion test passed' + +util=$(kubectl -n test get hpa podinfo -ojsonpath='{.spec.metrics[0].resource.target.averageUtilization}' | xargs) +if [[ ${util} -eq 50 ]]; then + echo '✔ Primary HPA successfully reconciled' +else + echo "⨯ Unexpected primary HPA resource target average utilization value: ${util}, expected: 50" + exit 1 +fi