/
k8sutil.go
33 lines (28 loc) · 1.01 KB
/
k8sutil.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package util
import (
"fmt"
"os"
)
// WatchNamespaceEnvVar is the constant for env variable WATCH_NAMESPACE
// which is the namespace where the watch activity happens.
// this value is empty if the operator is running with clusterScope.
const WatchNamespaceEnvVar = "WATCH_NAMESPACE"
// GetWatchNamespace returns the namespace the operator should be watching for changes
func GetWatchNamespace() (string, error) {
ns, found := os.LookupEnv(WatchNamespaceEnvVar)
if !found {
return "", fmt.Errorf("%s must be set", WatchNamespaceEnvVar)
}
return ns, nil
}
// OperatorNamespaceEnvVar is the constant for env variable OPERATOR_NAMESPACE
// which is the namespace where operator pod is deployed.
const OperatorNamespaceEnvVar = "OPERATOR_NAMESPACE"
// GetOperatorNamespace returns the namespace where the operator is deployed.
func GetOperatorNamespace() (string, error) {
ns, found := os.LookupEnv(OperatorNamespaceEnvVar)
if !found {
return "", fmt.Errorf("%s must be set", OperatorNamespaceEnvVar)
}
return ns, nil
}