Skip to content

Commit a68777d

Browse files
committed
only apply namespace cache option when --namespace flag is set
1 parent 87ffa02 commit a68777d

File tree

1 file changed

+20
-12
lines changed

1 file changed

+20
-12
lines changed

main.go

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,6 @@ import (
2323
"log"
2424
"os"
2525

26-
"github.com/telekom/cluster-api-ipam-provider-infoblox/api/v1alpha1"
27-
"github.com/telekom/cluster-api-ipam-provider-infoblox/internal/controllers"
28-
"github.com/telekom/cluster-api-ipam-provider-infoblox/internal/index"
29-
"github.com/telekom/cluster-api-ipam-provider-infoblox/internal/webhooks"
30-
"github.com/telekom/cluster-api-ipam-provider-infoblox/pkg/infoblox"
3126
"k8s.io/apimachinery/pkg/runtime"
3227
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
3328
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
@@ -44,6 +39,12 @@ import (
4439
"sigs.k8s.io/controller-runtime/pkg/log/zap"
4540
"sigs.k8s.io/controller-runtime/pkg/metrics/server"
4641
"sigs.k8s.io/controller-runtime/pkg/webhook"
42+
43+
"github.com/telekom/cluster-api-ipam-provider-infoblox/api/v1alpha1"
44+
"github.com/telekom/cluster-api-ipam-provider-infoblox/internal/controllers"
45+
"github.com/telekom/cluster-api-ipam-provider-infoblox/internal/index"
46+
"github.com/telekom/cluster-api-ipam-provider-infoblox/internal/webhooks"
47+
"github.com/telekom/cluster-api-ipam-provider-infoblox/pkg/infoblox"
4748
)
4849

4950
var (
@@ -79,10 +80,10 @@ func main() {
7980
flag.StringVar(&watchNamespace, "namespace", "",
8081
"Namespace that the controller watches to reconcile cluster-api objects. If unspecified, the controller watches for cluster-api objects across all namespaces.")
8182
flag.StringVar(&watchFilter, "watch-filter", "", "")
82-
opts := zap.Options{
83+
zapOpts := zap.Options{
8384
Development: true,
8485
}
85-
opts.BindFlags(flag.CommandLine)
86+
zapOpts.BindFlags(flag.CommandLine)
8687
flag.Parse()
8788

8889
// suppress logs from Infoblox client library
@@ -93,17 +94,24 @@ func main() {
9394

9495
ctx := ctrl.SetupSignalHandler()
9596

96-
namespacesToWatch := map[string]cache.Config{watchNamespace: {}}
97-
98-
mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{
97+
opts := ctrl.Options{
9998
Scheme: scheme,
10099
Metrics: server.Options{BindAddress: metricsAddr},
101100
WebhookServer: webhook.NewServer(webhook.Options{Port: 9443}),
102101
HealthProbeBindAddress: probeAddr,
103102
LeaderElection: enableLeaderElection,
104103
LeaderElectionID: "7bb7acb4.ipam.cluster.x-k8s.io",
105-
Cache: cache.Options{DefaultNamespaces: namespacesToWatch},
106-
})
104+
}
105+
106+
if watchNamespace != "" {
107+
opts.Cache = cache.Options{
108+
DefaultNamespaces: map[string]cache.Config{
109+
watchNamespace: {},
110+
},
111+
}
112+
}
113+
114+
mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), opts)
107115
if err != nil {
108116
setupLog.Error(err, "unable to start manager")
109117
os.Exit(1)

0 commit comments

Comments
 (0)