@@ -263,6 +263,7 @@ func RunOperator(ctx context.Context, controllerConfig *controllercmd.Controller
263
263
hyperShiftControlPlaneIsolationHook (hcpInformer .Lister (), controlPlaneNamespace ),
264
264
hyperShiftColocationHook (controlPlaneNamespace ),
265
265
hyperShiftNodeSelectorHook (hcpInformer .Lister (), controlPlaneNamespace ),
266
+ hyperShiftLabelsHook (hcpInformer .Lister (), controlPlaneNamespace ),
266
267
hyperShiftSetSecurityContext (),
267
268
}
268
269
@@ -420,6 +421,39 @@ func getHostedControlPlaneNodeSelector(hostedControlPlaneLister cache.GenericLis
420
421
return nodeSelector , nil
421
422
}
422
423
424
+ func hyperShiftLabelsHook (hcpLister cache.GenericLister , controlPlaneNamespace string ) dc.DeploymentHookFunc {
425
+ return func (_ * operatorv1.OperatorSpec , d * appsv1.Deployment ) error {
426
+ labels , err := getHostedControlPlaneLabels (hcpLister , controlPlaneNamespace )
427
+ if err != nil {
428
+ return err
429
+ }
430
+
431
+ for key , value := range labels {
432
+ // don't replace existing labels as they are used in the deployment's labelSelector.
433
+ if _ , exist := d .Spec .Template .Labels [key ]; ! exist {
434
+ d .Spec .Template .Labels [key ] = value
435
+ }
436
+ }
437
+ return nil
438
+ }
439
+ }
440
+
441
+ func getHostedControlPlaneLabels (hostedControlPlaneLister cache.GenericLister , namespace string ) (map [string ]string , error ) {
442
+ hcp , err := getHostedControlPlane (hostedControlPlaneLister , namespace )
443
+ if err != nil {
444
+ return nil , err
445
+ }
446
+ labels , exists , err := unstructured .NestedStringMap (hcp .UnstructuredContent (), "spec" , "labels" )
447
+ if ! exists {
448
+ return nil , nil
449
+ }
450
+ if err != nil {
451
+ return nil , err
452
+ }
453
+ klog .V (4 ).Infof ("Using labels %v" , labels )
454
+ return labels , nil
455
+ }
456
+
423
457
func getHostedControlPlaneTolerations (hostedControlPlaneLister cache.GenericLister , namespace string ) ([]corev1.Toleration , error ) {
424
458
hcp , err := getHostedControlPlane (hostedControlPlaneLister , namespace )
425
459
if err != nil {
0 commit comments