Merge pull request #143 from fluxcd/watch-all-namespaces

Add watch all namespaces flag
This commit is contained in:
Stefan Prodan 2020-09-11 16:13:50 +03:00 committed by GitHub
commit de561e4dec
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 7 deletions

View File

@ -30,16 +30,17 @@ spec:
name: http name: http
- containerPort: 8080 - containerPort: 8080
name: http-prom name: http-prom
args:
- --enable-leader-election
- --storage-path=/data
- --log-level=info
- --log-json
env: env:
- name: RUNTIME_NAMESPACE - name: RUNTIME_NAMESPACE
valueFrom: valueFrom:
fieldRef: fieldRef:
fieldPath: metadata.namespace fieldPath: metadata.namespace
args:
- --watch-all-namespaces
- --log-level=info
- --log-json
- --enable-leader-election
- --storage-path=/data
livenessProbe: livenessProbe:
httpGet: httpGet:
port: http port: http

11
main.go
View File

@ -68,6 +68,7 @@ func main() {
concurrent int concurrent int
logLevel string logLevel string
logJSON bool logJSON bool
watchAllNamespaces bool
) )
flag.StringVar(&metricsAddr, "metrics-addr", envOrDefault("METRICS_ADDR", ":8080"), "The address the metric endpoint binds to.") 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.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.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(&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() flag.Parse()
ctrl.SetLogger(logger.NewLogger(logLevel, logJSON)) 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{ mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{
Scheme: scheme, Scheme: scheme,
MetricsBindAddress: metricsAddr, MetricsBindAddress: metricsAddr,
Port: 9443, Port: 9443,
LeaderElection: enableLeaderElection, LeaderElection: enableLeaderElection,
LeaderElectionID: "305740c0.fluxcd.io", LeaderElectionID: "305740c0.fluxcd.io",
Namespace: os.Getenv("RUNTIME_NAMESPACE"), Namespace: watchNamespace,
Logger: ctrl.Log, Logger: ctrl.Log,
}) })
if err != nil { if err != nil {