@@ -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"
@@ -183,22 +187,39 @@ func main() {
183
187
}
184
188
}
185
189
190
+ var watchNamespaces map [string ]cache.Config
191
+ if watchNamespace != "" {
192
+ watchNamespaces = map [string ]cache.Config {
193
+ watchNamespace : {},
194
+ }
195
+ }
196
+
186
197
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
+ },
199
216
},
200
- Port : webhookPort ,
201
- CertDir : webhookCertDir ,
217
+ WebhookServer : webhook .NewServer (
218
+ webhookserver.Options {
219
+ Port : webhookPort ,
220
+ CertDir : webhookCertDir ,
221
+ },
222
+ ),
202
223
HealthProbeBindAddress : healthAddr ,
203
224
})
204
225
if err != nil {
0 commit comments