Skip to content

Commit c39cad9

Browse files
committed
Add watch all namespaces flag
1 parent 062cd71 commit c39cad9

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

config/manager/deployment.yaml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,20 @@ spec:
3232
name: http-webhook
3333
- containerPort: 8080
3434
name: http-prom
35+
env:
36+
- name: RUNTIME_NAMESPACE
37+
valueFrom:
38+
fieldRef:
39+
fieldPath: metadata.namespace
3540
livenessProbe:
3641
httpGet:
3742
port: http-prom
3843
path: /metrics
3944
args:
40-
- --enable-leader-election
45+
- --watch-all-namespaces
4146
- --log-level=info
4247
- --log-json
48+
- --enable-leader-election
4349
resources:
4450
limits:
4551
cpu: 1000m

main.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,29 +55,37 @@ func main() {
5555
concurrent int
5656
logLevel string
5757
logJSON bool
58+
watchAllNamespaces bool
5859
)
60+
5961
flag.StringVar(&metricsAddr, "metrics-addr", ":8080", "The address the metric endpoint binds to.")
6062
flag.StringVar(&eventsAddr, "events-addr", ":9090", "The address the event endpoint binds to.")
6163
flag.StringVar(&receiverAddr, "receiverAddr", ":9292", "The address the webhook receiver endpoint binds to.")
62-
6364
flag.BoolVar(&enableLeaderElection, "enable-leader-election", false,
6465
"Enable leader election for controller manager. "+
6566
"Enabling this will ensure there is only one active controller manager.")
6667
flag.IntVar(&concurrent, "concurrent", 4, "The number of concurrent notification reconciles.")
6768
flag.StringVar(&logLevel, "log-level", "info", "Set logging level. Can be debug, info or error.")
6869
flag.BoolVar(&logJSON, "log-json", false, "Set logging to JSON format.")
70+
flag.BoolVar(&watchAllNamespaces, "watch-all-namespaces", true,
71+
"Watch for custom resources in all namespaces, if set to false it will only watch the runtime namespace.")
6972
flag.Parse()
7073

7174
zapLogger := logger.NewLogger(logLevel, logJSON)
7275
ctrl.SetLogger(zapLogger)
7376

77+
watchNamespace := ""
78+
if !watchAllNamespaces {
79+
watchNamespace = os.Getenv("RUNTIME_NAMESPACE")
80+
}
81+
7482
mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{
7583
Scheme: scheme,
7684
MetricsBindAddress: metricsAddr,
7785
Port: 9443,
7886
LeaderElection: enableLeaderElection,
7987
LeaderElectionID: "4ae6d3b3.fluxcd.io",
80-
Namespace: os.Getenv("RUNTIME_NAMESPACE"),
88+
Namespace: watchNamespace,
8189
Logger: ctrl.Log,
8290
})
8391
if err != nil {

0 commit comments

Comments
 (0)