@@ -335,35 +335,34 @@ func (d *Deployer) waitForCSVSuccess(ctx context.Context) error {
335335
336336// detectOperatorDeploymentMode detects how the operator is currently deployed.
337337// Returns (operatorExists bool, isOLM OperatorDeploymentMode)
338- func (d * Deployer ) detectOperatorDeploymentMode (ctx context.Context ) (bool , OperatorDeploymentMode ) {
338+ func (d * Deployer ) detectOperatorDeploymentMode (ctx context.Context ) (bool , OperatorDeploymentMode , error ) {
339+ const olmOwnerLabel = "olm.owner"
340+
339341 // First, check if a Subscription exists (OLM-specific resource)
340342 _ , err := d .runKubectl (ctx , k8s.KubectlOptions {
341343 Args : []string {"get" , "subscription" , subscriptionName , "-n" , operatorNamespace },
342344 })
343345 if err == nil {
344- return true , OperatorModeOLM
346+ return true , OperatorModeOLM , nil
345347 }
346348
347- // If no subscription, check if operator deployment exists.
348- _ , err = d .runKubectl (ctx , k8s.KubectlOptions {
349- Args : []string {"get" , "deployment" , operatorDeploymentName , "-n" , operatorNamespace },
350- })
351- if err == nil {
352- // Deployment exists - check if it has OLM owner labels.
353- result , err := d .runKubectl (ctx , k8s.KubectlOptions {
354- Args : []string {"get" , "deployment" , operatorDeploymentName , "-n" , operatorNamespace , "-o" , "jsonpath={.metadata.labels}" },
355- })
356- // TODO(ROX-34499): This is not very robust. Better retrieve a specific label in the `get`
357- // command?
358- if err == nil && strings .Contains (result .Stdout , "olm.owner" ) {
359- return true , OperatorModeOLM
360- }
361- // Deployment exists without OLM labels = non-OLM deployment.
362- return true , OperatorModeNonOLM
349+ // If no subscription, check if operator deployment exists/if it has the expected OLM label.
350+ labelValue , err := k8s .RetrieveClusterResourceLabel (ctx , d .logger , operatorNamespace , "deployment" , operatorDeploymentName , olmOwnerLabel )
351+ if k8s .IsResourceNotFound (err ) {
352+ // No operator deployment found.
353+ return false , OperatorModeNonOLM , nil
354+ }
355+ if err != nil {
356+ return false , OperatorModeNonOLM , err
357+ }
358+
359+ if labelValue == "" {
360+ // Deployment exists without OLM labels -> non-OLM deployment.
361+ return true , OperatorModeNonOLM , nil
363362 }
364363
365- // No operator found .
366- return false , OperatorModeNonOLM
364+ // Label set -> OLM deployment .
365+ return true , OperatorModeOLM , nil
367366}
368367
369368// teardownOperatorOLM removes the operator when installed via OLM.
0 commit comments