@@ -32,6 +32,7 @@ import (
32
32
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
33
33
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
34
34
ctrl "sigs.k8s.io/controller-runtime"
35
+ "sigs.k8s.io/controller-runtime/pkg/cache"
35
36
"sigs.k8s.io/controller-runtime/pkg/healthz"
36
37
"sigs.k8s.io/controller-runtime/pkg/log/zap"
37
38
@@ -128,6 +129,32 @@ func main() {
128
129
}
129
130
}
130
131
132
+ var cacheOptions cache.Options
133
+ if watchNamespaces != "" {
134
+ setupLog .Info ("watching namespaces" , "namespaces" , watchNamespaces )
135
+
136
+ // Split the watchNamespaces string into a slice of namespaces
137
+ namespaces := strings .Split (watchNamespaces , "," )
138
+
139
+ // Create a map to hold namespace configurations
140
+ namespaceConfigs := make (map [string ]cache.Config )
141
+
142
+ // Add each namespace to the map
143
+ for _ , ns := range namespaces {
144
+ // Trim any whitespace from the namespace
145
+ ns = strings .TrimSpace (ns )
146
+ if ns != "" {
147
+ namespaceConfigs [ns ] = cache.Config {}
148
+ }
149
+ }
150
+
151
+ // Set the cache options with the namespace configurations
152
+ cacheOptions = cache.Options {
153
+ DefaultNamespaces : namespaceConfigs ,
154
+ }
155
+
156
+ setupLog .Info ("configured cache for namespaces" , "count" , len (namespaceConfigs ))
157
+ }
131
158
mgr , err := ctrl .NewManager (ctrl .GetConfigOrDie (), ctrl.Options {
132
159
Scheme : scheme ,
133
160
Metrics : metricsserver.Options {
@@ -137,6 +164,7 @@ func main() {
137
164
HealthProbeBindAddress : probeAddr ,
138
165
LeaderElection : enableLeaderElection ,
139
166
LeaderElectionID : "6d6f94cf.digitalis.io" ,
167
+ Cache : cacheOptions ,
140
168
})
141
169
if err != nil {
142
170
setupLog .Error (err , "unable to start vals-operator" )
0 commit comments