Skip to content

Commit

Permalink
Only add opts cache to controller manager when a namespace is specified:
Browse files Browse the repository at this point in the history
We want to be able to watch all namespaces if a
watchnamespace is not specified.

Signed-off-by: Jacob Weinstock <[email protected]>
  • Loading branch information
jacobweinstock committed Jan 10, 2024
1 parent 1fcb29b commit 48c95db
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -281,15 +281,11 @@ func main() { //nolint:funlen
broadcaster := cgrecord.NewBroadcasterWithCorrelatorOptions(cgrecord.CorrelatorOptions{
BurstSize: 100, //nolint:gomnd
})

mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{
opts := ctrl.Options{
Scheme: scheme,
Metrics: metricsserver.Options{
BindAddress: metricsAddr,
},
Cache: cache.Options{
DefaultNamespaces: map[string]cache.Config{watchNamespace: {}},
},
LeaderElection: enableLeaderElection,
LeaderElectionID: "controller-leader-election-capt",
LeaderElectionNamespace: leaderElectionNamespace,
Expand All @@ -298,7 +294,13 @@ func main() { //nolint:funlen
RetryPeriod: &leaderElectionRetryPeriod,
HealthProbeBindAddress: healthAddr,
EventBroadcaster: broadcaster,
})
}
if watchNamespace != "" {

Check failure on line 298 in main.go

View workflow job for this annotation

GitHub Actions / Validate lint

only one cuddle assignment allowed before if statement (wsl)
opts.Cache = cache.Options{
DefaultNamespaces: map[string]cache.Config{watchNamespace: {}},
}
}
mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), opts)

Check failure on line 303 in main.go

View workflow job for this annotation

GitHub Actions / Validate lint

assignments should only be cuddled with other assignments (wsl)
if err != nil {

Check failure on line 304 in main.go

View workflow job for this annotation

GitHub Actions / Validate lint

only one cuddle assignment allowed before if statement (wsl)
setupLog.Error(err, "unable to start manager")
os.Exit(1)
Expand Down

0 comments on commit 48c95db

Please sign in to comment.