Skip to content

Commit a9500a0

Browse files
committed
main: adjustments for new controller-runtime
1 parent 27a254b commit a9500a0

File tree

1 file changed

+35
-15
lines changed

1 file changed

+35
-15
lines changed

main.go

Lines changed: 35 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,12 @@ 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"
4144

4245
infrav1alpha5 "sigs.k8s.io/cluster-api-provider-openstack/api/v1alpha5"
4346
infrav1alpha6 "sigs.k8s.io/cluster-api-provider-openstack/api/v1alpha6"
@@ -183,22 +186,39 @@ func main() {
183186
}
184187
}
185188

189+
var watchNamespaces map[string]cache.Config
190+
if watchNamespace != "" {
191+
watchNamespaces = map[string]cache.Config{
192+
watchNamespace: {},
193+
}
194+
}
195+
186196
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{},
197+
Scheme: scheme,
198+
Metrics: metricsserver.Options{BindAddress: metricsBindAddr},
199+
LeaderElection: enableLeaderElection,
200+
LeaderElectionID: "controller-leader-election-capo",
201+
LeaseDuration: &leaderElectionLeaseDuration,
202+
RenewDeadline: &leaderElectionRenewDeadline,
203+
RetryPeriod: &leaderElectionRetryPeriod,
204+
Cache: cache.Options{
205+
DefaultNamespaces: watchNamespaces,
206+
SyncPeriod: &syncPeriod,
207+
},
208+
Client: client.Options{
209+
Cache: &client.CacheOptions{
210+
DisableFor: []client.Object{
211+
&corev1.ConfigMap{},
212+
&corev1.Secret{},
213+
},
214+
},
199215
},
200-
Port: webhookPort,
201-
CertDir: webhookCertDir,
216+
WebhookServer: webhook.NewServer(
217+
webhook.Options{
218+
Port: webhookPort,
219+
CertDir: webhookCertDir,
220+
},
221+
),
202222
HealthProbeBindAddress: healthAddr,
203223
})
204224
if err != nil {

0 commit comments

Comments
 (0)