Skip to content

Commit 810c2a6

Browse files
authored
Merge pull request #6095 from sbueringer/pr-fix-kcp-rollout
🐛 KCP: don't rollout machines when format is defaulted
2 parents 16ad231 + 78700cf commit 810c2a6

File tree

2 files changed

+69
-0
lines changed

2 files changed

+69
-0
lines changed

controlplane/kubeadm/internal/filters.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,15 @@ func cleanupConfigFields(kcpConfig *bootstrapv1.KubeadmConfigSpec, machineConfig
196196
kcpConfig.ClusterConfiguration = nil
197197
machineConfig.Spec.ClusterConfiguration = nil
198198

199+
// We have to treat the "empty" and CloudConfig format the same
200+
// otherwise defaulting on KCP will trigger a machine rollout.
201+
if kcpConfig.Format == "" {
202+
kcpConfig.Format = bootstrapv1.CloudConfig
203+
}
204+
if machineConfig.Spec.Format == "" {
205+
machineConfig.Spec.Format = bootstrapv1.CloudConfig
206+
}
207+
199208
// If KCP JoinConfiguration is not present, set machine JoinConfiguration to nil (nothing can trigger rollout here).
200209
// NOTE: this is required because CABPK applies an empty joinConfiguration in case no one is provided.
201210
if kcpConfig.JoinConfiguration == nil {

controlplane/kubeadm/internal/filters_test.go

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,20 @@ func TestGetAdjustedKcpConfig(t *testing.T) {
148148
}
149149

150150
func TestCleanupConfigFields(t *testing.T) {
151+
t.Run("Format gets set to cloud-config if not set", func(t *testing.T) {
152+
g := NewWithT(t)
153+
kcpConfig := &bootstrapv1.KubeadmConfigSpec{
154+
Format: "",
155+
}
156+
machineConfig := &bootstrapv1.KubeadmConfig{
157+
Spec: bootstrapv1.KubeadmConfigSpec{
158+
Format: "",
159+
},
160+
}
161+
cleanupConfigFields(kcpConfig, machineConfig)
162+
g.Expect(kcpConfig.Format).To(Equal(bootstrapv1.CloudConfig))
163+
g.Expect(machineConfig.Spec.Format).To(Equal(bootstrapv1.CloudConfig))
164+
})
151165
t.Run("ClusterConfiguration gets removed from KcpConfig and MachineConfig", func(t *testing.T) {
152166
g := NewWithT(t)
153167
kcpConfig := &bootstrapv1.KubeadmConfigSpec{
@@ -281,6 +295,52 @@ func TestMatchInitOrJoinConfiguration(t *testing.T) {
281295
kcp := &controlplanev1.KubeadmControlPlane{}
282296
g.Expect(matchInitOrJoinConfiguration(nil, kcp)).To(BeTrue())
283297
})
298+
t.Run("returns true if one format is empty and the other one cloud-config", func(t *testing.T) {
299+
g := NewWithT(t)
300+
kcp := &controlplanev1.KubeadmControlPlane{
301+
Spec: controlplanev1.KubeadmControlPlaneSpec{
302+
KubeadmConfigSpec: bootstrapv1.KubeadmConfigSpec{
303+
Format: bootstrapv1.CloudConfig,
304+
},
305+
},
306+
}
307+
m := &clusterv1.Machine{
308+
TypeMeta: metav1.TypeMeta{
309+
Kind: "KubeadmConfig",
310+
APIVersion: clusterv1.GroupVersion.String(),
311+
},
312+
ObjectMeta: metav1.ObjectMeta{
313+
Namespace: "default",
314+
Name: "test",
315+
},
316+
Spec: clusterv1.MachineSpec{
317+
Bootstrap: clusterv1.Bootstrap{
318+
ConfigRef: &corev1.ObjectReference{
319+
Kind: "KubeadmConfig",
320+
Namespace: "default",
321+
Name: "test",
322+
APIVersion: bootstrapv1.GroupVersion.String(),
323+
},
324+
},
325+
},
326+
}
327+
machineConfigs := map[string]*bootstrapv1.KubeadmConfig{
328+
m.Name: {
329+
TypeMeta: metav1.TypeMeta{
330+
Kind: "KubeadmConfig",
331+
APIVersion: bootstrapv1.GroupVersion.String(),
332+
},
333+
ObjectMeta: metav1.ObjectMeta{
334+
Namespace: "default",
335+
Name: "test",
336+
},
337+
Spec: bootstrapv1.KubeadmConfigSpec{
338+
Format: "",
339+
},
340+
},
341+
}
342+
g.Expect(matchInitOrJoinConfiguration(machineConfigs[m.Name], kcp)).To(BeTrue())
343+
})
284344
t.Run("returns true if InitConfiguration is equal", func(t *testing.T) {
285345
g := NewWithT(t)
286346
kcp := &controlplanev1.KubeadmControlPlane{

0 commit comments

Comments
 (0)