@@ -31,6 +31,7 @@ import (
3131 utilruntime "k8s.io/apimachinery/pkg/util/runtime"
3232 clientgoscheme "k8s.io/client-go/kubernetes/scheme"
3333 ctrl "sigs.k8s.io/controller-runtime"
34+ "sigs.k8s.io/controller-runtime/pkg/cache"
3435 "sigs.k8s.io/controller-runtime/pkg/healthz"
3536 "sigs.k8s.io/controller-runtime/pkg/metrics/filters"
3637 metricsserver "sigs.k8s.io/controller-runtime/pkg/metrics/server"
@@ -102,6 +103,14 @@ func Start(ctx context.Context) error {
102103 metricsServerOptions .FilterProvider = filters .WithAuthenticationAndAuthorization
103104 }
104105
106+ var cacheOptions cache.Options
107+ if viper .GetString ("watch-namespace" ) != "" {
108+ setupLog .Info ("Watching a single namespace" , "namespace" , viper .GetString ("watch-namespace" ))
109+ cacheOptions = cache.Options {
110+ DefaultNamespaces : map [string ]cache.Config {viper .GetString ("watch-namespace" ): {}},
111+ }
112+ }
113+
105114 mgr , err := ctrl .NewManager (ctrl .GetConfigOrDie (), ctrl.Options {
106115 Scheme : scheme ,
107116 Metrics : metricsServerOptions ,
@@ -120,6 +129,7 @@ func Start(ctx context.Context) error {
120129 // if you are doing or is intended to do any operation such as perform cleanups
121130 // after the manager stops then its usage might be unsafe.
122131 LeaderElectionReleaseOnCancel : true ,
132+ Cache : cacheOptions ,
123133 })
124134 if err != nil {
125135 setupLog .Error (err , "unable to start manager" )
0 commit comments