@@ -333,22 +333,6 @@ func TestCleanupConfigFields(t *testing.T) {
333
333
g .Expect (kcpConfig .ClusterConfiguration .IsDefined ()).To (BeFalse ())
334
334
g .Expect (machineConfig .Spec .ClusterConfiguration .IsDefined ()).To (BeFalse ())
335
335
})
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
- })
352
336
t .Run ("JoinConfiguration.Discovery gets removed because it is not relevant for compare" , func (t * testing.T ) {
353
337
g := NewWithT (t )
354
338
kcpConfig := & bootstrapv1.KubeadmConfigSpec {
@@ -367,7 +351,7 @@ func TestCleanupConfigFields(t *testing.T) {
367
351
g .Expect (kcpConfig .JoinConfiguration .Discovery ).To (BeComparableTo (bootstrapv1.Discovery {}))
368
352
g .Expect (machineConfig .Spec .JoinConfiguration .Discovery ).To (BeComparableTo (bootstrapv1.Discovery {}))
369
353
})
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 ) {
371
355
g := NewWithT (t )
372
356
kcpConfig := & bootstrapv1.KubeadmConfigSpec {
373
357
JoinConfiguration : bootstrapv1.JoinConfiguration {
@@ -385,23 +369,28 @@ func TestCleanupConfigFields(t *testing.T) {
385
369
g .Expect (kcpConfig .JoinConfiguration ).ToNot (BeNil ())
386
370
g .Expect (machineConfig .Spec .JoinConfiguration .ControlPlane ).To (BeNil ())
387
371
})
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 ) {
389
373
g := NewWithT (t )
390
374
kcpConfig := & bootstrapv1.KubeadmConfigSpec {
391
375
JoinConfiguration : bootstrapv1.JoinConfiguration {
392
- NodeRegistration : bootstrapv1. NodeRegistrationOptions {} , // NodeRegistrationOptions configuration missing in KCP
376
+ ControlPlane : nil , // Control plane configuration missing in KCP
393
377
},
394
378
}
395
379
machineConfig := & bootstrapv1.KubeadmConfig {
396
380
Spec : bootstrapv1.KubeadmConfigSpec {
397
381
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
+ },
399
388
},
400
389
},
401
390
}
402
391
cleanupConfigFields (kcpConfig , machineConfig )
403
392
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 ( ))
405
394
})
406
395
t .Run ("drops omittable fields" , func (t * testing.T ) {
407
396
g := NewWithT (t )
@@ -609,6 +598,53 @@ func TestMatchInitOrJoinConfiguration(t *testing.T) {
609
598
Files: nil,
610
599
DiskSetup: {},
611
600
... // 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
612
648
}` ))
613
649
})
614
650
t .Run ("returns true if returns true if only omittable configurations are not equal" , func (t * testing.T ) {
0 commit comments