From e340ba44016a8c9413a55c2b72a6aeaba4cceb7a Mon Sep 17 00:00:00 2001 From: huangwei Date: Mon, 11 Dec 2023 16:31:29 +0800 Subject: [PATCH 1/2] Skip checking DNS filed when checking KCP MachineNeedRollout --- controlplane/kubeadm/internal/filters.go | 7 +++++- controlplane/kubeadm/internal/filters_test.go | 25 +++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/controlplane/kubeadm/internal/filters.go b/controlplane/kubeadm/internal/filters.go index 5c3e9c9ada2c..0502a1aa7cae 100644 --- a/controlplane/kubeadm/internal/filters.go +++ b/controlplane/kubeadm/internal/filters.go @@ -189,11 +189,16 @@ func matchClusterConfiguration(kcp *controlplanev1.KubeadmControlPlane, machine if machineClusterConfig == nil { machineClusterConfig = &bootstrapv1.ClusterConfiguration{} } - kcpLocalClusterConfiguration := kcp.Spec.KubeadmConfigSpec.ClusterConfiguration + + kcpLocalClusterConfiguration := kcp.Spec.KubeadmConfigSpec.ClusterConfiguration.DeepCopy() if kcpLocalClusterConfiguration == nil { kcpLocalClusterConfiguration = &bootstrapv1.ClusterConfiguration{} } + // Skip checking DNS fields because we can update the configuration of the working cluster in place. + kcpLocalClusterConfiguration.DNS = bootstrapv1.DNS{} + machineClusterConfig.DNS = bootstrapv1.DNS{} + // Compare and return. return reflect.DeepEqual(machineClusterConfig, kcpLocalClusterConfiguration) } diff --git a/controlplane/kubeadm/internal/filters_test.go b/controlplane/kubeadm/internal/filters_test.go index b110b058828f..62eae18eca67 100644 --- a/controlplane/kubeadm/internal/filters_test.go +++ b/controlplane/kubeadm/internal/filters_test.go @@ -104,6 +104,31 @@ func TestMatchClusterConfiguration(t *testing.T) { } g.Expect(matchClusterConfiguration(kcp, m)).To(BeTrue()) }) + t.Run("Return true although the DNS fields are different", func(t *testing.T) { + g := NewWithT(t) + kcp := &controlplanev1.KubeadmControlPlane{ + Spec: controlplanev1.KubeadmControlPlaneSpec{ + KubeadmConfigSpec: bootstrapv1.KubeadmConfigSpec{ + ClusterConfiguration: &bootstrapv1.ClusterConfiguration{ + DNS: bootstrapv1.DNS{ + ImageMeta: bootstrapv1.ImageMeta{ + ImageTag: "v1.10.1", + ImageRepository: "gcr.io/capi-test", + }, + }, + }, + }, + }, + } + m := &clusterv1.Machine{ + ObjectMeta: metav1.ObjectMeta{ + Annotations: map[string]string{ + controlplanev1.KubeadmClusterConfigurationAnnotation: "{\"dns\":{\"imageRepository\":\"gcr.io/capi-test\",\"imageTag\":\"v1.9.3\"}}", + }, + }, + } + g.Expect(matchClusterConfiguration(kcp, m)).To(BeTrue()) + }) } func TestGetAdjustedKcpConfig(t *testing.T) { From b96e9ac690ceb93c9bf04485bf021dab8883ef68 Mon Sep 17 00:00:00 2001 From: huangwei Date: Thu, 14 Dec 2023 10:52:42 +0800 Subject: [PATCH 2/2] fix comment --- controlplane/kubeadm/internal/filters.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/controlplane/kubeadm/internal/filters.go b/controlplane/kubeadm/internal/filters.go index 0502a1aa7cae..a93ef3f2055b 100644 --- a/controlplane/kubeadm/internal/filters.go +++ b/controlplane/kubeadm/internal/filters.go @@ -190,14 +190,13 @@ func matchClusterConfiguration(kcp *controlplanev1.KubeadmControlPlane, machine machineClusterConfig = &bootstrapv1.ClusterConfiguration{} } - kcpLocalClusterConfiguration := kcp.Spec.KubeadmConfigSpec.ClusterConfiguration.DeepCopy() + kcpLocalClusterConfiguration := kcp.Spec.KubeadmConfigSpec.ClusterConfiguration if kcpLocalClusterConfiguration == nil { kcpLocalClusterConfiguration = &bootstrapv1.ClusterConfiguration{} } // Skip checking DNS fields because we can update the configuration of the working cluster in place. - kcpLocalClusterConfiguration.DNS = bootstrapv1.DNS{} - machineClusterConfig.DNS = bootstrapv1.DNS{} + machineClusterConfig.DNS = kcpLocalClusterConfiguration.DNS // Compare and return. return reflect.DeepEqual(machineClusterConfig, kcpLocalClusterConfiguration)