Skip to content

Commit

Permalink
tests: fix image name repeatability
Browse files Browse the repository at this point in the history
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 <rjohnson@coreweave.com>
  • Loading branch information
robbat2 committed Jun 28, 2024
1 parent dc86ade commit d4e70df
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions tests/e2e.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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
Expand All @@ -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"

Expand Down Expand Up @@ -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}

Expand Down

0 comments on commit d4e70df

Please sign in to comment.