@@ -308,6 +308,8 @@ func TestComputeControlPlane(t *testing.T) {
308308 cluster : scope .Current .Cluster ,
309309 templateRef : blueprint .ClusterClass .Spec .ControlPlane .Ref ,
310310 template : blueprint .ControlPlane .Template ,
311+ labels : mergeMap (blueprint .Topology .ControlPlane .Metadata .Labels , blueprint .ClusterClass .Spec .ControlPlane .Metadata .Labels ),
312+ annotations : mergeMap (blueprint .Topology .ControlPlane .Metadata .Annotations , blueprint .ClusterClass .Spec .ControlPlane .Metadata .Annotations ),
311313 currentRef : nil ,
312314 obj : obj ,
313315 })
@@ -349,6 +351,8 @@ func TestComputeControlPlane(t *testing.T) {
349351 cluster : scope .Current .Cluster ,
350352 templateRef : blueprint .ClusterClass .Spec .ControlPlane .Ref ,
351353 template : blueprint .ControlPlane .Template ,
354+ labels : mergeMap (blueprint .Topology .ControlPlane .Metadata .Labels , blueprint .ClusterClass .Spec .ControlPlane .Metadata .Labels ),
355+ annotations : mergeMap (blueprint .Topology .ControlPlane .Metadata .Annotations , blueprint .ClusterClass .Spec .ControlPlane .Metadata .Annotations ),
352356 currentRef : nil ,
353357 obj : obj ,
354358 })
@@ -391,18 +395,38 @@ func TestComputeControlPlane(t *testing.T) {
391395 cluster : scope .Current .Cluster ,
392396 templateRef : blueprint .ClusterClass .Spec .ControlPlane .Ref ,
393397 template : blueprint .ControlPlane .Template ,
398+ labels : mergeMap (blueprint .Topology .ControlPlane .Metadata .Labels , blueprint .ClusterClass .Spec .ControlPlane .Metadata .Labels ),
399+ annotations : mergeMap (blueprint .Topology .ControlPlane .Metadata .Annotations , blueprint .ClusterClass .Spec .ControlPlane .Metadata .Annotations ),
394400 currentRef : nil ,
395401 obj : obj ,
396402 })
397- gotMetadata , err := contract .ControlPlane ().MachineTemplate ().Metadata ().Get (obj )
403+
404+ gotMachineTemplateMetadata , err := contract .ControlPlane ().MachineTemplate ().Metadata ().Get (obj )
405+ g .Expect (err ).ToNot (HaveOccurred ())
406+
407+ gotControlPlaneMetadata , err := contract .ControlPlane ().Metadata ().Get (obj )
398408 g .Expect (err ).ToNot (HaveOccurred ())
399409
400410 expectedLabels := mergeMap (scope .Current .Cluster .Spec .Topology .ControlPlane .Metadata .Labels , blueprint .ClusterClass .Spec .ControlPlane .Metadata .Labels )
401411 expectedLabels [clusterv1 .ClusterLabelName ] = cluster .Name
402412 expectedLabels [clusterv1 .ClusterTopologyOwnedLabel ] = ""
403- g .Expect (gotMetadata ).To (Equal (& clusterv1.ObjectMeta {
413+
414+ expectedAnnotations := mergeMap (scope .Current .Cluster .Spec .Topology .ControlPlane .Metadata .Annotations , blueprint .ClusterClass .Spec .ControlPlane .Metadata .Annotations )
415+
416+ defaultControlPlaneAnnotations := map [string ]string {
417+ clusterv1 .TemplateClonedFromNameAnnotation : blueprint .ClusterClass .Spec .ControlPlane .Ref .Name ,
418+ clusterv1 .TemplateClonedFromGroupKindAnnotation : blueprint .ClusterClass .Spec .ControlPlane .Ref .GroupVersionKind ().GroupKind ().String (),
419+ }
420+ expectedControlPlaneAnnotations := mergeMap (defaultControlPlaneAnnotations , expectedAnnotations )
421+
422+ g .Expect (gotMachineTemplateMetadata ).To (Equal (& clusterv1.ObjectMeta {
423+ Labels : expectedLabels ,
424+ Annotations : expectedAnnotations ,
425+ }))
426+
427+ g .Expect (gotControlPlaneMetadata ).To (Equal (& clusterv1.ObjectMeta {
404428 Labels : expectedLabels ,
405- Annotations : mergeMap ( scope . Current . Cluster . Spec . Topology . ControlPlane . Metadata . Annotations , blueprint . ClusterClass . Spec . ControlPlane . Metadata . Annotations ) ,
429+ Annotations : expectedControlPlaneAnnotations ,
406430 }))
407431
408432 assertNestedField (g , obj , version , contract .ControlPlane ().Version ().Path ()... )
@@ -444,6 +468,8 @@ func TestComputeControlPlane(t *testing.T) {
444468 templateRef : blueprint .ClusterClass .Spec .ControlPlane .Ref ,
445469 template : blueprint .ControlPlane .Template ,
446470 currentRef : scope .Current .Cluster .Spec .ControlPlaneRef ,
471+ labels : mergeMap (blueprint .Topology .ControlPlane .Metadata .Labels , blueprint .ClusterClass .Spec .ControlPlane .Metadata .Labels ),
472+ annotations : mergeMap (blueprint .Topology .ControlPlane .Metadata .Annotations , blueprint .ClusterClass .Spec .ControlPlane .Metadata .Annotations ),
447473 obj : obj ,
448474 })
449475 })
@@ -1361,6 +1387,9 @@ func TestComputeMachineDeployment(t *testing.T) {
13611387
13621388 g .Expect (actualMd .Labels ).To (HaveKeyWithValue (clusterv1 .ClusterTopologyMachineDeploymentLabelName , "big-pool-of-machines" ))
13631389 g .Expect (actualMd .Labels ).To (HaveKey (clusterv1 .ClusterTopologyOwnedLabel ))
1390+ g .Expect (actualMd .Labels ).To (HaveKeyWithValue ("foo" , "baz" ))
1391+ g .Expect (actualMd .Labels ).To (HaveKeyWithValue ("fizz" , "buzz" ))
1392+ g .Expect (actualMd .Annotations ).To (HaveKeyWithValue ("annotation-1" , "annotation-1-val" ))
13641393 g .Expect (controllerutil .ContainsFinalizer (actualMd , clusterv1 .MachineDeploymentTopologyFinalizer )).To (BeTrue ())
13651394
13661395 g .Expect (actualMd .Spec .Selector .MatchLabels ).To (HaveKey (clusterv1 .ClusterTopologyOwnedLabel ))
@@ -1369,6 +1398,7 @@ func TestComputeMachineDeployment(t *testing.T) {
13691398 g .Expect (actualMd .Spec .Template .ObjectMeta .Labels ).To (HaveKeyWithValue ("foo" , "baz" ))
13701399 g .Expect (actualMd .Spec .Template .ObjectMeta .Labels ).To (HaveKeyWithValue ("fizz" , "buzz" ))
13711400 g .Expect (actualMd .Spec .Template .ObjectMeta .Labels ).To (HaveKey (clusterv1 .ClusterTopologyOwnedLabel ))
1401+ g .Expect (actualMd .Spec .Template .ObjectMeta .Annotations ).To (HaveKeyWithValue ("annotation-1" , "annotation-1-val" ))
13721402 g .Expect (actualMd .Spec .Template .Spec .InfrastructureRef .Name ).ToNot (Equal ("linux-worker-inframachinetemplate" ))
13731403 g .Expect (actualMd .Spec .Template .Spec .Bootstrap .ConfigRef .Name ).ToNot (Equal ("linux-worker-bootstraptemplate" ))
13741404 })
@@ -1415,11 +1445,15 @@ func TestComputeMachineDeployment(t *testing.T) {
14151445
14161446 g .Expect (actualMd .Labels ).To (HaveKeyWithValue (clusterv1 .ClusterTopologyMachineDeploymentLabelName , "big-pool-of-machines" ))
14171447 g .Expect (actualMd .Labels ).To (HaveKey (clusterv1 .ClusterTopologyOwnedLabel ))
1448+ g .Expect (actualMd .Labels ).To (HaveKeyWithValue ("foo" , "baz" ))
1449+ g .Expect (actualMd .Labels ).To (HaveKeyWithValue ("fizz" , "buzz" ))
1450+ g .Expect (actualMd .Annotations ).To (HaveKeyWithValue ("annotation-1" , "annotation-1-val" ))
14181451 g .Expect (controllerutil .ContainsFinalizer (actualMd , clusterv1 .MachineDeploymentTopologyFinalizer )).To (BeFalse ())
14191452
14201453 g .Expect (actualMd .Spec .Template .ObjectMeta .Labels ).To (HaveKeyWithValue ("foo" , "baz" ))
14211454 g .Expect (actualMd .Spec .Template .ObjectMeta .Labels ).To (HaveKeyWithValue ("fizz" , "buzz" ))
14221455 g .Expect (actualMd .Spec .Template .ObjectMeta .Labels ).To (HaveKey (clusterv1 .ClusterTopologyOwnedLabel ))
1456+ g .Expect (actualMd .Spec .Template .ObjectMeta .Annotations ).To (HaveKeyWithValue ("annotation-1" , "annotation-1-val" ))
14231457 g .Expect (actualMd .Spec .Template .Spec .InfrastructureRef .Name ).To (Equal ("linux-worker-inframachinetemplate" ))
14241458 g .Expect (actualMd .Spec .Template .Spec .Bootstrap .ConfigRef .Name ).To (Equal ("linux-worker-bootstraptemplate" ))
14251459 })
0 commit comments