Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[release-1.7] 🌱 e2e: enable ability to test pre-releases of kubernetes #10415

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 38 additions & 9 deletions scripts/ci-e2e-lib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,44 @@ capi:buildDockerImages () {
fi
}

# k8s::prepareKindestImagesVariables defaults the environment variables KUBERNETES_VERSION,
# KUBERNETES_VERSION_UPGRADE_TO, KUBERNETES_VERSION_UPGRADE_FROM 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() {
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
fi

# Tests not focusing on [PR-Blocking], [K8s-Install] or [K8s-Install-ci-latest],
# also run upgrade tests so default KUBERNETES_VERSION_UPGRADE_TO and KUBERNETES_VERSION_UPGRADE_FROM
# to the value in the e2e config if they are 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
if [[ -z "${KUBERNETES_VERSION_UPGRADE_FROM:-}" ]]; then
KUBERNETES_VERSION_UPGRADE_FROM=$(grep KUBERNETES_VERSION_UPGRADE_FROM: < "$E2E_CONF_FILE" | awk -F'"' '{ print $2}')
echo "Defaulting KUBERNETES_VERSION_UPGRADE_FROM to ${KUBERNETES_VERSION_UPGRADE_FROM} to trigger image build (because env var is not set)"
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 +103,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
6 changes: 3 additions & 3 deletions test/extension/handlers/topologymutation/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -331,13 +331,13 @@ func patchDockerMachineTemplate(ctx context.Context, dockerMachineTemplate *infr

// if found
if err == nil {
semVer, err := version.ParseMajorMinorPatchTolerant(cpVersion)
semVer, err := semver.ParseTolerant(cpVersion)
if err != nil {
return errors.Wrap(err, "could not parse control plane version")
}
kindMapping := kind.GetMapping(semVer, "")

log.Info(fmt.Sprintf("Setting MachineDeployment custom image to %q", kindMapping.Image))
log.Info(fmt.Sprintf("Setting control plane custom image to %q", kindMapping.Image))
dockerMachineTemplate.Spec.Template.Spec.CustomImage = kindMapping.Image
// return early if we have successfully patched a control plane dockerMachineTemplate
return nil
Expand All @@ -357,7 +357,7 @@ func patchDockerMachineTemplate(ctx context.Context, dockerMachineTemplate *infr
return errors.Wrap(err, "could not set customImage to MachineDeployment DockerMachineTemplate")
}

semVer, err := version.ParseMajorMinorPatchTolerant(mdVersion)
semVer, err := semver.ParseTolerant(mdVersion)
if err != nil {
return errors.Wrap(err, "could not parse MachineDeployment version")
}
Expand Down
20 changes: 20 additions & 0 deletions test/extension/handlers/topologymutation/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,26 @@ func Test_patchDockerMachineTemplate(t *testing.T) {
},
},
},
{
name: "sets customImage for templates linked to ControlPlane for pre versions",
template: &infrav1.DockerMachineTemplate{},
variables: map[string]apiextensionsv1.JSON{
runtimehooksv1.BuiltinsName: {Raw: toJSON(runtimehooksv1.Builtins{
ControlPlane: &runtimehooksv1.ControlPlaneBuiltins{
Version: "v1.23.0-rc.0",
},
})},
},
expectedTemplate: &infrav1.DockerMachineTemplate{
Spec: infrav1.DockerMachineTemplateSpec{
Template: infrav1.DockerMachineTemplateResource{
Spec: infrav1.DockerMachineSpec{
CustomImage: "kindest/node:v1.23.0-rc.0",
},
},
},
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(*testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion test/framework/kubetest/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ func parseKubetestConfig(kubetestConfigFile string) (kubetestConfig, error) {
}

func isUsingCIArtifactsVersion(k8sVersion string) bool {
return strings.Contains(k8sVersion, "-")
return strings.Contains(k8sVersion, "+")
}

func discoverClusterKubernetesVersion(proxy framework.ClusterProxy) (string, error) {
Expand Down
4 changes: 2 additions & 2 deletions test/infrastructure/kind/mapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -376,8 +376,8 @@ func GetMapping(k8sVersion semver.Version, customImage string) Mapping {
continue
}

// If the mapping is for the same patch version, return it
if k8sVersion.Patch == m.KubernetesVersion.Patch {
// If the mapping is for the same patch version and no pre version is defined, return it
if k8sVersion.Patch == m.KubernetesVersion.Patch && len(k8sVersion.Pre) == 0 {
return Mapping{
KubernetesVersion: m.KubernetesVersion,
Mode: m.Mode,
Expand Down