Skip to content

Commit

Permalink
Merge pull request #238 from yevgeny-shnaidman/yevgeny/watch-namespace
Browse files Browse the repository at this point in the history
Getting rid of pkg/utils
  • Loading branch information
k8s-ci-robot authored Jun 10, 2024
2 parents 1788698 + b42f91b commit 0b42db2
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ import (
"sigs.k8s.io/node-feature-discovery-operator/internal/deployment"
"sigs.k8s.io/node-feature-discovery-operator/internal/job"
"sigs.k8s.io/node-feature-discovery-operator/internal/status"
"sigs.k8s.io/node-feature-discovery-operator/pkg/utils"
"sigs.k8s.io/node-feature-discovery-operator/pkg/version"
// +kubebuilder:scaffold:imports
)
Expand All @@ -52,7 +51,8 @@ var (

const (
// ProgramName is the canonical name of this program
ProgramName = "nfd-operator"
ProgramName = "nfd-operator"
watchNamespaceEnvVar = "WATCH_NAMESPACE"
)

// operatorArgs holds command line arguments
Expand Down Expand Up @@ -96,10 +96,10 @@ func main() {
os.Exit(0)
}

watchNamespace, envSet := utils.GetWatchNamespace()
if !envSet {
setupLogger.Info("unable to get WatchNamespace, " +
"the manager will watch and manage resources in all namespaces")
watchNamespace, err := getWatchNamespace()
if err != nil {
setupLogger.Error(err, "WatchNamespaceEnvVar is not set")
os.Exit(1)
}

// Create a new manager to manage the operator
Expand Down Expand Up @@ -184,3 +184,12 @@ func initFlags(flagset *flag.FlagSet) *operatorArgs {

return &args
}

// getWatchNamespace returns the Namespace the operator should be watching for changes
func getWatchNamespace() (string, error) {
value, present := os.LookupEnv(watchNamespaceEnvVar)
if !present {
return "", fmt.Errorf("environment variable %s is not defined", watchNamespaceEnvVar)
}
return value, nil
}

0 comments on commit 0b42db2

Please sign in to comment.