From d4e70dfdf2364ad1760c96918d74630215f57217 Mon Sep 17 00:00:00 2001 From: "Robin H. Johnson" Date: Fri, 28 Jun 2024 15:56:13 -0700 Subject: [PATCH] tests: fix image name repeatability tests/e2e.sh tries to update manifests for several resources as part of testing. Repeated runs may not correctly update the manifests on subsequent passes. Ensure it's updated each time, and reset the state back to clean. Signed-off-by: Robin H. Johnson --- tests/e2e.sh | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/tests/e2e.sh b/tests/e2e.sh index 4cb89f6336..4a1cafcfc5 100755 --- a/tests/e2e.sh +++ b/tests/e2e.sh @@ -42,6 +42,10 @@ function finish() { kill %1 || true kubectl delete -f examples/standard/ || true kubectl delete -f tests/manifests/ || true + # Ensure this is a clean state before next tests + mv -f ./examples/standard/deployment.yaml{.bak,} || true + mv -f ./examples/daemonsetsharding/deployment.yaml{.bak,} || true + mv -f ./examples/daemonsetsharding/daemonset.yaml{.bak,} || true } function setup_kind() { @@ -95,8 +99,8 @@ function kube_state_metrics_up() { fi } function test_daemonset() { - sed -i "s|${KUBE_STATE_METRICS_CURRENT_IMAGE_NAME}:v.*|${KUBE_STATE_METRICS_IMAGE_NAME}:${KUBE_STATE_METRICS_IMAGE_TAG}|g" ./examples/daemonsetsharding/deployment.yaml - sed -i "s|${KUBE_STATE_METRICS_CURRENT_IMAGE_NAME}:v.*|${KUBE_STATE_METRICS_IMAGE_NAME}:${KUBE_STATE_METRICS_IMAGE_TAG}|g" ./examples/daemonsetsharding/daemonset.yaml + set_image_name ./examples/daemonsetsharding/deployment.yaml + set_image_name ./examples/daemonsetsharding/daemonset.yaml kubectl get deployment -n kube-system kubectl create -f ./examples/daemonsetsharding @@ -119,6 +123,16 @@ function test_daemonset() { sleep 20 } +set_image_name() { + f=$1 + # Change the stock name as well as the temporary name, to the new value. + local new=${KUBE_STATE_METRICS_IMAGE_NAME}:${KUBE_STATE_METRICS_IMAGE_TAG} + sed -i.bak \ + -e "s|image: ${KUBE_STATE_METRICS_CURRENT_IMAGE_NAME}:v.*|image: ${new}|g" \ + -e "s|image: ${KUBE_STATE_METRICS_IMAGE_NAME}:v.*|image: ${new}|g" \ + "${f}" +} + is_kube_running="false" @@ -152,7 +166,7 @@ echo "local kube-state-metrics image tag: $KUBE_STATE_METRICS_IMAGE_TAG" kind load docker-image "${KUBE_STATE_METRICS_IMAGE_NAME}:${KUBE_STATE_METRICS_IMAGE_TAG}" # update kube-state-metrics image tag in deployment.yaml -sed -i.bak "s|${KUBE_STATE_METRICS_CURRENT_IMAGE_NAME}:v.*|${KUBE_STATE_METRICS_IMAGE_NAME}:${KUBE_STATE_METRICS_IMAGE_TAG}|g" ./examples/standard/deployment.yaml +set_image_name ./examples/standard/deployment.yaml mkdir -p ${KUBE_STATE_METRICS_LOG_DIR}