mirror of
https://github.com/zalando/postgres-operator.git
synced 2026-10-18 07:00:09 +02:00
Avoid reading the namespace file every time the NamespacedName value is decoded. (#243)
This commit is contained in:
+10
-6
@@ -154,6 +154,9 @@ type ControllerConfig struct {
|
|||||||
Namespace string
|
Namespace string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// cached value for the GetOperatorNamespace
|
||||||
|
var operatorNamespace string
|
||||||
|
|
||||||
func (n NamespacedName) String() string {
|
func (n NamespacedName) String() string {
|
||||||
return types.NamespacedName(n).String()
|
return types.NamespacedName(n).String()
|
||||||
}
|
}
|
||||||
@@ -192,11 +195,12 @@ func (n *NamespacedName) DecodeWorker(value, operatorNamespace string) error {
|
|||||||
// GetOperatorNamespace assumes serviceaccount secret is mounted by kubernetes
|
// GetOperatorNamespace assumes serviceaccount secret is mounted by kubernetes
|
||||||
// Placing this func here instead of pgk/util avoids circular import
|
// Placing this func here instead of pgk/util avoids circular import
|
||||||
func GetOperatorNamespace() string {
|
func GetOperatorNamespace() string {
|
||||||
|
if operatorNamespace == "" {
|
||||||
operatorNamespaceBytes, err := ioutil.ReadFile(fileWithNamespace)
|
operatorNamespaceBytes, err := ioutil.ReadFile(fileWithNamespace)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("Unable to detect operator namespace from within its pod due to: %v", err)
|
log.Fatalf("Unable to detect operator namespace from within its pod due to: %v", err)
|
||||||
|
}
|
||||||
|
operatorNamespace = string(operatorNamespaceBytes)
|
||||||
}
|
}
|
||||||
|
return operatorNamespace
|
||||||
return string(operatorNamespaceBytes)
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user