diff --git a/hack/util.sh b/hack/util.sh index 2daf8a4f2eb..37197bcbbeb 100755 --- a/hack/util.sh +++ b/hack/util.sh @@ -38,3 +38,42 @@ capz::util::should_build_kubernetes() { fi echo "false" } + +capz::util::resolve_k8s_versions() { + if [ -n "${KUBERNETES_VERSION:-}" ]; then + k8s::resolveVersion "KUBERNETES_VERSION" "$KUBERNETES_VERSION" + export KUBERNETES_VERSION=$resolveVersion + fi + + if [ -n "${KUBERNETES_VERSION_UPGRADE_TO:-}" ]; then + k8s::resolveVersion "KUBERNETES_VERSION_UPGRADE_TO" "$KUBERNETES_VERSION_UPGRADE_TO" + export KUBERNETES_VERSION_UPGRADE_TO=$resolveVersion + fi + + if [ -n "${KUBERNETES_VERSION_UPGRADE_FROM:-}" ]; then + k8s::resolveVersion "KUBERNETES_VERSION_UPGRADE_FROM" "$KUBERNETES_VERSION_UPGRADE_FROM" + export KUBERNETES_VERSION_UPGRADE_FROM=$resolveVersion + fi +} + +# k8s::resolveVersion resolves kubernetes version labels (e.g. latest) to the corresponding version numbers. +# The result will be available in the resolveVersion variable which is accessible from the caller. +# +# NOTE: this doesn't guarantee a reference VM image will be available for this version. +# TODO: check the capi offer for the image. +k8s::resolveVersion() { + local variableName=$1 + local version=$2 + + resolveVersion=$version + if [[ "$version" =~ ^v ]]; then + return + fi + + if [[ "$version" =~ ^ci/ ]]; then + resolveVersion=$(curl -LsS "http://dl.k8s.io/ci/${version#ci/}.txt") + else + resolveVersion=$(curl -LsS "http://dl.k8s.io/release/${version}.txt") + fi + echo "+ $variableName=\"$version\" resolved to \"$resolveVersion\"" +} \ No newline at end of file diff --git a/scripts/ci-e2e.sh b/scripts/ci-e2e.sh index 95dc20b8d99..3096c26667a 100755 --- a/scripts/ci-e2e.sh +++ b/scripts/ci-e2e.sh @@ -72,6 +72,8 @@ export AZURE_CONTROL_PLANE_MACHINE_TYPE="${AZURE_CONTROL_PLANE_MACHINE_TYPE:-"St export AZURE_NODE_MACHINE_TYPE="${AZURE_NODE_MACHINE_TYPE:-"Standard_D2s_v3"}" export KIND_EXPERIMENTAL_DOCKER_NETWORK="bridge" +capz::util::resolve_k8s_versions + # Generate SSH key. AZURE_SSH_PUBLIC_KEY_FILE=${AZURE_SSH_PUBLIC_KEY_FILE:-""} if [ -z "${AZURE_SSH_PUBLIC_KEY_FILE}" ]; then diff --git a/test/e2e/capi_test.go b/test/e2e/capi_test.go index 1f9334c758a..c377894e222 100644 --- a/test/e2e/capi_test.go +++ b/test/e2e/capi_test.go @@ -23,6 +23,7 @@ import ( "fmt" "os" + "github.com/blang/semver" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" corev1 "k8s.io/api/core/v1" @@ -228,6 +229,12 @@ var _ = Describe("Running the Cluster API E2E tests", func() { }) var _ = Describe("When upgrading a workload cluster and testing K8S conformance [Conformance] [K8s-Upgrade]", func() { + // Opt into Windows for versions greater than or equal to 1.22 + if semver.MustParse(e2eConfig.Variables[capi_e2e.KubernetesVersionUpgradeFrom]).GTE(semver.MustParse("v1.22.0")) { + Expect(os.Setenv("WINDOWS_WORKER_MACHINE_COUNT", "2")).To(Succeed()) + Expect(os.Setenv("K8S_FEATURE_GATES", "WindowsHostProcessContainers=true")).To(Succeed()) + } + capi_e2e.ClusterUpgradeConformanceSpec(context.TODO(), func() capi_e2e.ClusterUpgradeConformanceSpecInput { return capi_e2e.ClusterUpgradeConformanceSpecInput{ E2EConfig: e2eConfig,