-
Couldn't load subscription status.
- Fork 293
Allow the opensearch operator to watch multiple namespaces #1101
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -20,10 +20,12 @@ import ( | |||||||||||||||||||||||||||
| "flag" | ||||||||||||||||||||||||||||
| "fmt" | ||||||||||||||||||||||||||||
| "os" | ||||||||||||||||||||||||||||
| "strconv" | ||||||||||||||||||||||||||||
| "strings" | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| "sigs.k8s.io/controller-runtime/pkg/cache" | ||||||||||||||||||||||||||||
| metricsserver "sigs.k8s.io/controller-runtime/pkg/metrics/server" | ||||||||||||||||||||||||||||
| "sigs.k8s.io/controller-runtime/pkg/webhook" | ||||||||||||||||||||||||||||
| "strconv" | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| "github.com/Opster/opensearch-k8s-operator/opensearch-operator/controllers" | ||||||||||||||||||||||||||||
| "go.uber.org/zap/zapcore" | ||||||||||||||||||||||||||||
|
|
@@ -32,13 +34,14 @@ import ( | |||||||||||||||||||||||||||
| // to ensure that exec-entrypoint and run can make use of them. | ||||||||||||||||||||||||||||
| _ "k8s.io/client-go/plugin/pkg/client/auth" | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| "net/http" | ||||||||||||||||||||||||||||
| _ "net/http/pprof" | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| opsterv1 "github.com/Opster/opensearch-k8s-operator/opensearch-operator/api/v1" | ||||||||||||||||||||||||||||
| monitoring "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1" | ||||||||||||||||||||||||||||
| "k8s.io/apimachinery/pkg/runtime" | ||||||||||||||||||||||||||||
| utilruntime "k8s.io/apimachinery/pkg/util/runtime" | ||||||||||||||||||||||||||||
| clientgoscheme "k8s.io/client-go/kubernetes/scheme" | ||||||||||||||||||||||||||||
| "net/http" | ||||||||||||||||||||||||||||
| _ "net/http/pprof" | ||||||||||||||||||||||||||||
| ctrl "sigs.k8s.io/controller-runtime" | ||||||||||||||||||||||||||||
| "sigs.k8s.io/controller-runtime/pkg/healthz" | ||||||||||||||||||||||||||||
| "sigs.k8s.io/controller-runtime/pkg/log/zap" | ||||||||||||||||||||||||||||
|
|
@@ -68,22 +71,24 @@ func main() { | |||||||||||||||||||||||||||
| "Enable leader election for controller manager. "+ | ||||||||||||||||||||||||||||
| "Enabling this will ensure there is only one active controller manager.") | ||||||||||||||||||||||||||||
| flag.StringVar(&watchNamespace, "watch-namespace", "", | ||||||||||||||||||||||||||||
| "The namespace that controller manager is restricted to watch. If not set, default is to watch all namespaces.") | ||||||||||||||||||||||||||||
| "The comma-separated list of namespaces that the controller manager is restricted to watch. If not set, default is to watch all namespaces.") | ||||||||||||||||||||||||||||
| flag.StringVar(&logLevel, "loglevel", "info", "The log level to use for the operator logs. Possible values: debug,info,warn,error") | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| var cacheOpts cache.Options | ||||||||||||||||||||||||||||
| if watchNamespace != "" { | ||||||||||||||||||||||||||||
| cacheOpts.DefaultNamespaces = map[string]cache.Config{ | ||||||||||||||||||||||||||||
| watchNamespace: {}, | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| opts := zap.Options{ | ||||||||||||||||||||||||||||
| Development: false, | ||||||||||||||||||||||||||||
| TimeEncoder: zapcore.ISO8601TimeEncoder, | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
| opts.BindFlags(flag.CommandLine) | ||||||||||||||||||||||||||||
| flag.Parse() | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| watchNamespaceList := strings.Split(watchNamespace, ",") | ||||||||||||||||||||||||||||
| cacheOpts.DefaultNamespaces = make(map[string]cache.Config) | ||||||||||||||||||||||||||||
| for _, watchNs := range watchNamespaceList { | ||||||||||||||||||||||||||||
| cacheOpts.DefaultNamespaces[watchNs] = cache.Config{} | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
|
Comment on lines
+86
to
+91
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When watchNamespace is not set, it will be an empty string "". You end up with "error":"unable to list: default because of unknown namespace for the cache"You need to check if watchNamespace is empty before processing it:
Suggested change
|
||||||||||||||||||||||||||||
| level, err := zapcore.ParseLevel(logLevel) | ||||||||||||||||||||||||||||
| if err != nil { | ||||||||||||||||||||||||||||
| fmt.Printf("Invalid log level '%s'. Leaving on info", logLevel) | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's not increment versions in a PR please