github.com/percona/percona-xtradb-cluster-operator@v1.14.0/pkg/k8s/utils.go (about) 1 package k8s 2 3 import ( 4 "fmt" 5 "os" 6 "strings" 7 ) 8 9 const WatchNamespaceEnvVar = "WATCH_NAMESPACE" 10 11 // GetWatchNamespace returns the namespace the operator should be watching for changes 12 func GetWatchNamespace() (string, error) { 13 ns, found := os.LookupEnv(WatchNamespaceEnvVar) 14 if !found { 15 return "", fmt.Errorf("%s must be set", WatchNamespaceEnvVar) 16 } 17 return ns, nil 18 } 19 20 // GetOperatorNamespace returns the namespace of the operator pod 21 func GetOperatorNamespace() (string, error) { 22 nsBytes, err := os.ReadFile("/var/run/secrets/kubernetes.io/serviceaccount/namespace") 23 if err != nil { 24 return "", err 25 } 26 27 return strings.TrimSpace(string(nsBytes)), nil 28 }