From daaaa194da7369885a011bbb52c863f86bae1d0c Mon Sep 17 00:00:00 2001 From: Christian Schlotter Date: Thu, 4 Apr 2024 19:28:11 +0200 Subject: [PATCH] default KUBERNETES_VERSION if not set --- scripts/ci-e2e-lib.sh | 44 +++++++++++++++++++++++++++++-------- scripts/ci-e2e.sh | 1 + test/e2e/config/docker.yaml | 2 +- 3 files changed, 37 insertions(+), 10 deletions(-) diff --git a/scripts/ci-e2e-lib.sh b/scripts/ci-e2e-lib.sh index 6457e26f4e45..2080c9cfb837 100644 --- a/scripts/ci-e2e-lib.sh +++ b/scripts/ci-e2e-lib.sh @@ -34,6 +34,41 @@ capi:buildDockerImages () { fi } +# k8s::prepareKindestImagesVariables defaults the environment variables KUBERNETES_VERSION, +# KUBERNETES_VERSION_UPGRADE_TO and KUBERNETES_VERSION_LATEST_CI depending on what +# is set in GINKGO_FOCUS. +# Note: We do this to ensure that the kindest/node image gets built if it does +# not already exist, e.g. for pre-releases, but only if necessary. +k8s::prepareKindestImagesVariables() { + # Always default KUBERNETES_VERSION to the value in the e2e config. + + if [[ ${GINKGO_FOCUS:-} == *"K8s-Install-ci-latest"* ]]; then + # If the test focuses on [K8s-Install-ci-latest], only default KUBERNETES_VERSION_LATEST_CI + # to the value in the e2e config and only if it is not set. + # Note: We do this because we want to specify KUBERNETES_VERSION_LATEST_CI *only* in the e2e config. + if [[ -z "${KUBERNETES_VERSION_LATEST_CI:-}" ]]; then + KUBERNETES_VERSION_LATEST_CI=$(grep KUBERNETES_VERSION_LATEST_CI: < "$E2E_CONF_FILE" | awk -F'"' '{ print $2}') + echo "Defaulting KUBERNETES_VERSION_LATEST_CI to ${KUBERNETES_VERSION_LATEST_CI} to trigger image build (because env var is not set)" + fi + elif [[ ${GINKGO_FOCUS:-} != *"K8s-Upgrade"* ]]; then + # In any other case which is not [K8s-Upgrade], default KUBERNETES_VERSION if it is not set to make sure + # the corresponding kindest/node image exists. + if [[ -z "${KUBERNETES_VERSION:-}" ]]; then + KUBERNETES_VERSION=$(grep KUBERNETES_VERSION: < "$E2E_CONF_FILE" | awk -F'"' '{ print $2}') + echo "Defaulting KUBERNETES_VERSION to ${KUBERNETES_VERSION} to trigger image build (because env var is not set)" + fi + + # Tests not focusing on [PR-Blocking] or [K8s-Install], also run upgrade tests so default + # KUBERNETES_VERSION_UPGRADE_TO to the value in the e2e config if it is not set. + if [[ ${GINKGO_FOCUS:-} != *"PR-Blocking"* ]] && [[ ${GINKGO_FOCUS:-} != *"K8s-Install"* ]]; then + if [[ -z "${KUBERNETES_VERSION_UPGRADE_TO:-}" ]]; then + KUBERNETES_VERSION_UPGRADE_TO=$(grep KUBERNETES_VERSION_UPGRADE_TO: < "$E2E_CONF_FILE" | awk -F'"' '{ print $2}') + echo "Defaulting KUBERNETES_VERSION_UPGRADE_TO to ${KUBERNETES_VERSION_UPGRADE_TO} to trigger image build (because env var is not set)" + fi + fi + fi +} + # k8s::prepareKindestImages checks all the e2e test variables representing a Kubernetes version, # and makes sure a corresponding kindest/node image is available locally. k8s::prepareKindestImages() { @@ -65,15 +100,6 @@ k8s::prepareKindestImages() { kind::prepareKindestImage "$resolveVersion" fi - # If the test focuses on [K8s-Install-ci-latest], default KUBERNETES_VERSION_LATEST_CI - # to the value in the e2e config if it is not set. - # Note: We do this because we want to specify KUBERNETES_VERSION_LATEST_CI *only* in the e2e config. - if [[ ${GINKGO_FOCUS:-} == *"K8s-Install-ci-latest"* ]]; then - if [[ -z "${KUBERNETES_VERSION_LATEST_CI:-}" ]]; then - KUBERNETES_VERSION_LATEST_CI=$(grep KUBERNETES_VERSION_LATEST_CI < "$E2E_CONF_FILE" | awk -F'"' '{ print $2}') - echo "Defaulting KUBERNETES_VERSION_LATEST_CI to ${KUBERNETES_VERSION_LATEST_CI} to trigger image build (because env var is not set)" - fi - fi if [ -n "${KUBERNETES_VERSION_LATEST_CI:-}" ]; then k8s::resolveVersion "KUBERNETES_VERSION_LATEST_CI" "$KUBERNETES_VERSION_LATEST_CI" export KUBERNETES_VERSION_LATEST_CI=$resolveVersion diff --git a/scripts/ci-e2e.sh b/scripts/ci-e2e.sh index 8e45da3e83d1..f8b6e501eb2d 100755 --- a/scripts/ci-e2e.sh +++ b/scripts/ci-e2e.sh @@ -54,6 +54,7 @@ export USE_EXISTING_CLUSTER=false # - KUBERNETES_VERSION_UPGRADE_TO # - KUBERNETES_VERSION_UPGRADE_FROM # - KUBERNETES_VERSION_LATEST_CI +k8s::prepareKindestImagesVariables k8s::prepareKindestImages # pre-pull all the images that will be used in the e2e, thus making the actual test run diff --git a/test/e2e/config/docker.yaml b/test/e2e/config/docker.yaml index 6752e16bb74a..5b16821bf087 100644 --- a/test/e2e/config/docker.yaml +++ b/test/e2e/config/docker.yaml @@ -314,7 +314,7 @@ variables: # allowing the same e2e config file to be re-used in different Prow jobs e.g. each one with a K8s version permutation. # The following Kubernetes versions should be the latest versions with already published kindest/node images. # This avoids building node images in the default case which improves the test duration significantly. - KUBERNETES_VERSION_MANAGEMENT: "v1.30.0-rc.1" + KUBERNETES_VERSION_MANAGEMENT: "v1.29.2" KUBERNETES_VERSION: "v1.30.0-rc.1" KUBERNETES_VERSION_UPGRADE_FROM: "v1.29.2" KUBERNETES_VERSION_UPGRADE_TO: "v1.30.0-rc.1"