@@ -333,22 +333,6 @@ func TestCleanupConfigFields(t *testing.T) {
333333 g .Expect (kcpConfig .ClusterConfiguration .IsDefined ()).To (BeFalse ())
334334 g .Expect (machineConfig .Spec .ClusterConfiguration .IsDefined ()).To (BeFalse ())
335335 })
336- t .Run ("JoinConfiguration gets removed from MachineConfig if it was not derived by KCPConfig" , func (t * testing.T ) {
337- g := NewWithT (t )
338- kcpConfig := & bootstrapv1.KubeadmConfigSpec {
339- JoinConfiguration : bootstrapv1.JoinConfiguration {}, // KCP not providing a JoinConfiguration
340- }
341- machineConfig := & bootstrapv1.KubeadmConfig {
342- Spec : bootstrapv1.KubeadmConfigSpec {
343- JoinConfiguration : bootstrapv1.JoinConfiguration {
344- ControlPlane : & bootstrapv1.JoinControlPlane {},
345- }, // Machine gets a default JoinConfiguration from CABPK
346- },
347- }
348- cleanupConfigFields (kcpConfig , machineConfig )
349- g .Expect (kcpConfig .JoinConfiguration .IsDefined ()).To (BeFalse ())
350- g .Expect (machineConfig .Spec .JoinConfiguration .IsDefined ()).To (BeFalse ())
351- })
352336 t .Run ("JoinConfiguration.Discovery gets removed because it is not relevant for compare" , func (t * testing.T ) {
353337 g := NewWithT (t )
354338 kcpConfig := & bootstrapv1.KubeadmConfigSpec {
@@ -367,7 +351,7 @@ func TestCleanupConfigFields(t *testing.T) {
367351 g .Expect (kcpConfig .JoinConfiguration .Discovery ).To (BeComparableTo (bootstrapv1.Discovery {}))
368352 g .Expect (machineConfig .Spec .JoinConfiguration .Discovery ).To (BeComparableTo (bootstrapv1.Discovery {}))
369353 })
370- t .Run ("JoinConfiguration.ControlPlane gets removed from MachineConfig if it was not derived by KCPConfig " , func (t * testing.T ) {
354+ t .Run ("JoinConfiguration.ControlPlane gets removed from MachineConfig if it was added by CABPK " , func (t * testing.T ) {
371355 g := NewWithT (t )
372356 kcpConfig := & bootstrapv1.KubeadmConfigSpec {
373357 JoinConfiguration : bootstrapv1.JoinConfiguration {
@@ -385,23 +369,28 @@ func TestCleanupConfigFields(t *testing.T) {
385369 g .Expect (kcpConfig .JoinConfiguration ).ToNot (BeNil ())
386370 g .Expect (machineConfig .Spec .JoinConfiguration .ControlPlane ).To (BeNil ())
387371 })
388- t .Run ("JoinConfiguration.NodeRegistrationOptions gets removed from MachineConfig if it was not derived by KCPConfig " , func (t * testing.T ) {
372+ t .Run ("JoinConfiguration.ControlPlane gets not removed from MachineConfig if it is not empty " , func (t * testing.T ) {
389373 g := NewWithT (t )
390374 kcpConfig := & bootstrapv1.KubeadmConfigSpec {
391375 JoinConfiguration : bootstrapv1.JoinConfiguration {
392- NodeRegistration : bootstrapv1. NodeRegistrationOptions {} , // NodeRegistrationOptions configuration missing in KCP
376+ ControlPlane : nil , // Control plane configuration missing in KCP
393377 },
394378 }
395379 machineConfig := & bootstrapv1.KubeadmConfig {
396380 Spec : bootstrapv1.KubeadmConfigSpec {
397381 JoinConfiguration : bootstrapv1.JoinConfiguration {
398- NodeRegistration : bootstrapv1.NodeRegistrationOptions {Name : "test" }, // Machine gets a some JoinConfiguration.NodeRegistrationOptions
382+ ControlPlane : & bootstrapv1.JoinControlPlane {
383+ LocalAPIEndpoint : bootstrapv1.APIEndpoint {
384+ AdvertiseAddress : "1.2.3.4" ,
385+ BindPort : 6443 ,
386+ },
387+ },
399388 },
400389 },
401390 }
402391 cleanupConfigFields (kcpConfig , machineConfig )
403392 g .Expect (kcpConfig .JoinConfiguration ).ToNot (BeNil ())
404- g .Expect (machineConfig .Spec .JoinConfiguration .NodeRegistration ). To ( BeComparableTo (bootstrapv1. NodeRegistrationOptions {} ))
393+ g .Expect (machineConfig .Spec .JoinConfiguration .ControlPlane ). ToNot ( BeNil ( ))
405394 })
406395 t .Run ("drops omittable fields" , func (t * testing.T ) {
407396 g := NewWithT (t )
@@ -609,6 +598,53 @@ func TestMatchInitOrJoinConfiguration(t *testing.T) {
609598 Files: nil,
610599 DiskSetup: {},
611600 ... // 9 identical fields
601+ }` ))
602+ })
603+ t .Run ("returns false if JoinConfiguration is NOT equal" , func (t * testing.T ) {
604+ g := NewWithT (t )
605+ kcp := & controlplanev1.KubeadmControlPlane {
606+ Spec : controlplanev1.KubeadmControlPlaneSpec {
607+ KubeadmConfigSpec : bootstrapv1.KubeadmConfigSpec {
608+ ClusterConfiguration : bootstrapv1.ClusterConfiguration {},
609+ InitConfiguration : bootstrapv1.InitConfiguration {},
610+ // JoinConfiguration not set anymore.
611+ },
612+ },
613+ }
614+ machineConfig := & bootstrapv1.KubeadmConfig {
615+ ObjectMeta : metav1.ObjectMeta {
616+ Namespace : "default" ,
617+ Name : "test" ,
618+ },
619+ Spec : bootstrapv1.KubeadmConfigSpec {
620+ JoinConfiguration : bootstrapv1.JoinConfiguration {
621+ NodeRegistration : bootstrapv1.NodeRegistrationOptions {
622+ Name : "An old name" , // This is a change
623+ },
624+ },
625+ },
626+ }
627+ match , diff , err := matchInitOrJoinConfiguration (machineConfig , kcp )
628+ g .Expect (err ).ToNot (HaveOccurred ())
629+ g .Expect (match ).To (BeFalse ())
630+ g .Expect (diff ).To (BeComparableTo (`&v1beta2.KubeadmConfigSpec{
631+ ClusterConfiguration: {},
632+ InitConfiguration: {NodeRegistration: {ImagePullPolicy: "IfNotPresent"}},
633+ JoinConfiguration: v1beta2.JoinConfiguration{
634+ NodeRegistration: v1beta2.NodeRegistrationOptions{
635+ - Name: "An old name",
636+ + Name: "",
637+ CRISocket: "",
638+ Taints: nil,
639+ ... // 4 identical fields
640+ },
641+ CACertPath: "",
642+ Discovery: {},
643+ ... // 4 identical fields
644+ },
645+ Files: nil,
646+ DiskSetup: {},
647+ ... // 9 identical fields
612648 }` ))
613649 })
614650 t .Run ("returns true if returns true if only omittable configurations are not equal" , func (t * testing.T ) {
0 commit comments