Skip to content

Commit

Permalink
default KUBERNETES_VERSION if not set
Browse files Browse the repository at this point in the history
  • Loading branch information
chrischdi committed Apr 5, 2024
1 parent 3930054 commit daaaa19
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 10 deletions.
44 changes: 35 additions & 9 deletions scripts/ci-e2e-lib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions scripts/ci-e2e.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/config/docker.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit daaaa19

Please sign in to comment.