From 800efe666421a150602cdf21fe7c5ffb1eaceb71 Mon Sep 17 00:00:00 2001 From: stefanprodan Date: Fri, 11 Sep 2020 15:57:36 +0300 Subject: [PATCH] Add watch all namespaces flag --- config/manager/deployment.yaml | 11 ++++++----- main.go | 11 +++++++++-- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/config/manager/deployment.yaml b/config/manager/deployment.yaml index 523b3dcf..a635d694 100644 --- a/config/manager/deployment.yaml +++ b/config/manager/deployment.yaml @@ -30,16 +30,17 @@ spec: name: http - containerPort: 8080 name: http-prom - args: - - --enable-leader-election - - --storage-path=/data - - --log-level=info - - --log-json env: - name: RUNTIME_NAMESPACE valueFrom: fieldRef: fieldPath: metadata.namespace + args: + - --watch-all-namespaces + - --log-level=info + - --log-json + - --enable-leader-election + - --storage-path=/data livenessProbe: httpGet: port: http diff --git a/main.go b/main.go index 047dfccb..d32afe83 100644 --- a/main.go +++ b/main.go @@ -68,6 +68,7 @@ func main() { concurrent int logLevel string logJSON bool + watchAllNamespaces bool ) flag.StringVar(&metricsAddr, "metrics-addr", envOrDefault("METRICS_ADDR", ":8080"), "The address the metric endpoint binds to.") @@ -80,7 +81,8 @@ func main() { flag.IntVar(&concurrent, "concurrent", 2, "The number of concurrent reconciles per controller.") flag.StringVar(&logLevel, "log-level", "info", "Set logging level. Can be debug, info or error.") flag.BoolVar(&logJSON, "log-json", false, "Set logging to JSON format.") - + flag.BoolVar(&watchAllNamespaces, "watch-all-namespaces", true, + "Watch for custom resources in all namespaces, if set to false it will only watch the runtime namespace.") flag.Parse() ctrl.SetLogger(logger.NewLogger(logLevel, logJSON)) @@ -95,13 +97,18 @@ func main() { } } + watchNamespace := "" + if !watchAllNamespaces { + watchNamespace = os.Getenv("RUNTIME_NAMESPACE") + } + mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{ Scheme: scheme, MetricsBindAddress: metricsAddr, Port: 9443, LeaderElection: enableLeaderElection, LeaderElectionID: "305740c0.fluxcd.io", - Namespace: os.Getenv("RUNTIME_NAMESPACE"), + Namespace: watchNamespace, Logger: ctrl.Log, }) if err != nil {