Merge pull request #143 from fluxcd/watch-all-namespaces
Add watch all namespaces flag
This commit is contained in:
commit
de561e4dec
|
@ -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
11
main.go
|
@ -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 {
|
||||||
|
|
Loading…
Reference in New Issue