@@ -311,9 +311,16 @@ func (d *Deployer) deployOperatorFromCSV(ctx context.Context, bundleDir string)
311311 d .useOperatorPullSecrets = d .config .Roxie .KonfluxImagesEnabled () && d .config .Roxie .ClusterType .NeedsPullSecrets ()
312312
313313 d .logger .Info ("📋 Operator deployment plan:" )
314- d .logger .Dim (fmt .Sprintf (" • Namespace: %s" , operatorNamespace ))
315- d .logger .Dim (fmt .Sprintf (" • ServiceAccount: %s" , serviceAccountName ))
316- d .logger .Dim (fmt .Sprintf (" • Setting up pull secrets: %v" , d .useOperatorPullSecrets ))
314+ d .logger .Dimf (" • Namespace: %s" , operatorNamespace )
315+ d .logger .Dimf (" • ServiceAccount: %s" , serviceAccountName )
316+ d .logger .Dimf (" • Setting up pull secrets: %v" , d .useOperatorPullSecrets )
317+ if len (d .config .Operator .EnvVars ) > 0 {
318+ d .logger .Dimf (" • Custom operator env vars: %d" , len (d .config .Operator .EnvVars ))
319+ for _ , envVar := range envVarsToSortedList (d .config .Operator .EnvVars ) {
320+ ev := envVar .(map [string ]interface {})
321+ d .logger .Dimf (" %s=%s" , ev ["name" ], ev ["value" ])
322+ }
323+ }
317324
318325 if err := d .prepareNamespace (ctx , operatorNamespace , d .useOperatorPullSecrets ); err != nil {
319326 return err
@@ -520,6 +527,16 @@ func (d *Deployer) createDeploymentFromCSV(ctx context.Context, namespace string
520527 if template , ok := spec ["template" ].(map [string ]interface {}); ok {
521528 if podSpec , ok := template ["spec" ].(map [string ]interface {}); ok {
522529 podSpec ["serviceAccountName" ] = deploymentSpec ["service_account" ]
530+
531+ if len (d .config .Operator .EnvVars ) > 0 {
532+ containers , ok := podSpec ["containers" ].([]interface {})
533+ if ! ok {
534+ return errors .New ("no containers found in deployment pod spec" )
535+ }
536+ if err := d .injectEnvVarsIntoManagerContainer (containers ); err != nil {
537+ return fmt .Errorf ("failed to inject operator env vars: %w" , err )
538+ }
539+ }
523540 }
524541 }
525542
@@ -538,6 +555,45 @@ func (d *Deployer) createDeploymentFromCSV(ctx context.Context, namespace string
538555 return nil
539556}
540557
558+ const managerContainerName = "manager"
559+
560+ // injectEnvVarsIntoManagerContainer merges configured operator env vars into
561+ // the manager container, overriding any existing env vars with the same name.
562+ func (d * Deployer ) injectEnvVarsIntoManagerContainer (containers []interface {}) error {
563+ for _ , c := range containers {
564+ container , ok := c .(map [string ]interface {})
565+ if ! ok {
566+ continue
567+ }
568+ if container ["name" ] != managerContainerName {
569+ continue
570+ }
571+
572+ existing := make (map [string ]int )
573+ envList , _ := container ["env" ].([]interface {})
574+ for i , item := range envList {
575+ if envVar , ok := item .(map [string ]interface {}); ok {
576+ if name , ok := envVar ["name" ].(string ); ok {
577+ existing [name ] = i
578+ }
579+ }
580+ }
581+
582+ for _ , envVar := range envVarsToSortedList (d .config .Operator .EnvVars ) {
583+ name := envVar .(map [string ]interface {})["name" ].(string )
584+ if idx , found := existing [name ]; found {
585+ envList [idx ] = envVar
586+ } else {
587+ envList = append (envList , envVar )
588+ }
589+ }
590+
591+ container ["env" ] = envList
592+ return nil
593+ }
594+ return fmt .Errorf ("container %q not found in deployment" , managerContainerName )
595+ }
596+
541597func (d * Deployer ) applyBundleServiceResources (ctx context.Context , bundleDir , namespace string ) error {
542598 serviceFile := filepath .Join (bundleDir , "rhacs-operator-controller-manager-metrics-service_v1_service.yaml" )
543599 if _ , err := os .Stat (serviceFile ); err == nil {
0 commit comments