@@ -35,9 +35,13 @@ import (
35
35
"k8s.io/klog/v2"
36
36
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
37
37
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"
39
40
"sigs.k8s.io/controller-runtime/pkg/client/config"
40
41
"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"
41
45
42
46
infrav1alpha5 "sigs.k8s.io/cluster-api-provider-openstack/api/v1alpha5"
43
47
infrav1alpha6 "sigs.k8s.io/cluster-api-provider-openstack/api/v1alpha6"
@@ -180,22 +184,39 @@ func main() {
180
184
}
181
185
}
182
186
187
+ var watchNamespaces map [string ]cache.Config
188
+ if watchNamespace != "" {
189
+ watchNamespaces = map [string ]cache.Config {
190
+ watchNamespace : {},
191
+ }
192
+ }
193
+
183
194
mgr , err := ctrl .NewManager (cfg , ctrl.Options {
184
- Scheme : scheme ,
185
- MetricsBindAddress : metricsBindAddr ,
186
- LeaderElection : enableLeaderElection ,
187
- LeaderElectionID : "controller-leader-election-capo" ,
188
- LeaseDuration : & leaderElectionLeaseDuration ,
189
- RenewDeadline : & leaderElectionRenewDeadline ,
190
- RetryPeriod : & leaderElectionRetryPeriod ,
191
- Namespace : watchNamespace ,
192
- SyncPeriod : & syncPeriod ,
193
- ClientDisableCacheFor : []client.Object {
194
- & corev1.ConfigMap {},
195
- & corev1.Secret {},
195
+ Scheme : scheme ,
196
+ Metrics : metricsserver.Options {BindAddress : metricsBindAddr },
197
+ LeaderElection : enableLeaderElection ,
198
+ LeaderElectionID : "controller-leader-election-capo" ,
199
+ LeaseDuration : & leaderElectionLeaseDuration ,
200
+ RenewDeadline : & leaderElectionRenewDeadline ,
201
+ RetryPeriod : & leaderElectionRetryPeriod ,
202
+ Cache : cache.Options {
203
+ DefaultNamespaces : watchNamespaces ,
204
+ SyncPeriod : & syncPeriod ,
205
+ },
206
+ Client : client.Options {
207
+ Cache : & client.CacheOptions {
208
+ DisableFor : []client.Object {
209
+ & corev1.ConfigMap {},
210
+ & corev1.Secret {},
211
+ },
212
+ },
196
213
},
197
- Port : webhookPort ,
198
- CertDir : webhookCertDir ,
214
+ WebhookServer : webhook .NewServer (
215
+ webhookserver.Options {
216
+ Port : webhookPort ,
217
+ CertDir : webhookCertDir ,
218
+ },
219
+ ),
199
220
HealthProbeBindAddress : healthAddr ,
200
221
})
201
222
if err != nil {
0 commit comments