@@ -35,9 +35,13 @@ import (
3535	"k8s.io/klog/v2" 
3636	clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" 
3737	ctrl "sigs.k8s.io/controller-runtime" 
38- 	"sigs.k8s.io/controller-runtime/pkg/client" 
38+ 	cache "sigs.k8s.io/controller-runtime/pkg/cache" 
39+ 	client "sigs.k8s.io/controller-runtime/pkg/client" 
3940	"sigs.k8s.io/controller-runtime/pkg/client/config" 
4041	"sigs.k8s.io/controller-runtime/pkg/controller" 
42+ 	metricsserver "sigs.k8s.io/controller-runtime/pkg/metrics/server" 
43+ 	"sigs.k8s.io/controller-runtime/pkg/webhook" 
44+ 	webhookserver "sigs.k8s.io/controller-runtime/pkg/webhook" 
4145
4246	infrav1alpha5 "sigs.k8s.io/cluster-api-provider-openstack/api/v1alpha5" 
4347	infrav1alpha6 "sigs.k8s.io/cluster-api-provider-openstack/api/v1alpha6" 
@@ -183,22 +187,39 @@ func main() {
183187		}
184188	}
185189
190+ 	var  watchNamespaces  map [string ]cache.Config 
191+ 	if  watchNamespace  !=  ""  {
192+ 		watchNamespaces  =  map [string ]cache.Config {
193+ 			watchNamespace : {},
194+ 		}
195+ 	}
196+ 
186197	mgr , err  :=  ctrl .NewManager (cfg , ctrl.Options {
187- 		Scheme :             scheme ,
188- 		MetricsBindAddress : metricsBindAddr ,
189- 		LeaderElection :     enableLeaderElection ,
190- 		LeaderElectionID :   "controller-leader-election-capo" ,
191- 		LeaseDuration :      & leaderElectionLeaseDuration ,
192- 		RenewDeadline :      & leaderElectionRenewDeadline ,
193- 		RetryPeriod :        & leaderElectionRetryPeriod ,
194- 		Namespace :          watchNamespace ,
195- 		SyncPeriod :         & syncPeriod ,
196- 		ClientDisableCacheFor : []client.Object {
197- 			& corev1.ConfigMap {},
198- 			& corev1.Secret {},
198+ 		Scheme :           scheme ,
199+ 		Metrics :          metricsserver.Options {BindAddress : metricsBindAddr },
200+ 		LeaderElection :   enableLeaderElection ,
201+ 		LeaderElectionID : "controller-leader-election-capo" ,
202+ 		LeaseDuration :    & leaderElectionLeaseDuration ,
203+ 		RenewDeadline :    & leaderElectionRenewDeadline ,
204+ 		RetryPeriod :      & leaderElectionRetryPeriod ,
205+ 		Cache : cache.Options {
206+ 			DefaultNamespaces : watchNamespaces ,
207+ 			SyncPeriod :        & syncPeriod ,
208+ 		},
209+ 		Client : client.Options {
210+ 			Cache : & client.CacheOptions {
211+ 				DisableFor : []client.Object {
212+ 					& corev1.ConfigMap {},
213+ 					& corev1.Secret {},
214+ 				},
215+ 			},
199216		},
200- 		Port :                   webhookPort ,
201- 		CertDir :                webhookCertDir ,
217+ 		WebhookServer : webhook .NewServer (
218+ 			webhookserver.Options {
219+ 				Port :    webhookPort ,
220+ 				CertDir : webhookCertDir ,
221+ 			},
222+ 		),
202223		HealthProbeBindAddress : healthAddr ,
203224	})
204225	if  err  !=  nil  {
0 commit comments