From 25334cfef778aa5c27f286cae1c1ac184656c517 Mon Sep 17 00:00:00 2001 From: Stefan Bueringer Date: Tue, 22 Oct 2024 16:28:14 +0200 Subject: [PATCH] KCP: Skip validation if CoreDNS migration library supports an upgrade if skip CoreDNS is set MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Stefan Büringer buringerst@vmware.com --- .../webhooks/kubeadm_control_plane.go | 6 +++++ .../webhooks/kubeadm_control_plane_test.go | 22 +++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/controlplane/kubeadm/internal/webhooks/kubeadm_control_plane.go b/controlplane/kubeadm/internal/webhooks/kubeadm_control_plane.go index d848d4616bba..7237c49d3b54 100644 --- a/controlplane/kubeadm/internal/webhooks/kubeadm_control_plane.go +++ b/controlplane/kubeadm/internal/webhooks/kubeadm_control_plane.go @@ -620,6 +620,12 @@ func (webhook *KubeadmControlPlane) validateCoreDNSVersion(oldK, newK *controlpl if toVersion.Equals(fromVersion) { return allErrs } + + // Skip validating if the skip CoreDNS annotation is set. If set, KCP doesn't use the migration library. + if _, ok := newK.Annotations[controlplanev1.SkipCoreDNSAnnotation]; ok { + return allErrs + } + if err := migration.ValidUpMigration(fromVersion.String(), toVersion.String()); err != nil { allErrs = append( allErrs, diff --git a/controlplane/kubeadm/internal/webhooks/kubeadm_control_plane_test.go b/controlplane/kubeadm/internal/webhooks/kubeadm_control_plane_test.go index 9c62b22ad4e6..168b37d8d149 100644 --- a/controlplane/kubeadm/internal/webhooks/kubeadm_control_plane_test.go +++ b/controlplane/kubeadm/internal/webhooks/kubeadm_control_plane_test.go @@ -554,6 +554,17 @@ func TestKubeadmControlPlaneValidateUpdate(t *testing.T) { }, } + validUnsupportedCoreDNSVersionWithSkipAnnotation := dns.DeepCopy() + validUnsupportedCoreDNSVersionWithSkipAnnotation.Spec.KubeadmConfigSpec.ClusterConfiguration.DNS = bootstrapv1.DNS{ + ImageMeta: bootstrapv1.ImageMeta{ + ImageRepository: "gcr.io/capi-test", + ImageTag: "v99.99.99", + }, + } + validUnsupportedCoreDNSVersionWithSkipAnnotation.Annotations = map[string]string{ + controlplanev1.SkipCoreDNSAnnotation: "", + } + unsetCoreDNSToVersion := dns.DeepCopy() unsetCoreDNSToVersion.Spec.KubeadmConfigSpec.ClusterConfiguration.DNS = bootstrapv1.DNS{ ImageMeta: bootstrapv1.ImageMeta{ @@ -860,6 +871,17 @@ func TestKubeadmControlPlaneValidateUpdate(t *testing.T) { before: validUnsupportedCoreDNSVersion, kcp: validUnsupportedCoreDNSVersion, }, + { + name: "should fail when upgrading to an unsupported version", + before: dns, + kcp: validUnsupportedCoreDNSVersion, + expectErr: true, + }, + { + name: "should succeed when upgrading to an unsupported version and KCP has skip annotation set", + before: dns, + kcp: validUnsupportedCoreDNSVersionWithSkipAnnotation, + }, { name: "should fail when using an invalid DNS build", expectErr: true,