Skip to content

Commit 800efe6

Browse files
committed
Add watch all namespaces flag
1 parent a58ad6f commit 800efe6

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

config/manager/deployment.yaml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,17 @@ spec:
3030
name: http
3131
- containerPort: 8080
3232
name: http-prom
33-
args:
34-
- --enable-leader-election
35-
- --storage-path=/data
36-
- --log-level=info
37-
- --log-json
3833
env:
3934
- name: RUNTIME_NAMESPACE
4035
valueFrom:
4136
fieldRef:
4237
fieldPath: metadata.namespace
38+
args:
39+
- --watch-all-namespaces
40+
- --log-level=info
41+
- --log-json
42+
- --enable-leader-election
43+
- --storage-path=/data
4344
livenessProbe:
4445
httpGet:
4546
port: http

main.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ func main() {
6868
concurrent int
6969
logLevel string
7070
logJSON bool
71+
watchAllNamespaces bool
7172
)
7273

7374
flag.StringVar(&metricsAddr, "metrics-addr", envOrDefault("METRICS_ADDR", ":8080"), "The address the metric endpoint binds to.")
@@ -80,7 +81,8 @@ func main() {
8081
flag.IntVar(&concurrent, "concurrent", 2, "The number of concurrent reconciles per controller.")
8182
flag.StringVar(&logLevel, "log-level", "info", "Set logging level. Can be debug, info or error.")
8283
flag.BoolVar(&logJSON, "log-json", false, "Set logging to JSON format.")
83-
84+
flag.BoolVar(&watchAllNamespaces, "watch-all-namespaces", true,
85+
"Watch for custom resources in all namespaces, if set to false it will only watch the runtime namespace.")
8486
flag.Parse()
8587

8688
ctrl.SetLogger(logger.NewLogger(logLevel, logJSON))
@@ -95,13 +97,18 @@ func main() {
9597
}
9698
}
9799

100+
watchNamespace := ""
101+
if !watchAllNamespaces {
102+
watchNamespace = os.Getenv("RUNTIME_NAMESPACE")
103+
}
104+
98105
mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{
99106
Scheme: scheme,
100107
MetricsBindAddress: metricsAddr,
101108
Port: 9443,
102109
LeaderElection: enableLeaderElection,
103110
LeaderElectionID: "305740c0.fluxcd.io",
104-
Namespace: os.Getenv("RUNTIME_NAMESPACE"),
111+
Namespace: watchNamespace,
105112
Logger: ctrl.Log,
106113
})
107114
if err != nil {

0 commit comments

Comments
 (0)