@@ -42,6 +42,7 @@ import (
42
42
"k8s.io/utils/ptr"
43
43
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
44
44
"sigs.k8s.io/cluster-api/controllers/clustercache"
45
+ "sigs.k8s.io/cluster-api/controllers/crdmigrator"
45
46
"sigs.k8s.io/cluster-api/controllers/remote"
46
47
"sigs.k8s.io/cluster-api/util/apiwarnings"
47
48
capiflags "sigs.k8s.io/cluster-api/util/flags"
93
94
vSphereVMConcurrency int
94
95
vSphereClusterIdentityConcurrency int
95
96
vSphereDeploymentZoneConcurrency int
97
+ skipCRDMigrationPhases []string
96
98
97
99
managerOptions = capiflags.ManagerOptions {}
98
100
@@ -187,6 +189,9 @@ func InitFlags(fs *pflag.FlagSet) {
187
189
fs .BoolVar (& enableContentionProfiling , "contention-profiling" , false ,
188
190
"Enable block profiling." )
189
191
192
+ fs .StringArrayVar (& skipCRDMigrationPhases , "skip-crd-migration-phases" , []string {},
193
+ "List of CRD migration phases to skip. Valid values are: StorageVersionMigration, CleanupManagedFields." )
194
+
190
195
fs .DurationVar (& syncPeriod , "sync-period" , defaultSyncPeriod ,
191
196
"The minimum interval at which watched resources are reconciled (e.g. 15m)" )
192
197
@@ -225,6 +230,14 @@ func InitFlags(fs *pflag.FlagSet) {
225
230
// Add RBAC for the authorized diagnostics endpoint.
226
231
// +kubebuilder:rbac:groups=authentication.k8s.io,resources=tokenreviews,verbs=create
227
232
// +kubebuilder:rbac:groups=authorization.k8s.io,resources=subjectaccessreviews,verbs=create
233
+ // ADD CRD RBAC for CRD Migrator.
234
+ // +kubebuilder:rbac:groups=apiextensions.k8s.io,resources=customresourcedefinitions,verbs=get;list;watch
235
+ // govmomi
236
+ // +kubebuilder:rbac:groups=apiextensions.k8s.io,resources=customresourcedefinitions;customresourcedefinitions/status,verbs=update;patch,resourceNames=vsphereclusters.infrastructure.cluster.x-k8s.io;vsphereclustertemplates.infrastructure.cluster.x-k8s.io;vspheremachines.infrastructure.cluster.x-k8s.io;vspheremachinetemplates.infrastructure.cluster.x-k8s.io;vspherevms.infrastructure.cluster.x-k8s.io;vsphereclusteridentities.infrastructure.cluster.x-k8s.io;vspheredeploymentzones.infrastructure.cluster.x-k8s.io;vspherefailuredomains.infrastructure.cluster.x-k8s.io
237
+ // supervisor
238
+ // +kubebuilder:rbac:groups=apiextensions.k8s.io,resources=customresourcedefinitions;customresourcedefinitions/status,verbs=update;patch,resourceNames=vsphereclusters.vmware.infrastructure.cluster.x-k8s.io;vsphereclustertemplates.vmware.infrastructure.cluster.x-k8s.io;vspheremachines.vmware.infrastructure.cluster.x-k8s.io;vspheremachinetemplates.vmware.infrastructure.cluster.x-k8s.io;providerserviceaccounts.vmware.infrastructure.cluster.x-k8s.io
239
+ // govmomi CRs
240
+ // +kubebuilder:rbac:groups=infrastructure.cluster.x-k8s.io,resources=vspheremachinetemplates;vsphereclustertemplates,verbs=get;list;watch;patch;update
228
241
229
242
func main () {
230
243
InitFlags (pflag .CommandLine )
@@ -317,6 +330,43 @@ func main() {
317
330
setupLog .Info (fmt .Sprintf ("CRD for %s not loaded, skipping." , supervisorGVR .String ()))
318
331
}
319
332
333
+ // Note: The kubebuilder RBAC markers above has to be kept in sync
334
+ // with the CRDs that should be migrated by this provider.
335
+ crdMigratorConfig := map [client.Object ]crdmigrator.ByObjectConfig {}
336
+ if isGovmomiCRDLoaded {
337
+ crdMigratorConfig [& infrav1.VSphereCluster {}] = crdmigrator.ByObjectConfig {UseCache : true }
338
+ crdMigratorConfig [& infrav1.VSphereClusterTemplate {}] = crdmigrator.ByObjectConfig {UseCache : false }
339
+ crdMigratorConfig [& infrav1.VSphereMachine {}] = crdmigrator.ByObjectConfig {UseCache : true }
340
+ crdMigratorConfig [& infrav1.VSphereMachineTemplate {}] = crdmigrator.ByObjectConfig {UseCache : true }
341
+ crdMigratorConfig [& infrav1.VSphereVM {}] = crdmigrator.ByObjectConfig {UseCache : true }
342
+ crdMigratorConfig [& infrav1.VSphereClusterIdentity {}] = crdmigrator.ByObjectConfig {UseCache : true }
343
+ crdMigratorConfig [& infrav1.VSphereDeploymentZone {}] = crdmigrator.ByObjectConfig {UseCache : true }
344
+ crdMigratorConfig [& infrav1.VSphereFailureDomain {}] = crdmigrator.ByObjectConfig {UseCache : true }
345
+ }
346
+ if isSupervisorCRDLoaded {
347
+ crdMigratorConfig [& vmwarev1.VSphereCluster {}] = crdmigrator.ByObjectConfig {UseCache : true }
348
+ crdMigratorConfig [& vmwarev1.VSphereClusterTemplate {}] = crdmigrator.ByObjectConfig {UseCache : false }
349
+ crdMigratorConfig [& vmwarev1.VSphereMachine {}] = crdmigrator.ByObjectConfig {UseCache : true }
350
+ crdMigratorConfig [& vmwarev1.VSphereMachineTemplate {}] = crdmigrator.ByObjectConfig {UseCache : true }
351
+ crdMigratorConfig [& vmwarev1.ProviderServiceAccount {}] = crdmigrator.ByObjectConfig {UseCache : true }
352
+ }
353
+
354
+ crdMigratorSkipPhases := []crdmigrator.Phase {}
355
+ for _ , p := range skipCRDMigrationPhases {
356
+ crdMigratorSkipPhases = append (crdMigratorSkipPhases , crdmigrator .Phase (p ))
357
+ }
358
+ if err := (& crdmigrator.CRDMigrator {
359
+ Client : mgr .GetClient (),
360
+ APIReader : mgr .GetAPIReader (),
361
+ SkipCRDMigrationPhases : crdMigratorSkipPhases ,
362
+ Config : crdMigratorConfig ,
363
+ // The CRDMigrator is run with only concurrency 1 to ensure we don't overwhelm the apiserver by patching a
364
+ // lot of CRs concurrently.
365
+ }).SetupWithManager (ctx , mgr , concurrency (1 )); err != nil {
366
+ setupLog .Error (err , "Unable to create controller" , "controller" , "CRDMigrator" )
367
+ os .Exit (1 )
368
+ }
369
+
320
370
return nil
321
371
}
322
372
0 commit comments