File tree Expand file tree Collapse file tree 1 file changed +10
-6
lines changed Expand file tree Collapse file tree 1 file changed +10
-6
lines changed Original file line number Diff line number Diff line change @@ -154,6 +154,9 @@ type ControllerConfig struct {
154154 Namespace string
155155}
156156
157+ // cached value for the GetOperatorNamespace
158+ var operatorNamespace string
159+
157160func (n NamespacedName ) String () string {
158161 return types .NamespacedName (n ).String ()
159162}
@@ -192,11 +195,12 @@ func (n *NamespacedName) DecodeWorker(value, operatorNamespace string) error {
192195// GetOperatorNamespace assumes serviceaccount secret is mounted by kubernetes
193196// Placing this func here instead of pgk/util avoids circular import
194197func GetOperatorNamespace () string {
195-
196- operatorNamespaceBytes , err := ioutil .ReadFile (fileWithNamespace )
197- if err != nil {
198- log .Fatalf ("Unable to detect operator namespace from within its pod due to: %v" , err )
198+ if operatorNamespace == "" {
199+ operatorNamespaceBytes , err := ioutil .ReadFile (fileWithNamespace )
200+ if err != nil {
201+ log .Fatalf ("Unable to detect operator namespace from within its pod due to: %v" , err )
202+ }
203+ operatorNamespace = string (operatorNamespaceBytes )
199204 }
200-
201- return string (operatorNamespaceBytes )
205+ return operatorNamespace
202206}
You can’t perform that action at this time.
0 commit comments