@@ -41,3 +41,55 @@ if err := reconciler.SetupWithManager(mgr); err != nil {
4141 panic (fmt.Sprintf (" unable to create reconciler: %s " , err))
4242}
4343```
44+
45+ ### Creating a Helm reconciler with multiple namespace installation
46+
47+ Add the WATCH_NAMESPACE to the manager files to restrict the namespace to observe where the operator is installed
48+
49+ ``` json
50+ name: manager
51+ env:
52+ - name: WATCH_NAMESPACE
53+ valueFrom:
54+ fieldRef:
55+ fieldPath: metadata.namespace
56+ ```
57+
58+ Filter the events to the namespace where the operator is installed
59+
60+ ``` go
61+ // Operator's main.go
62+ watchNamespace = os.Getenv (" WATCH_NAMESPACE" )
63+
64+ var cacheOpts cache.Options
65+ if watchNamespace != " " {
66+ setupLog.Info (" Watching specific namespace" , " namespace" , watchNamespace)
67+ cacheOpts = cache.Options {
68+ DefaultNamespaces: map [string ]cache.Config {
69+ watchNamespace: {},
70+ },
71+ }
72+ } else {
73+ setupLog.Info (" Watching all namespaces" )
74+ }
75+
76+ mgr , err := ctrl.NewManager (ctrl.GetConfigOrDie (), ctrl.Options {
77+ ...
78+ Cache : cacheOpts,
79+ })
80+
81+ ...
82+ chart , err := loader.Load (" path/to/chart" )
83+ if err != nil {
84+ panic (err)
85+ }
86+
87+ reconciler := reconciler.New (
88+ reconciler.WithChart (*chart),
89+ reconciler.WithGroupVersionKind (gvk),
90+ )
91+
92+ if err := reconciler.SetupWithManager (mgr); err != nil {
93+ panic (fmt.Sprintf (" unable to create reconciler: %s " , err))
94+ }
95+ ```
0 commit comments