Skip to content

Commit

Permalink
Create a manager cache only when a ns is specified:
Browse files Browse the repository at this point in the history
A cache with a "" namespace causes reconcile errors:
"unable to get: namespace/machine because of unknown namespace for the cache"
With this change is the ns is "" we use the default behavior
of the manager which is to watch and list all namespaces.

Signed-off-by: Jacob Weinstock <[email protected]>
  • Loading branch information
jacobweinstock committed Sep 30, 2023
1 parent 1065313 commit b24fff5
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 b24fff5

Please sign in to comment.