@@ -42,6 +42,7 @@ import (
4242 fakeclient "sigs.k8s.io/controller-runtime/pkg/client/fake"
4343 "sigs.k8s.io/controller-runtime/pkg/reconcile"
4444
45+ bootstrapv1alpha1 "github.com/openshift-assisted/cluster-api-provider-openshift-assisted/bootstrap/api/v1alpha1"
4546 controlplanev1alpha2 "github.com/openshift-assisted/cluster-api-provider-openshift-assisted/controlplane/api/v1alpha2"
4647 testutils "github.com/openshift-assisted/cluster-api-provider-openshift-assisted/test/utils"
4748 corev1 "k8s.io/api/core/v1"
@@ -871,6 +872,98 @@ var _ = Describe("Scale operations and machine updates", func() {
871872 Expect (oacp .Status .UpdatedReplicas ).To (Equal (int32 (0 )))
872873 })
873874 })
875+
876+ Context ("Label propagation" , func () {
877+ BeforeEach (func () {
878+ oacp .Spec .Replicas = 1
879+ // Add custom labels to the OpenshiftAssistedControlPlane
880+ oacp .Labels = map [string ]string {
881+ "custom-label" : "custom-value" ,
882+ "discovery-ignition" : "enabled" ,
883+ "test-label" : "test-value" ,
884+ }
885+ Expect (k8sClient .Create (ctx , oacp )).To (Succeed ())
886+ })
887+
888+ It ("should copy labels from OpenshiftAssistedControlPlane to OpenshiftAssistedConfig" , func () {
889+ // Reconcile to create machines and bootstrap configs
890+ result , err := controllerReconciler .Reconcile (ctx , reconcile.Request {NamespacedName : typeNamespacedName })
891+ Expect (err ).NotTo (HaveOccurred ())
892+ Expect (result ).To (Equal (ctrlruntime.Result {}))
893+
894+ // Get the created bootstrap configs
895+ bootstrapConfigList := & bootstrapv1alpha1.OpenshiftAssistedConfigList {}
896+ Expect (k8sClient .List (ctx , bootstrapConfigList , client .InNamespace (namespace ))).To (Succeed ())
897+ Expect (bootstrapConfigList .Items ).To (HaveLen (1 ))
898+
899+ bootstrapConfig := & bootstrapConfigList .Items [0 ]
900+
901+ // Verify that custom labels from oacp are present in the bootstrap config
902+ Expect (bootstrapConfig .Labels ).To (HaveKeyWithValue ("custom-label" , "custom-value" ))
903+ Expect (bootstrapConfig .Labels ).To (HaveKeyWithValue ("discovery-ignition" , "enabled" ))
904+ Expect (bootstrapConfig .Labels ).To (HaveKeyWithValue ("test-label" , "test-value" ))
905+
906+ // Verify that standard control plane labels are also present
907+ Expect (bootstrapConfig .Labels ).To (HaveKeyWithValue (clusterv1 .ClusterNameLabel , clusterName ))
908+ Expect (bootstrapConfig .Labels ).To (HaveKey (clusterv1 .MachineControlPlaneLabel ))
909+ Expect (bootstrapConfig .Labels ).To (HaveKey (clusterv1 .MachineControlPlaneNameLabel ))
910+ })
911+
912+ It ("should not override standard control plane labels with custom labels" , func () {
913+ // Update oacp with labels that would conflict with standard labels
914+ Expect (k8sClient .Get (ctx , typeNamespacedName , oacp )).To (Succeed ())
915+ oacp .Labels [clusterv1 .ClusterNameLabel ] = "wrong-cluster-name"
916+ Expect (k8sClient .Update (ctx , oacp )).To (Succeed ())
917+
918+ // Reconcile to create machines and bootstrap configs
919+ result , err := controllerReconciler .Reconcile (ctx , reconcile.Request {NamespacedName : typeNamespacedName })
920+ Expect (err ).NotTo (HaveOccurred ())
921+ Expect (result ).To (Equal (ctrlruntime.Result {}))
922+
923+ // Get the created bootstrap configs
924+ bootstrapConfigList := & bootstrapv1alpha1.OpenshiftAssistedConfigList {}
925+ Expect (k8sClient .List (ctx , bootstrapConfigList , client .InNamespace (namespace ))).To (Succeed ())
926+ Expect (bootstrapConfigList .Items ).To (HaveLen (1 ))
927+
928+ bootstrapConfig := & bootstrapConfigList .Items [0 ]
929+
930+ // Verify that the standard cluster name label is NOT overridden by the custom label
931+ Expect (bootstrapConfig .Labels ).To (HaveKeyWithValue (clusterv1 .ClusterNameLabel , clusterName ))
932+ Expect (bootstrapConfig .Labels ).NotTo (HaveKeyWithValue (clusterv1 .ClusterNameLabel , "wrong-cluster-name" ))
933+ })
934+ })
935+
936+ Context ("Annotation propagation for discovery ignition" , func () {
937+ BeforeEach (func () {
938+ oacp .Spec .Replicas = 1
939+ })
940+
941+ It ("should propagate discovery-ignition-override annotation from OpenshiftAssistedControlPlane to OpenshiftAssistedConfig" , func () {
942+ // Add discovery-ignition-override annotation to the OpenshiftAssistedControlPlane
943+ discoveryIgnitionOverride := `{"ignition":{"version":"3.2.0"},"storage":{"files":[{"path":"/etc/test","contents":{"source":"data:,test"}}]}}`
944+ oacp .Annotations = map [string ]string {
945+ bootstrapv1alpha1 .DiscoveryIgnitionOverrideAnnotation : discoveryIgnitionOverride ,
946+ "custom-annotation" : "custom-value" ,
947+ }
948+ Expect (k8sClient .Create (ctx , oacp )).To (Succeed ())
949+
950+ // Reconcile to create machines and bootstrap configs
951+ result , err := controllerReconciler .Reconcile (ctx , reconcile.Request {NamespacedName : typeNamespacedName })
952+ Expect (err ).NotTo (HaveOccurred ())
953+ Expect (result ).To (Equal (ctrlruntime.Result {}))
954+
955+ // Get the created bootstrap configs
956+ bootstrapConfigList := & bootstrapv1alpha1.OpenshiftAssistedConfigList {}
957+ Expect (k8sClient .List (ctx , bootstrapConfigList , client .InNamespace (namespace ))).To (Succeed ())
958+ Expect (bootstrapConfigList .Items ).To (HaveLen (1 ))
959+
960+ bootstrapConfig := & bootstrapConfigList .Items [0 ]
961+
962+ // Verify that annotations from oacp are present in the bootstrap config
963+ Expect (bootstrapConfig .Annotations ).To (HaveKeyWithValue (bootstrapv1alpha1 .DiscoveryIgnitionOverrideAnnotation , discoveryIgnitionOverride ))
964+ Expect (bootstrapConfig .Annotations ).To (HaveKeyWithValue ("custom-annotation" , "custom-value" ))
965+ })
966+ })
874967})
875968
876969// Create dummy machine template
0 commit comments