From d48b35b55d866b8efe549f29ead1a933e96f2dab Mon Sep 17 00:00:00 2001 From: Levi080513 Date: Tue, 16 Jan 2024 01:23:28 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Skip=20checking=20`clusterConfig?= =?UTF-8?q?uration.dns`=20fields=20when=20KCP=20checking=20MachineNeedRoll?= =?UTF-8?q?out=20=20(#9857)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Skip checking DNS filed when checking KCP MachineNeedRollout * fix comment --- controlplane/kubeadm/internal/filters.go | 4 +++ controlplane/kubeadm/internal/filters_test.go | 25 +++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/controlplane/kubeadm/internal/filters.go b/controlplane/kubeadm/internal/filters.go index a3154223acef..82f5c92f39b8 100644 --- a/controlplane/kubeadm/internal/filters.go +++ b/controlplane/kubeadm/internal/filters.go @@ -189,11 +189,15 @@ func matchClusterConfiguration(kcp *controlplanev1.KubeadmControlPlane, machine if machineClusterConfig == nil { machineClusterConfig = &bootstrapv1.ClusterConfiguration{} } + 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. + machineClusterConfig.DNS = kcpLocalClusterConfiguration.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 0cef8e855846..373f585c4497 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) {