Skip to content

Commit

Permalink
fix: reformat the cache option creation
Browse files Browse the repository at this point in the history
  • Loading branch information
danielpanzella committed Oct 30, 2024
1 parent a7d4138 commit 5624501
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func main() {
flag.BoolVar(&enableLeaderElection, "leader-elect", false,
"Enable leader election for controller manager. "+
"Enabling this will ensure there is only one active controller manager.")
flag.StringVar(&isolationNamespaces, "isolation-namespaces", "", "Specify namespaces that the controller should monitor when operating in namespace isolation mode.")
flag.StringVar(&isolationNamespaces, "isolation-namespaces", "", "Specify namespaces (as a comma separated string) that the controller should monitor when operating in namespace isolation mode.")

opts := zap.Options{Development: true}
opts.BindFlags(flag.CommandLine)
Expand All @@ -81,13 +81,19 @@ func main() {
logger := zap.New(zap.UseFlagOptions(&opts))
ctrl.SetLogger(logger)

var namespaces []string
cacheOptions := cache.Options{}
if isolationNamespaces != "" {
namespaces = strings.Split(isolationNamespaces, ",")
namespaces := strings.Split(isolationNamespaces, ",")
namespacesCacheConfig := map[string]cache.Config{}
for _, ns := range namespaces {
namespacesCacheConfig[ns] = cache.Config{}
}
cacheOptions.DefaultNamespaces = namespacesCacheConfig
}

managerOptions := ctrl.Options{
Scheme: scheme,
Cache: cacheOptions,
Metrics: server.Options{BindAddress: metricsAddr},
WebhookServer: webhook.NewServer(webhook.Options{
Port: 9443,
Expand All @@ -108,13 +114,6 @@ func main() {
// LeaderElectionReleaseOnCancel: true,
}

if len(namespaces) > 0 {
managerOptions.Cache = cache.Options{DefaultNamespaces: map[string]cache.Config{}}
for _, ns := range namespaces {
managerOptions.Cache.DefaultNamespaces[ns] = cache.Config{}
}
}

mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), managerOptions)
if err != nil {
setupLog.Error(err, "unable to start manager")
Expand Down

0 comments on commit 5624501

Please sign in to comment.