Skip to content

Commit

Permalink
Create a manager cache only when a ns is specified: (#156)
Browse files Browse the repository at this point in the history
  • Loading branch information
mergify[bot] authored Oct 2, 2023
2 parents 1065313 + b24fff5 commit 96dbc0e
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,18 +116,23 @@ func main() {

setupLog.Info("Watching objects in namespace for reconciliation", "namespace", kubeNamespace)

mgr, err := ctrl.NewManager(cfg, ctrl.Options{
opts := ctrl.Options{
Scheme: scheme,
Cache: cache.Options{
DefaultNamespaces: map[string]cache.Config{kubeNamespace: {}},
},
Metrics: metricsserver.Options{
BindAddress: metricsAddr,
},
HealthProbeBindAddress: probeAddr,
LeaderElection: enableLeaderElection,
LeaderElectionID: "e74dec1a.tinkerbell.org",
})
}
// If a namespace is specified, only watch that namespace. Otherwise, watch all namespaces.
if kubeNamespace != "" {
opts.Cache = cache.Options{
DefaultNamespaces: map[string]cache.Config{kubeNamespace: {}},
}
}

mgr, err := ctrl.NewManager(cfg, opts)
if err != nil {
setupLog.Error(err, "unable to start manager")
os.Exit(1)
Expand Down

0 comments on commit 96dbc0e

Please sign in to comment.