Skip to content

Commit 22448fd

Browse files
🐛 Fix rollout when init configuration in KCP is empty (#12344)
* Fix rollout when init configuration in KCP is empty * Ensure the fix doesn't have side effects
1 parent 5528b1a commit 22448fd

File tree

2 files changed

+57
-0
lines changed

2 files changed

+57
-0
lines changed

controlplane/kubeadm/internal/filters.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,12 @@ func matchInitOrJoinConfiguration(machineConfig *bootstrapv1.KubeadmConfig, kcp
336336
func getAdjustedKcpConfig(kcp *controlplanev1.KubeadmControlPlane, machineConfig *bootstrapv1.KubeadmConfig) *bootstrapv1.KubeadmConfigSpec {
337337
kcpConfig := kcp.Spec.KubeadmConfigSpec.DeepCopy()
338338

339+
// Init configuration is usually be set under normal circumstances, but with some test providers (e.g. CAPD in memory)
340+
// it is left empty; In this case, we are initializing it so the comparison code can be simplified.
341+
if kcpConfig.InitConfiguration == nil {
342+
kcpConfig.InitConfiguration = &bootstrapv1.InitConfiguration{}
343+
}
344+
339345
// Machine's join configuration is nil when it is the first machine in the control plane.
340346
if machineConfig.Spec.JoinConfiguration == nil {
341347
kcpConfig.JoinConfiguration = nil

controlplane/kubeadm/internal/filters_test.go

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -538,6 +538,57 @@ func TestMatchInitOrJoinConfiguration(t *testing.T) {
538538
g.Expect(match).To(BeTrue())
539539
g.Expect(diff).To(BeEmpty())
540540
})
541+
t.Run("returns true if InitConfiguration is equal", func(t *testing.T) {
542+
g := NewWithT(t)
543+
kcp := &controlplanev1.KubeadmControlPlane{
544+
Spec: controlplanev1.KubeadmControlPlaneSpec{
545+
KubeadmConfigSpec: bootstrapv1.KubeadmConfigSpec{
546+
ClusterConfiguration: &bootstrapv1.ClusterConfiguration{},
547+
InitConfiguration: nil,
548+
JoinConfiguration: &bootstrapv1.JoinConfiguration{},
549+
},
550+
},
551+
}
552+
m := &clusterv1.Machine{
553+
TypeMeta: metav1.TypeMeta{
554+
Kind: "KubeadmConfig",
555+
APIVersion: clusterv1.GroupVersion.String(),
556+
},
557+
ObjectMeta: metav1.ObjectMeta{
558+
Namespace: "default",
559+
Name: "test",
560+
},
561+
Spec: clusterv1.MachineSpec{
562+
Bootstrap: clusterv1.Bootstrap{
563+
ConfigRef: &corev1.ObjectReference{
564+
Kind: "KubeadmConfig",
565+
Namespace: "default",
566+
Name: "test",
567+
APIVersion: bootstrapv1.GroupVersion.String(),
568+
},
569+
},
570+
},
571+
}
572+
machineConfigs := map[string]*bootstrapv1.KubeadmConfig{
573+
m.Name: {
574+
TypeMeta: metav1.TypeMeta{
575+
Kind: "KubeadmConfig",
576+
APIVersion: bootstrapv1.GroupVersion.String(),
577+
},
578+
ObjectMeta: metav1.ObjectMeta{
579+
Namespace: "default",
580+
Name: "test",
581+
},
582+
Spec: bootstrapv1.KubeadmConfigSpec{
583+
InitConfiguration: &bootstrapv1.InitConfiguration{},
584+
},
585+
},
586+
}
587+
match, diff, err := matchInitOrJoinConfiguration(machineConfigs[m.Name], kcp)
588+
g.Expect(err).ToNot(HaveOccurred())
589+
g.Expect(match).To(BeTrue())
590+
g.Expect(diff).To(BeEmpty())
591+
})
541592
t.Run("returns true if InitConfiguration is equal", func(t *testing.T) {
542593
g := NewWithT(t)
543594
kcp := &controlplanev1.KubeadmControlPlane{

0 commit comments

Comments
 (0)