Skip to content

Commit

Permalink
Use known kind images where they exist
Browse files Browse the repository at this point in the history
Signed-off-by: killianmuldoon <kmuldoon@vmware.com>
  • Loading branch information
killianmuldoon committed Jun 15, 2023
1 parent 2fc70ba commit 3c0c11a
Show file tree
Hide file tree
Showing 9 changed files with 57 additions and 11 deletions.
2 changes: 1 addition & 1 deletion test/e2e/cluster_upgrade_runtimesdk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (
"k8s.io/utils/pointer"
)

var _ = Describe("When upgrading a workload cluster using ClusterClass with RuntimeSDK [PR-Informing] [ClusterClass]", func() {
var _ = Describe("When upgrading a workload cluster using ClusterClass with RuntimeSDK [ClusterClass]", func() {
clusterUpgradeWithRuntimeSDKSpec(ctx, func() clusterUpgradeWithRuntimeSDKSpecInput {
version, err := semver.ParseTolerant(e2eConfig.GetVariable(KubernetesVersionUpgradeFrom))
Expect(err).ToNot(HaveOccurred(), "Invalid argument, KUBERNETES_VERSION_UPGRADE_FROM is not a valid version")
Expand Down
6 changes: 3 additions & 3 deletions test/e2e/clusterctl_upgrade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
"sigs.k8s.io/cluster-api/test/framework"
)

var _ = Describe("When testing clusterctl upgrades (v0.4=>current)", func() {
var _ = Describe("When testing clusterctl upgrades [PR-Informing] (v0.4=>current)", func() {
ClusterctlUpgradeSpec(ctx, func() ClusterctlUpgradeSpecInput {
return ClusterctlUpgradeSpecInput{
E2EConfig: e2eConfig,
Expand All @@ -35,7 +35,7 @@ var _ = Describe("When testing clusterctl upgrades (v0.4=>current)", func() {
SkipCleanup: skipCleanup,
InitWithBinary: "https://github.com/kubernetes-sigs/cluster-api/releases/download/v0.4.8/clusterctl-{OS}-{ARCH}",
InitWithProvidersContract: "v1alpha4",
// NOTE: If this version is changed here the image and SHA must also be updated in all DockerMachineTemplates in `test/data/infrastructure-docker/v1.0/bases.
// NOTE: If this version is changed here the image and SHA must also be updated in all DockerMachineTemplates in `test/data/infrastructure-docker/v0.4/bases.
InitWithKubernetesVersion: "v1.23.17",
WorkloadKubernetesVersion: "v1.23.17",
MgmtFlavor: "topology",
Expand All @@ -55,7 +55,7 @@ var _ = Describe("When testing clusterctl upgrades (v0.4=>current)", func() {
})
})

var _ = Describe("When testing clusterctl upgrades (v1.0=>current)", func() {
var _ = Describe("When testing clusterctl upgrades [PR-Informing] (v1.0=>current)", func() {
ClusterctlUpgradeSpec(ctx, func() ClusterctlUpgradeSpecInput {
return ClusterctlUpgradeSpecInput{
E2EConfig: e2eConfig,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ metadata:
spec:
template:
spec:
# NOTE: If the Kubernetes version is changed in `clusterctl_upgrade_test.go` the image and SHA must be updated here.
customImage: "kindest/node:v1.23.17@sha256:f77f8cf0b30430ca4128cc7cfafece0c274a118cd0cdb251049664ace0dee4ff"
extraMounts:
- containerPath: "/var/run/docker.sock"
Expand Down
1 change: 1 addition & 0 deletions test/e2e/data/infrastructure-docker/v0.4/bases/md.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ metadata:
spec:
template:
spec:
# NOTE: If the Kubernetes version is changed in `clusterctl_upgrade_test.go` the image and SHA must be updated here.
customImage: "kindest/node:v1.23.17@sha256:f77f8cf0b30430ca4128cc7cfafece0c274a118cd0cdb251049664ace0dee4ff"
extraMounts:
- containerPath: "/var/run/docker.sock"
Expand Down
4 changes: 2 additions & 2 deletions test/e2e/data/infrastructure-docker/v0.4/bases/mp.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ metadata:
name: "${CLUSTER_NAME}-dmp-0"
spec:
template:
spec:
customImage: "kindest/node:v1.23.17@sha256:f77f8cf0b30430ca4128cc7cfafece0c274a118cd0cdb251049664ace0dee4ff"
# NOTE: If the Kubernetes version is changed in `clusterctl_upgrade_test.go` the image and SHA must be updated here.
customImage: "kindest/node:v1.23.17@sha256:f77f8cf0b30430ca4128cc7cfafece0c274a118cd0cdb251049664ace0dee4ff"

---
# KubeadmConfigTemplate referenced by the MachinePool
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ metadata:
spec:
template:
spec:
# NOTE: If the Kubernetes version is changed in `clusterctl_upgrade_test.go` the image and SHA must be updated here.
customImage: "kindest/node:v1.23.17@sha256:f77f8cf0b30430ca4128cc7cfafece0c274a118cd0cdb251049664ace0dee4ff"
extraMounts:
- containerPath: "/var/run/docker.sock"
Expand Down
1 change: 1 addition & 0 deletions test/e2e/data/infrastructure-docker/v1.0/bases/md.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ metadata:
spec:
template:
spec:
# NOTE: If the Kubernetes version is changed in `clusterctl_upgrade_test.go` the image and SHA must be updated here.
customImage: "kindest/node:v1.23.17@sha256:f77f8cf0b30430ca4128cc7cfafece0c274a118cd0cdb251049664ace0dee4ff"
extraMounts:
- containerPath: "/var/run/docker.sock"
Expand Down
39 changes: 39 additions & 0 deletions test/infrastructure/docker/internal/docker/kind_version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
Copyright 2023 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package docker

// knownKindImageVersions is a map that maps KIND node images and tags to the shas of images recommended for use with a
// specific KIND version.
// Contains shas for KIND v0.19.0. NOTE: These must be updated when the kind version is updated.
var knownKindImageVersions = map[string]string{
"kindest/node:v1.27.1": "kindest/node:v1.27.1@sha256:b7d12ed662b873bd8510879c1846e87c7e676a79fefc93e17b2a52989d3ff42b",
"kindest/node:v1.26.4": "kindest/node:v1.26.4@sha256:f4c0d87be03d6bea69f5e5dc0adb678bb498a190ee5c38422bf751541cebe92e",
"kindest/node:v1.25.9": "kindest/node:v1.25.9@sha256:c08d6c52820aa42e533b70bce0c2901183326d86dcdcbedecc9343681db45161",
"kindest/node:v1.24.13": "kindest/node:v1.24.13@sha256:cea86276e698af043af20143f4bf0509e730ec34ed3b7fa790cc0bea091bc5dd",
"kindest/node:v1.23.17": "kindest/node:v1.23.17@sha256:f77f8cf0b30430ca4128cc7cfafece0c274a118cd0cdb251049664ace0dee4ff",
"kindest/node:v1.22.17": "kindest/node:v1.22.17@sha256:9af784f45a584f6b28bce2af84c494d947a05bd709151466489008f80a9ce9d5",
"kindest/node:v1.21.14": "kindest/node:v1.21.14@sha256:220cfafdf6e3915fbce50e13d1655425558cb98872c53f802605aa2fb2d569cf",
}

// kindImageVersionFix maps an input image and tag to a known SHA for a given KIND release.
// If the passed in image version is not found, this function returns the original image string.
func kindImageVersionFix(image string) string {
if knownImage, ok := knownKindImageVersions[image]; ok {
return knownImage
}
return image
}
13 changes: 8 additions & 5 deletions test/infrastructure/docker/internal/docker/machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,21 +205,24 @@ func (m *Machine) ContainerImage() string {
}

// Create creates a docker container hosting a Kubernetes node.
func (m *Machine) Create(ctx context.Context, image string, role string, version *string, labels map[string]string, mounts []infrav1.Mount) error {
func (m *Machine) Create(ctx context.Context, customImage string, role string, version *string, labels map[string]string, mounts []infrav1.Mount) error {
log := ctrl.LoggerFrom(ctx)

// Create if not exists.
if m.container == nil {
var err error

machineImage := m.machineImage(version)
if image != "" {
machineImage = image
if customImage != "" {
machineImage = customImage
}

// Ensure the image is using a known good kindest/node image if one exists.
machineImage = kindImageVersionFix(machineImage)

switch role {
case constants.ControlPlaneNodeRoleValue:
log.Info("Creating control plane machine container")
log.Info(fmt.Sprintf("Creating control plane machine container with machine image %s", machineImage))
m.container, err = m.nodeCreator.CreateControlPlaneNode(
ctx,
m.ContainerName(),
Expand All @@ -236,7 +239,7 @@ func (m *Machine) Create(ctx context.Context, image string, role string, version
return errors.WithStack(err)
}
case constants.WorkerNodeRoleValue:
log.Info("Creating worker machine container")
log.Info(fmt.Sprintf("Creating worker machine container with machine image %s", machineImage))
m.container, err = m.nodeCreator.CreateWorkerNode(
ctx,
m.ContainerName(),
Expand Down

0 comments on commit 3c0c11a

Please sign in to comment.