Ensure Default NS Always Set
This commit ensures that the namespace specified for the Operator via env var
PGO_OPERATOR_NAMESPACE is always set as the default watched namespace
for the Operator install when the NAMESPACE env var is empty.
@@ -677,11 +677,13 @@ func ValidateNamespacesWatched(clientset *kubernetes.Clientset,
}
// getNamespacesFromEnv returns a slice containing the namespaces strored the NAMESPACE env var in
-// csv format.
+// csv format. If NAMESPACE is empty, then the Operator namespace as specified in env var
+// PGO_OPERATOR_NAMESPACE is returned.
func getNamespacesFromEnv() []string {
namespaceEnvVar := os.Getenv("NAMESPACE")
if namespaceEnvVar == "" {
- return nil
+ defaultNs := os.Getenv("PGO_OPERATOR_NAMESPACE")
+ return []string{defaultNs}
}
return strings.Split(namespaceEnvVar, ",")
}
@@ -982,10 +984,5 @@ func GetInitialNamespaceList(clientset *kubernetes.Clientset,
}
}
- // default to the namespace for the Operator install if the namespace list is still empty
- if len(namespaceList) == 0 {
- namespaceList = append(namespaceList, pgoNamespace)
- }
-
return namespaceList, nil
}
