@@ -39,7 +39,7 @@ func NewDefaultOperatorControllerConfig(flavour generator.ClusterFlavour, c *cli
3939 cfg .AddDeploymentHookBuilders (c , withClusterWideProxy , withStandaloneReplicas )
4040 } else {
4141 // HyperShift
42- cfg .AddDeploymentHookBuilders (c , withHyperShiftReplicas , withHyperShiftNodeSelector , withHyperShiftControlPlaneImages , withHyperShiftCustomTolerations )
42+ cfg .AddDeploymentHookBuilders (c , withHyperShiftReplicas , withHyperShiftNodeSelector , withHyperShiftLabels , withHyperShiftControlPlaneImages , withHyperShiftCustomTolerations )
4343 }
4444
4545 return cfg
@@ -141,6 +141,49 @@ func getHostedControlPlaneTolerations(hostedControlPlaneLister hypev1beta1lister
141141 return tolerations , nil
142142}
143143
144+ // withHyperShiftLabels sets Deployment labels on a HyperShift hosted control-plane.
145+ func withHyperShiftLabels (c * clients.Clients ) (dc.DeploymentHookFunc , []factory.Informer ) {
146+ hook := func (_ * opv1.OperatorSpec , deployment * appsv1.Deployment ) error {
147+ labels , err := getHostedControlLabels (
148+ c .ControlPlaneHypeInformer .Hypershift ().V1beta1 ().HostedControlPlanes ().Lister (),
149+ c .ControlPlaneNamespace )
150+ if err != nil {
151+ return err
152+ }
153+
154+ if deployment .Spec .Template .Labels == nil {
155+ deployment .Spec .Template .Labels = map [string ]string {}
156+ }
157+
158+ for key , value := range labels {
159+ // don't replace existing labels as they are used in the deployment's labelSelector.
160+ if _ , exist := deployment .Spec .Template .Labels [key ]; ! exist {
161+ deployment .Spec .Template .Labels [key ] = value
162+ }
163+ }
164+ return nil
165+ }
166+ informers := []factory.Informer {
167+ c .ControlPlaneHypeInformer .Hypershift ().V1beta1 ().HostedControlPlanes ().Informer (),
168+ }
169+ return hook , informers
170+ }
171+
172+ // getHostedControlLabels returns the labels from the HostedControlPlane CR.
173+ func getHostedControlLabels (hostedControlPlaneLister hypev1beta1listers.HostedControlPlaneLister , namespace string ) (map [string ]string , error ) {
174+ hcp , err := getHostedControlPlane (hostedControlPlaneLister , namespace )
175+ if err != nil {
176+ return nil , err
177+ }
178+ labels := hcp .Spec .Labels
179+ if len (labels ) == 0 {
180+ return nil , nil
181+ }
182+ klog .V (4 ).Infof ("Using labels %v" , labels )
183+ return labels , nil
184+
185+ }
186+
144187// getHostedControlPlane returns the HostedControlPlane CR.
145188func getHostedControlPlane (hostedControlPlaneLister hypev1beta1listers.HostedControlPlaneLister , namespace string ) (* hypev1beta1api.HostedControlPlane , error ) {
146189 list , err := hostedControlPlaneLister .List (labels .Everything ())
0 commit comments