Skip to content

Commit b24fff5

Browse files
Create a manager cache only when a ns is specified:
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]>
1 parent 1065313 commit b24fff5

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

main.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -116,18 +116,23 @@ func main() {
116116

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

119-
mgr, err := ctrl.NewManager(cfg, ctrl.Options{
119+
opts := ctrl.Options{
120120
Scheme: scheme,
121-
Cache: cache.Options{
122-
DefaultNamespaces: map[string]cache.Config{kubeNamespace: {}},
123-
},
124121
Metrics: metricsserver.Options{
125122
BindAddress: metricsAddr,
126123
},
127124
HealthProbeBindAddress: probeAddr,
128125
LeaderElection: enableLeaderElection,
129126
LeaderElectionID: "e74dec1a.tinkerbell.org",
130-
})
127+
}
128+
// If a namespace is specified, only watch that namespace. Otherwise, watch all namespaces.
129+
if kubeNamespace != "" {
130+
opts.Cache = cache.Options{
131+
DefaultNamespaces: map[string]cache.Config{kubeNamespace: {}},
132+
}
133+
}
134+
135+
mgr, err := ctrl.NewManager(cfg, opts)
131136
if err != nil {
132137
setupLog.Error(err, "unable to start manager")
133138
os.Exit(1)

0 commit comments

Comments
 (0)