Skip to content

Commit 0b42db2

Browse files
authored
Merge pull request #238 from yevgeny-shnaidman/yevgeny/watch-namespace
Getting rid of pkg/utils
2 parents 1788698 + b42f91b commit 0b42db2

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

main.go

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ import (
4040
"sigs.k8s.io/node-feature-discovery-operator/internal/deployment"
4141
"sigs.k8s.io/node-feature-discovery-operator/internal/job"
4242
"sigs.k8s.io/node-feature-discovery-operator/internal/status"
43-
"sigs.k8s.io/node-feature-discovery-operator/pkg/utils"
4443
"sigs.k8s.io/node-feature-discovery-operator/pkg/version"
4544
// +kubebuilder:scaffold:imports
4645
)
@@ -52,7 +51,8 @@ var (
5251

5352
const (
5453
// ProgramName is the canonical name of this program
55-
ProgramName = "nfd-operator"
54+
ProgramName = "nfd-operator"
55+
watchNamespaceEnvVar = "WATCH_NAMESPACE"
5656
)
5757

5858
// operatorArgs holds command line arguments
@@ -96,10 +96,10 @@ func main() {
9696
os.Exit(0)
9797
}
9898

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

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

185185
return &args
186186
}
187+
188+
// getWatchNamespace returns the Namespace the operator should be watching for changes
189+
func getWatchNamespace() (string, error) {
190+
value, present := os.LookupEnv(watchNamespaceEnvVar)
191+
if !present {
192+
return "", fmt.Errorf("environment variable %s is not defined", watchNamespaceEnvVar)
193+
}
194+
return value, nil
195+
}

0 commit comments

Comments
 (0)