@@ -75,6 +75,12 @@ type ClusterClassRolloutSpecInput struct {
75
75
// Allows to inject a function to be run after test namespace is created.
76
76
// If not specified, this is a no-op.
77
77
PostNamespaceCreated func (managementClusterProxy framework.ClusterProxy , workloadClusterNamespace string )
78
+
79
+ // FilterMetadataBeforeValidation allows filtering out labels and annotations of Machines, InfraMachines,
80
+ // BootstrapConfigs and Nodes before we validate them.
81
+ // This can be e.g. used to filter out additional infrastructure provider specific labels that would
82
+ // otherwise lead to a failed test.
83
+ FilterMetadataBeforeValidation func (object client.Object ) clusterv1.ObjectMeta
78
84
}
79
85
80
86
// ClusterClassRolloutSpec implements a test that verifies the ClusterClass rollout behavior.
@@ -111,6 +117,14 @@ func ClusterClassRolloutSpec(ctx context.Context, inputGetter func() ClusterClas
111
117
Expect (input .E2EConfig .Variables ).To (HaveKey (KubernetesVersion ))
112
118
Expect (input .E2EConfig .Variables ).To (HaveValidVersion (input .E2EConfig .GetVariable (KubernetesVersion )))
113
119
120
+ // Set a default function to ensure that FilterMetadataBeforeValidation has a default behavior for
121
+ // filtering metadata if it is not specified by infrastructure provider.
122
+ if input .FilterMetadataBeforeValidation == nil {
123
+ input .FilterMetadataBeforeValidation = func (obj client.Object ) clusterv1.ObjectMeta {
124
+ return clusterv1.ObjectMeta {Labels : obj .GetLabels (), Annotations : obj .GetAnnotations ()}
125
+ }
126
+ }
127
+
114
128
// Set up a Namespace where to host objects for this spec and create a watcher for the namespace events.
115
129
namespace , cancelWatches = framework .SetupSpecNamespace (ctx , specName , input .BootstrapClusterProxy , input .ArtifactFolder , input .PostNamespaceCreated )
116
130
clusterResources = new (clusterctl.ApplyClusterTemplateAndWaitResult )
@@ -142,7 +156,7 @@ func ClusterClassRolloutSpec(ctx context.Context, inputGetter func() ClusterClas
142
156
WaitForMachineDeployments : input .E2EConfig .GetIntervals (specName , "wait-worker-nodes" ),
143
157
WaitForMachinePools : input .E2EConfig .GetIntervals (specName , "wait-machine-pool-nodes" ),
144
158
}, clusterResources )
145
- assertClusterObjects (ctx , input .BootstrapClusterProxy , clusterResources .Cluster , clusterResources .ClusterClass )
159
+ assertClusterObjects (ctx , input .BootstrapClusterProxy , clusterResources .Cluster , clusterResources .ClusterClass , input . FilterMetadataBeforeValidation )
146
160
147
161
By ("Rolling out changes to control plane, MachineDeployments, and MachinePools (in-place)" )
148
162
machinesBeforeUpgrade := getMachinesByCluster (ctx , input .BootstrapClusterProxy .GetClient (), clusterResources .Cluster )
@@ -218,7 +232,7 @@ func ClusterClassRolloutSpec(ctx context.Context, inputGetter func() ClusterClas
218
232
machinesAfterUpgrade := getMachinesByCluster (ctx , input .BootstrapClusterProxy .GetClient (), clusterResources .Cluster )
219
233
g .Expect (machinesAfterUpgrade .Equal (machinesBeforeUpgrade )).To (BeTrue (), "Machines must not be replaced through in-place rollout" )
220
234
}, 30 * time .Second , 1 * time .Second ).Should (Succeed ())
221
- assertClusterObjects (ctx , input .BootstrapClusterProxy , clusterResources .Cluster , clusterResources .ClusterClass )
235
+ assertClusterObjects (ctx , input .BootstrapClusterProxy , clusterResources .Cluster , clusterResources .ClusterClass , input . FilterMetadataBeforeValidation )
222
236
223
237
By ("Rolling out changes to control plane, MachineDeployments, and MachinePools (rollout)" )
224
238
machinesBeforeUpgrade = getMachinesByCluster (ctx , input .BootstrapClusterProxy .GetClient (), clusterResources .Cluster )
@@ -259,7 +273,7 @@ func ClusterClassRolloutSpec(ctx context.Context, inputGetter func() ClusterClas
259
273
machinesAfterUpgrade := getMachinesByCluster (ctx , input .BootstrapClusterProxy .GetClient (), clusterResources .Cluster )
260
274
g .Expect (machinesAfterUpgrade .HasAny (machinesBeforeUpgrade .UnsortedList ()... )).To (BeFalse (), "All Machines must be replaced through rollout" )
261
275
}, input .E2EConfig .GetIntervals (specName , "wait-control-plane" )... ).Should (Succeed ())
262
- assertClusterObjects (ctx , input .BootstrapClusterProxy , clusterResources .Cluster , clusterResources .ClusterClass )
276
+ assertClusterObjects (ctx , input .BootstrapClusterProxy , clusterResources .Cluster , clusterResources .ClusterClass , input . FilterMetadataBeforeValidation )
263
277
264
278
By ("Rolling out control plane and MachineDeployment (rolloutAfter)" )
265
279
machinesBeforeUpgrade = getMachinesByCluster (ctx , input .BootstrapClusterProxy .GetClient (), clusterResources .Cluster )
@@ -287,7 +301,7 @@ func ClusterClassRolloutSpec(ctx context.Context, inputGetter func() ClusterClas
287
301
machinesAfterUpgrade := getMachinesByCluster (ctx , input .BootstrapClusterProxy .GetClient (), clusterResources .Cluster )
288
302
g .Expect (machinesAfterUpgrade .HasAny (machinesBeforeUpgrade .UnsortedList ()... )).To (BeFalse (), "All Machines must be replaced through rollout with rolloutAfter" )
289
303
}, input .E2EConfig .GetIntervals (specName , "wait-machine-upgrade" )... ).Should (Succeed ())
290
- assertClusterObjects (ctx , input .BootstrapClusterProxy , clusterResources .Cluster , clusterResources .ClusterClass )
304
+ assertClusterObjects (ctx , input .BootstrapClusterProxy , clusterResources .Cluster , clusterResources .ClusterClass , input . FilterMetadataBeforeValidation )
291
305
292
306
By ("PASSED!" )
293
307
})
@@ -299,7 +313,7 @@ func ClusterClassRolloutSpec(ctx context.Context, inputGetter func() ClusterClas
299
313
}
300
314
301
315
// assertClusterObjects asserts cluster objects by checking that all objects have the right labels, annotations and selectors.
302
- func assertClusterObjects (ctx context.Context , clusterProxy framework.ClusterProxy , cluster * clusterv1.Cluster , clusterClass * clusterv1.ClusterClass ) {
316
+ func assertClusterObjects (ctx context.Context , clusterProxy framework.ClusterProxy , cluster * clusterv1.Cluster , clusterClass * clusterv1.ClusterClass , filterMetadataBeforeValidation func ( object client. Object ) clusterv1. ObjectMeta ) {
303
317
By ("Checking cluster objects have the right labels, annotations and selectors" )
304
318
305
319
Eventually (func (g Gomega ) {
@@ -312,12 +326,12 @@ func assertClusterObjects(ctx context.Context, clusterProxy framework.ClusterPro
312
326
313
327
// ControlPlane
314
328
assertControlPlane (g , clusterClassObjects , clusterObjects , cluster , clusterClass )
315
- assertControlPlaneMachines (g , clusterObjects , cluster )
329
+ assertControlPlaneMachines (g , clusterObjects , cluster , filterMetadataBeforeValidation )
316
330
317
331
// MachineDeployments
318
332
assertMachineDeployments (g , clusterClassObjects , clusterObjects , cluster , clusterClass )
319
333
assertMachineSets (g , clusterObjects , cluster )
320
- assertMachineSetsMachines (g , clusterObjects , cluster )
334
+ assertMachineSetsMachines (g , clusterObjects , cluster , filterMetadataBeforeValidation )
321
335
322
336
// MachinePools
323
337
assertMachinePools (g , clusterClassObjects , clusterObjects , cluster , clusterClass )
@@ -430,13 +444,14 @@ func assertControlPlane(g Gomega, clusterClassObjects clusterClassObjects, clust
430
444
))
431
445
}
432
446
433
- func assertControlPlaneMachines (g Gomega , clusterObjects clusterObjects , cluster * clusterv1.Cluster ) {
447
+ func assertControlPlaneMachines (g Gomega , clusterObjects clusterObjects , cluster * clusterv1.Cluster , filterMetadataBeforeValidation func ( object client. Object ) clusterv1. ObjectMeta ) {
434
448
controlPlaneMachineTemplateMetadata := mustMetadata (contract .ControlPlane ().MachineTemplate ().Metadata ().Get (clusterObjects .ControlPlane ))
435
449
controlPlaneInfrastructureMachineTemplateTemplateMetadata := mustMetadata (contract .InfrastructureMachineTemplate ().Template ().Metadata ().Get (clusterObjects .ControlPlaneInfrastructureMachineTemplate ))
436
450
437
451
for _ , machine := range clusterObjects .ControlPlaneMachines {
438
452
// ControlPlane Machine.metadata
439
- g .Expect (machine .Labels ).To (BeEquivalentTo (
453
+ machineMetadata := filterMetadataBeforeValidation (machine )
454
+ g .Expect (machineMetadata .Labels ).To (BeEquivalentTo (
440
455
union (
441
456
map [string ]string {
442
457
clusterv1 .ClusterNameLabel : cluster .Name ,
@@ -449,17 +464,18 @@ func assertControlPlaneMachines(g Gomega, clusterObjects clusterObjects, cluster
449
464
))
450
465
g .Expect (
451
466
union (
452
- machine .Annotations ,
467
+ machineMetadata .Annotations ,
453
468
).without (g , controlplanev1 .KubeadmClusterConfigurationAnnotation ),
454
469
).To (BeEquivalentTo (
455
470
controlPlaneMachineTemplateMetadata .Annotations ,
456
471
))
457
472
458
473
// ControlPlane Machine InfrastructureMachine.metadata
459
474
infrastructureMachine := clusterObjects .InfrastructureMachineByMachine [machine .Name ]
475
+ infrastructureMachineMetadata := filterMetadataBeforeValidation (infrastructureMachine )
460
476
controlPlaneMachineTemplateInfrastructureRef , err := contract .ControlPlane ().MachineTemplate ().InfrastructureRef ().Get (clusterObjects .ControlPlane )
461
477
g .Expect (err ).ToNot (HaveOccurred ())
462
- g .Expect (infrastructureMachine . GetLabels () ).To (BeEquivalentTo (
478
+ g .Expect (infrastructureMachineMetadata . Labels ).To (BeEquivalentTo (
463
479
union (
464
480
map [string ]string {
465
481
clusterv1 .ClusterNameLabel : cluster .Name ,
@@ -471,7 +487,7 @@ func assertControlPlaneMachines(g Gomega, clusterObjects clusterObjects, cluster
471
487
controlPlaneInfrastructureMachineTemplateTemplateMetadata .Labels ,
472
488
),
473
489
))
474
- g .Expect (infrastructureMachine . GetAnnotations () ).To (BeEquivalentTo (
490
+ g .Expect (infrastructureMachineMetadata . Annotations ).To (BeEquivalentTo (
475
491
union (
476
492
map [string ]string {
477
493
clusterv1 .TemplateClonedFromGroupKindAnnotation : groupKind (controlPlaneMachineTemplateInfrastructureRef ),
@@ -484,7 +500,8 @@ func assertControlPlaneMachines(g Gomega, clusterObjects clusterObjects, cluster
484
500
485
501
// ControlPlane Machine BootstrapConfig.metadata
486
502
bootstrapConfig := clusterObjects .BootstrapConfigByMachine [machine .Name ]
487
- g .Expect (bootstrapConfig .GetLabels ()).To (BeEquivalentTo (
503
+ bootstrapConfigMetadata := filterMetadataBeforeValidation (bootstrapConfig )
504
+ g .Expect (bootstrapConfigMetadata .Labels ).To (BeEquivalentTo (
488
505
union (
489
506
map [string ]string {
490
507
clusterv1 .ClusterNameLabel : cluster .Name ,
@@ -497,16 +514,18 @@ func assertControlPlaneMachines(g Gomega, clusterObjects clusterObjects, cluster
497
514
))
498
515
g .Expect (
499
516
union (
500
- bootstrapConfig . GetAnnotations () ,
517
+ bootstrapConfigMetadata . Annotations ,
501
518
).without (g , clusterv1 .MachineCertificatesExpiryDateAnnotation ),
502
519
).To (BeEquivalentTo (
503
520
controlPlaneMachineTemplateMetadata .Annotations ,
504
521
))
505
522
506
523
// ControlPlane Machine Node.metadata
507
524
node := clusterObjects .NodesByMachine [machine .Name ]
508
- for k , v := range getManagedLabels (machine .Labels ) {
509
- g .Expect (node .GetLabels ()).To (HaveKeyWithValue (k , v ))
525
+ nodeMetadata := filterMetadataBeforeValidation (node )
526
+
527
+ for k , v := range getManagedLabels (machineMetadata .Labels ) {
528
+ g .Expect (nodeMetadata .Labels ).To (HaveKeyWithValue (k , v ))
510
529
}
511
530
}
512
531
}
@@ -790,7 +809,7 @@ func assertMachineSets(g Gomega, clusterObjects clusterObjects, cluster *cluster
790
809
}
791
810
}
792
811
793
- func assertMachineSetsMachines (g Gomega , clusterObjects clusterObjects , cluster * clusterv1.Cluster ) {
812
+ func assertMachineSetsMachines (g Gomega , clusterObjects clusterObjects , cluster * clusterv1.Cluster , filterMetadataBeforeValidation func ( object client. Object ) clusterv1. ObjectMeta ) {
794
813
for _ , machineDeployment := range clusterObjects .MachineDeployments {
795
814
mdTopology := getMDTopology (cluster , machineDeployment )
796
815
infrastructureMachineTemplate := clusterObjects .InfrastructureMachineTemplateByMachineDeployment [machineDeployment .Name ]
@@ -802,8 +821,9 @@ func assertMachineSetsMachines(g Gomega, clusterObjects clusterObjects, cluster
802
821
machineTemplateHash := machineSet .Labels [clusterv1 .MachineDeploymentUniqueLabel ]
803
822
804
823
for _ , machine := range clusterObjects .MachinesByMachineSet [machineSet .Name ] {
824
+ machineMetadata := filterMetadataBeforeValidation (machine )
805
825
// MachineDeployment MachineSet Machine.metadata
806
- g .Expect (machine .Labels ).To (BeEquivalentTo (
826
+ g .Expect (machineMetadata .Labels ).To (BeEquivalentTo (
807
827
union (
808
828
map [string ]string {
809
829
clusterv1 .ClusterNameLabel : cluster .Name ,
@@ -816,13 +836,14 @@ func assertMachineSetsMachines(g Gomega, clusterObjects clusterObjects, cluster
816
836
machineSet .Spec .Template .Labels ,
817
837
),
818
838
))
819
- g .Expect (machine .Annotations ).To (BeEquivalentTo (
839
+ g .Expect (machineMetadata .Annotations ).To (BeEquivalentTo (
820
840
machineSet .Spec .Template .Annotations ,
821
841
))
822
842
823
843
// MachineDeployment MachineSet Machine InfrastructureMachine.metadata
824
844
infrastructureMachine := clusterObjects .InfrastructureMachineByMachine [machine .Name ]
825
- g .Expect (infrastructureMachine .GetLabels ()).To (BeEquivalentTo (
845
+ infrastructureMachineMetadata := filterMetadataBeforeValidation (infrastructureMachine )
846
+ g .Expect (infrastructureMachineMetadata .Labels ).To (BeEquivalentTo (
826
847
union (
827
848
map [string ]string {
828
849
clusterv1 .ClusterNameLabel : cluster .Name ,
@@ -836,7 +857,7 @@ func assertMachineSetsMachines(g Gomega, clusterObjects clusterObjects, cluster
836
857
infrastructureMachineTemplateTemplateMetadata .Labels ,
837
858
),
838
859
))
839
- g .Expect (infrastructureMachine . GetAnnotations () ).To (BeEquivalentTo (
860
+ g .Expect (infrastructureMachineMetadata . Annotations ).To (BeEquivalentTo (
840
861
union (
841
862
map [string ]string {
842
863
clusterv1 .TemplateClonedFromGroupKindAnnotation : groupKind (& machineSet .Spec .Template .Spec .InfrastructureRef ),
@@ -849,7 +870,8 @@ func assertMachineSetsMachines(g Gomega, clusterObjects clusterObjects, cluster
849
870
850
871
// MachineDeployment MachineSet Machine BootstrapConfig.metadata
851
872
bootstrapConfig := clusterObjects .BootstrapConfigByMachine [machine .Name ]
852
- g .Expect (bootstrapConfig .GetLabels ()).To (BeEquivalentTo (
873
+ bootstrapConfigMetadata := filterMetadataBeforeValidation (bootstrapConfig )
874
+ g .Expect (bootstrapConfigMetadata .Labels ).To (BeEquivalentTo (
853
875
union (
854
876
map [string ]string {
855
877
clusterv1 .ClusterNameLabel : cluster .Name ,
@@ -863,7 +885,7 @@ func assertMachineSetsMachines(g Gomega, clusterObjects clusterObjects, cluster
863
885
bootstrapConfigTemplateTemplateMetadata .Labels ,
864
886
),
865
887
))
866
- g .Expect (bootstrapConfig . GetAnnotations () ).To (BeEquivalentTo (
888
+ g .Expect (bootstrapConfigMetadata . Annotations ).To (BeEquivalentTo (
867
889
union (
868
890
map [string ]string {
869
891
clusterv1 .TemplateClonedFromGroupKindAnnotation : groupKind (machineSet .Spec .Template .Spec .Bootstrap .ConfigRef ),
@@ -876,8 +898,9 @@ func assertMachineSetsMachines(g Gomega, clusterObjects clusterObjects, cluster
876
898
877
899
// MachineDeployment MachineSet Machine Node.metadata
878
900
node := clusterObjects .NodesByMachine [machine .Name ]
879
- for k , v := range getManagedLabels (machine .Labels ) {
880
- g .Expect (node .GetLabels ()).To (HaveKeyWithValue (k , v ))
901
+ nodeMetadata := filterMetadataBeforeValidation (node )
902
+ for k , v := range getManagedLabels (machineMetadata .Labels ) {
903
+ g .Expect (nodeMetadata .Labels ).To (HaveKeyWithValue (k , v ))
881
904
}
882
905
}
883
906
}
0 commit comments