Skip to content

Commit

Permalink
Enhance GetWatchNamespace func
Browse files Browse the repository at this point in the history
Co-authored-by: Markus Lehtonen <markus.lehtonen@intel.com>
  • Loading branch information
ArangoGutierrez and marquiz committed Feb 8, 2022
1 parent 7c09709 commit f833220
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 16 deletions.
6 changes: 3 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@ func main() {
os.Exit(0)
}

watchNamespace, err := utils.GetWatchNamespace()
if err != nil {
klog.Error(err, "unable to get WatchNamespace, "+
watchNamespace, envSet := utils.GetWatchNamespace()
if !envSet {
klog.Warning("unable to get WatchNamespace, " +
"the manager will watch and manage resources in all namespaces")
}

Expand Down
20 changes: 7 additions & 13 deletions pkg/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,15 @@ limitations under the License.
package utils

import (
"fmt"
"os"
)

// GetWatchNamespace returns the Namespace the operator should be watching for changes
func GetWatchNamespace() (string, error) {
// WatchNamespaceEnvVar is the constant for env variable WATCH_NAMESPACE
// which specifies the Namespace to watch.
// An empty value means the operator is running with cluster scope.
var watchNamespaceEnvVar = "WATCH_NAMESPACE"

ns, found := os.LookupEnv(watchNamespaceEnvVar)
if !found {
return "", fmt.Errorf("%s must be set", watchNamespaceEnvVar)
}
// WatchNamespaceEnvVar is the constant for env variable WATCH_NAMESPACE
// which specifies the Namespace to watch.
// An empty value means the operator is running with cluster scope.
const WatchNamespaceEnvVar = "WATCH_NAMESPACE"

return ns, nil
// GetWatchNamespace returns the Namespace the operator should be watching for changes
func GetWatchNamespace() (string, bool) {
return os.LookupEnv(WatchNamespaceEnvVar)
}

0 comments on commit f833220

Please sign in to comment.