Skip to content

Commit abac1df

Browse files
authored
Watch namespaces option was never implemented (#81)
1 parent 33ca2e6 commit abac1df

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

main.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import (
3232
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
3333
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
3434
ctrl "sigs.k8s.io/controller-runtime"
35+
"sigs.k8s.io/controller-runtime/pkg/cache"
3536
"sigs.k8s.io/controller-runtime/pkg/healthz"
3637
"sigs.k8s.io/controller-runtime/pkg/log/zap"
3738

@@ -128,6 +129,32 @@ func main() {
128129
}
129130
}
130131

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+
}
131158
mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{
132159
Scheme: scheme,
133160
Metrics: metricsserver.Options{
@@ -137,6 +164,7 @@ func main() {
137164
HealthProbeBindAddress: probeAddr,
138165
LeaderElection: enableLeaderElection,
139166
LeaderElectionID: "6d6f94cf.digitalis.io",
167+
Cache: cacheOptions,
140168
})
141169
if err != nil {
142170
setupLog.Error(err, "unable to start vals-operator")

0 commit comments

Comments
 (0)