@@ -37,6 +37,7 @@ import (
3737 "github.com/mongodb/mongodb-atlas-kubernetes/pkg/controller/atlasdatabaseuser"
3838 "github.com/mongodb/mongodb-atlas-kubernetes/pkg/controller/atlasproject"
3939 "github.com/mongodb/mongodb-atlas-kubernetes/pkg/controller/watch"
40+ "github.com/mongodb/mongodb-atlas-kubernetes/pkg/util/kube"
4041 // +kubebuilder:scaffold:imports
4142)
4243
@@ -76,14 +77,14 @@ func main() {
7677 os .Exit (1 )
7778 }
7879
79- operatorPod := operatorPodObjectKey ()
80+ operatorPod := operatorDeploymentObjectKey ()
8081
8182 if err = (& atlascluster.AtlasClusterReconciler {
82- Client : mgr .GetClient (),
83- Log : logger .Named ("controllers" ).Named ("AtlasCluster" ).Sugar (),
84- Scheme : mgr .GetScheme (),
85- AtlasDomain : config .AtlasDomain ,
86- OperatorPod : operatorPod ,
83+ Client : mgr .GetClient (),
84+ Log : logger .Named ("controllers" ).Named ("AtlasCluster" ).Sugar (),
85+ Scheme : mgr .GetScheme (),
86+ AtlasDomain : config .AtlasDomain ,
87+ OperatorDeploymentName : operatorPod ,
8788 }).SetupWithManager (mgr ); err != nil {
8889 setupLog .Error (err , "unable to create controller" , "controller" , "AtlasCluster" )
8990 os .Exit (1 )
@@ -159,15 +160,18 @@ func parseConfiguration(log *zap.SugaredLogger) Config {
159160 return config
160161}
161162
162- func operatorPodObjectKey () client.ObjectKey {
163- operatorName := os .Getenv ("OPERATOR_NAME " )
164- if operatorName == "" {
165- log .Fatal (`"OPERATOR_NAME " environment variable must be set!` )
163+ func operatorDeploymentObjectKey () client.ObjectKey {
164+ operatorPodName := os .Getenv ("OPERATOR_POD_NAME " )
165+ if operatorPodName == "" {
166+ log .Fatal (`"OPERATOR_POD_NAME " environment variable must be set!` )
166167 }
167168 operatorNamespace := os .Getenv ("OPERATOR_NAMESPACE" )
168169 if operatorNamespace == "" {
169170 log .Fatal (`"OPERATOR_NAMESPACE" environment variable must be set!` )
170171 }
171-
172- return client.ObjectKey {Namespace : operatorNamespace , Name : operatorName }
172+ deploymentName , err := kube .ParseDeploymentNameFromPodName (operatorPodName )
173+ if err != nil {
174+ log .Fatalf (`Failed to get Operator Deployment name from "OPERATOR_POD_NAME" environment variable: %s` , err .Error ())
175+ }
176+ return client.ObjectKey {Namespace : operatorNamespace , Name : deploymentName }
173177}
0 commit comments