diff --git a/charts/opensearch-operator/templates/opensearch-operator-controller-manager-deployment.yaml b/charts/opensearch-operator/templates/opensearch-operator-controller-manager-deployment.yaml index 5ef31be8..911c3d30 100755 --- a/charts/opensearch-operator/templates/opensearch-operator-controller-manager-deployment.yaml +++ b/charts/opensearch-operator/templates/opensearch-operator-controller-manager-deployment.yaml @@ -51,8 +51,12 @@ spec: - --metrics-bind-address={{ .Values.manager.metricsBindAddress }} - --leader-elect {{- if .Values.manager.watchNamespace }} + {{- if kindIs "slice" .Values.manager.watchNamespace }} + - --watch-namespace={{ .Values.manager.watchNamespace | join "," }} + {{- else }} - --watch-namespace={{ .Values.manager.watchNamespace }} {{- end }} + {{- end }} - --loglevel={{ .Values.manager.loglevel }} command: - /manager diff --git a/charts/opensearch-operator/values.yaml b/charts/opensearch-operator/values.yaml index 7076e288..239ff952 100644 --- a/charts/opensearch-operator/values.yaml +++ b/charts/opensearch-operator/values.yaml @@ -63,6 +63,10 @@ manager: # If a watchNamespace is specified, the manager's cache will be restricted to # watch objects in the desired namespace. Defaults is to watch all namespaces. + # To watch multiple namespaces, separate them by commas, or define it as a list. + # Examples: + # watchNamespace: ns1,ns2 + # watchNamespace: [ns1, ns2] watchNamespace: metricsBindAddress: 127.0.0.1:8080 diff --git a/docs/userguide/main.md b/docs/userguide/main.md index 1a5635fb..b82a1adc 100644 --- a/docs/userguide/main.md +++ b/docs/userguide/main.md @@ -92,6 +92,10 @@ manager: loglevel: info # If specified, the operator will be restricted to watch objects only in the desired namespace. Defaults is to watch all namespaces. + # To watch multiple namespaces, either separate their name via commas or define it as a list. + # Examples: + # watchNamespaces: 'ns1,ns2' + # watchNamespace: [ns1, ns2] watchNamespace: # Configure extra environment variables for the operator. You can also pull them from secrets or configmaps diff --git a/opensearch-operator/main.go b/opensearch-operator/main.go index 68bffcf2..7a5a9834 100644 --- a/opensearch-operator/main.go +++ b/opensearch-operator/main.go @@ -22,7 +22,10 @@ import ( "os" "strconv" + "strings" + "github.com/Opster/opensearch-k8s-operator/opensearch-operator/pkg/helpers" + "sigs.k8s.io/controller-runtime/pkg/cache" metricsserver "sigs.k8s.io/controller-runtime/pkg/metrics/server" "sigs.k8s.io/controller-runtime/pkg/webhook" @@ -71,7 +74,7 @@ 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") opts := zap.Options{ @@ -94,6 +97,9 @@ func main() { cacheOpts.DefaultNamespaces = map[string]cache.Config{ watchNamespace: {}, } + for watchNs := range strings.SplitSeq(watchNamespace, ",") { + cacheOpts.DefaultNamespaces[watchNs] = cache.Config{} + } } level, err := zapcore.ParseLevel(logLevel)