Add watch all namespaces flag

This commit is contained in:
stefanprodan 2020-09-11 15:57:36 +03:00
parent a58ad6f755
commit 800efe6664
2 changed files with 15 additions and 7 deletions

View File

@ -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

11
main.go
View File

@ -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 {