@@ -68,13 +68,18 @@ type ClusterctlUpgradeSpecInput struct {
68
68
// InitWithProvidersContract can be used to override the INIT_WITH_PROVIDERS_CONTRACT e2e config variable with a specific
69
69
// provider contract to use to initialise the secondary management cluster, e.g. `v1alpha3`
70
70
InitWithProvidersContract string
71
- SkipCleanup bool
72
- ControlPlaneWaiters clusterctl.ControlPlaneWaiters
73
- PreInit func (managementClusterProxy framework.ClusterProxy )
74
- PreUpgrade func (managementClusterProxy framework.ClusterProxy )
75
- PostUpgrade func (managementClusterProxy framework.ClusterProxy )
76
- MgmtFlavor string
77
- WorkloadFlavor string
71
+ // InitWithKubernetesVersion can be used to override the INIT_WITH_KUBERNETES_VERSION e2e config variable with a specific
72
+ // Kubernetes version to use to create the secondary management cluster, e.g. `v1.25.0`
73
+ InitWithKubernetesVersion string
74
+ // UpgradeClusterctlVariables can be used to set additional variables for clusterctl upgrade.
75
+ UpgradeClusterctlVariables map [string ]string
76
+ SkipCleanup bool
77
+ ControlPlaneWaiters clusterctl.ControlPlaneWaiters
78
+ PreInit func (managementClusterProxy framework.ClusterProxy )
79
+ PreUpgrade func (managementClusterProxy framework.ClusterProxy )
80
+ PostUpgrade func (managementClusterProxy framework.ClusterProxy )
81
+ MgmtFlavor string
82
+ WorkloadFlavor string
78
83
}
79
84
80
85
// ClusterctlUpgradeSpec implements a test that verifies clusterctl upgrade of a management cluster.
@@ -115,12 +120,15 @@ func ClusterctlUpgradeSpec(ctx context.Context, inputGetter func() ClusterctlUpg
115
120
testCancelWatches context.CancelFunc
116
121
117
122
managementClusterName string
118
- clusterctlBinaryURL string
119
123
managementClusterNamespace * corev1.Namespace
120
124
managementClusterCancelWatches context.CancelFunc
121
125
managementClusterResources * clusterctl.ApplyClusterTemplateAndWaitResult
122
126
managementClusterProxy framework.ClusterProxy
123
127
128
+ initClusterctlBinaryURL string
129
+ initContract string
130
+ initKubernetesVersion string
131
+
124
132
workLoadClusterName string
125
133
)
126
134
@@ -130,17 +138,34 @@ func ClusterctlUpgradeSpec(ctx context.Context, inputGetter func() ClusterctlUpg
130
138
Expect (input .E2EConfig ).ToNot (BeNil (), "Invalid argument. input.E2EConfig can't be nil when calling %s spec" , specName )
131
139
Expect (input .ClusterctlConfigPath ).To (BeAnExistingFile (), "Invalid argument. input.ClusterctlConfigPath must be an existing file when calling %s spec" , specName )
132
140
Expect (input .BootstrapClusterProxy ).ToNot (BeNil (), "Invalid argument. input.BootstrapClusterProxy can't be nil when calling %s spec" , specName )
133
- var clusterctlBinaryURLTemplate string
134
- if input .InitWithBinary == "" {
141
+
142
+ clusterctlBinaryURLTemplate := input .InitWithBinary
143
+ if clusterctlBinaryURLTemplate == "" {
135
144
Expect (input .E2EConfig .Variables ).To (HaveKey (initWithBinaryVariableName ), "Invalid argument. %s variable must be defined when calling %s spec" , initWithBinaryVariableName , specName )
136
145
Expect (input .E2EConfig .Variables [initWithBinaryVariableName ]).ToNot (BeEmpty (), "Invalid argument. %s variable can't be empty when calling %s spec" , initWithBinaryVariableName , specName )
137
146
clusterctlBinaryURLTemplate = input .E2EConfig .GetVariable (initWithBinaryVariableName )
138
- } else {
139
- clusterctlBinaryURLTemplate = input .InitWithBinary
140
147
}
141
148
clusterctlBinaryURLReplacer := strings .NewReplacer ("{OS}" , runtime .GOOS , "{ARCH}" , runtime .GOARCH )
142
- clusterctlBinaryURL = clusterctlBinaryURLReplacer .Replace (clusterctlBinaryURLTemplate )
143
- Expect (input .E2EConfig .Variables ).To (HaveKey (initWithKubernetesVersion ))
149
+ initClusterctlBinaryURL = clusterctlBinaryURLReplacer .Replace (clusterctlBinaryURLTemplate )
150
+
151
+ // NOTE: by default we are considering all the providers, no matter of the contract.
152
+ // However, given that we want to test both v1alpha3 --> v1beta1 and v1alpha4 --> v1beta1, the INIT_WITH_PROVIDERS_CONTRACT
153
+ // variable can be used to select versions with a specific contract.
154
+ initContract = "*"
155
+ if input .E2EConfig .HasVariable (initWithProvidersContract ) {
156
+ initContract = input .E2EConfig .GetVariable (initWithProvidersContract )
157
+ }
158
+ if input .InitWithProvidersContract != "" {
159
+ initContract = input .InitWithProvidersContract
160
+ }
161
+
162
+ initKubernetesVersion = input .InitWithKubernetesVersion
163
+ if initKubernetesVersion == "" {
164
+ Expect (input .E2EConfig .Variables ).To (HaveKey (initWithKubernetesVersion ), "Invalid argument. %s variable must be defined when calling %s spec" , initWithKubernetesVersion , specName )
165
+ Expect (input .E2EConfig .Variables [initWithKubernetesVersion ]).ToNot (BeEmpty (), "Invalid argument. %s variable can't be empty when calling %s spec" , initWithKubernetesVersion , specName )
166
+ initKubernetesVersion = input .E2EConfig .GetVariable (initWithKubernetesVersion )
167
+ }
168
+
144
169
Expect (input .E2EConfig .Variables ).To (HaveKey (KubernetesVersion ))
145
170
Expect (os .MkdirAll (input .ArtifactFolder , 0750 )).To (Succeed (), "Invalid argument. input.ArtifactFolder can't be created for %s spec" , specName )
146
171
@@ -164,7 +189,7 @@ func ClusterctlUpgradeSpec(ctx context.Context, inputGetter func() ClusterctlUpg
164
189
Flavor : input .MgmtFlavor ,
165
190
Namespace : managementClusterNamespace .Name ,
166
191
ClusterName : managementClusterName ,
167
- KubernetesVersion : input . E2EConfig . GetVariable ( initWithKubernetesVersion ) ,
192
+ KubernetesVersion : initKubernetesVersion ,
168
193
ControlPlaneMachineCount : pointer .Int64Ptr (1 ),
169
194
WorkerMachineCount : pointer .Int64Ptr (1 ),
170
195
},
@@ -193,27 +218,15 @@ func ClusterctlUpgradeSpec(ctx context.Context, inputGetter func() ClusterctlUpg
193
218
managementClusterProxy = input .BootstrapClusterProxy .GetWorkloadCluster (ctx , cluster .Namespace , cluster .Name )
194
219
195
220
// Download the older clusterctl version to be used for setting up the management cluster to be upgraded
196
-
197
- log .Logf ("Downloading clusterctl binary from %s" , clusterctlBinaryURL )
198
- clusterctlBinaryPath := downloadToTmpFile (ctx , clusterctlBinaryURL )
221
+ log .Logf ("Downloading clusterctl binary from %s" , initClusterctlBinaryURL )
222
+ clusterctlBinaryPath := downloadToTmpFile (ctx , initClusterctlBinaryURL )
199
223
defer os .Remove (clusterctlBinaryPath ) // clean up
200
224
201
225
err := os .Chmod (clusterctlBinaryPath , 0744 ) //nolint:gosec
202
226
Expect (err ).ToNot (HaveOccurred (), "failed to chmod temporary file" )
203
227
204
228
By ("Initializing the workload cluster with older versions of providers" )
205
229
206
- // NOTE: by default we are considering all the providers, no matter of the contract.
207
- // However, given that we want to test both v1alpha3 --> v1beta1 and v1alpha4 --> v1beta1, the INIT_WITH_PROVIDERS_CONTRACT
208
- // variable can be used to select versions with a specific contract.
209
- contract := "*"
210
- if input .E2EConfig .HasVariable (initWithProvidersContract ) {
211
- contract = input .E2EConfig .GetVariable (initWithProvidersContract )
212
- }
213
- if input .InitWithProvidersContract != "" {
214
- contract = input .InitWithProvidersContract
215
- }
216
-
217
230
if input .PreInit != nil {
218
231
By ("Running Pre-init steps against the management cluster" )
219
232
input .PreInit (managementClusterProxy )
@@ -223,10 +236,10 @@ func ClusterctlUpgradeSpec(ctx context.Context, inputGetter func() ClusterctlUpg
223
236
ClusterctlBinaryPath : clusterctlBinaryPath , // use older version of clusterctl to init the management cluster
224
237
ClusterProxy : managementClusterProxy ,
225
238
ClusterctlConfigPath : input .ClusterctlConfigPath ,
226
- CoreProvider : input .E2EConfig .GetProviderLatestVersionsByContract (contract , config .ClusterAPIProviderName )[0 ],
227
- BootstrapProviders : input .E2EConfig .GetProviderLatestVersionsByContract (contract , config .KubeadmBootstrapProviderName ),
228
- ControlPlaneProviders : input .E2EConfig .GetProviderLatestVersionsByContract (contract , config .KubeadmControlPlaneProviderName ),
229
- InfrastructureProviders : input .E2EConfig .GetProviderLatestVersionsByContract (contract , input .E2EConfig .InfrastructureProviders ()... ),
239
+ CoreProvider : input .E2EConfig .GetProviderLatestVersionsByContract (initContract , config .ClusterAPIProviderName )[0 ],
240
+ BootstrapProviders : input .E2EConfig .GetProviderLatestVersionsByContract (initContract , config .KubeadmBootstrapProviderName ),
241
+ ControlPlaneProviders : input .E2EConfig .GetProviderLatestVersionsByContract (initContract , config .KubeadmControlPlaneProviderName ),
242
+ InfrastructureProviders : input .E2EConfig .GetProviderLatestVersionsByContract (initContract , input .E2EConfig .InfrastructureProviders ()... ),
230
243
LogFolder : filepath .Join (input .ArtifactFolder , "clusters" , cluster .Name ),
231
244
}, input .E2EConfig .GetIntervals (specName , "wait-controllers" )... )
232
245
@@ -313,6 +326,7 @@ func ClusterctlUpgradeSpec(ctx context.Context, inputGetter func() ClusterctlUpg
313
326
By ("Upgrading providers to the latest version available" )
314
327
clusterctl .UpgradeManagementClusterAndWait (ctx , clusterctl.UpgradeManagementClusterAndWaitInput {
315
328
ClusterctlConfigPath : input .ClusterctlConfigPath ,
329
+ ClusterctlVariables : input .UpgradeClusterctlVariables ,
316
330
ClusterProxy : managementClusterProxy ,
317
331
Contract : clusterv1 .GroupVersion .Version ,
318
332
LogFolder : filepath .Join (input .ArtifactFolder , "clusters" , cluster .Name ),
@@ -342,19 +356,34 @@ func ClusterctlUpgradeSpec(ctx context.Context, inputGetter func() ClusterctlUpg
342
356
// After upgrading we are sure the version is the latest version of the API,
343
357
// so it is possible to use the standard helpers
344
358
345
- testMachineDeployments := framework .GetMachineDeploymentsByCluster (ctx , framework.GetMachineDeploymentsByClusterInput {
346
- Lister : managementClusterProxy .GetClient (),
347
- ClusterName : workLoadClusterName ,
348
- Namespace : testNamespace .Name ,
349
- })
350
-
351
- framework .ScaleAndWaitMachineDeployment (ctx , framework.ScaleAndWaitMachineDeploymentInput {
352
- ClusterProxy : managementClusterProxy ,
353
- Cluster : & clusterv1.Cluster {ObjectMeta : metav1.ObjectMeta {Namespace : testNamespace .Name }},
354
- MachineDeployment : testMachineDeployments [0 ],
355
- Replicas : 2 ,
356
- WaitForMachineDeployments : input .E2EConfig .GetIntervals (specName , "wait-worker-nodes" ),
359
+ workloadCluster := framework .GetClusterByName (ctx , framework.GetClusterByNameInput {
360
+ Getter : managementClusterProxy .GetClient (),
361
+ Namespace : testNamespace .Name ,
362
+ Name : workLoadClusterName ,
357
363
})
364
+ if workloadCluster .Spec .Topology != nil {
365
+ // Cluster is using ClusterClass, scale up via topology.
366
+ framework .ScaleAndWaitMachineDeploymentTopology (ctx , framework.ScaleAndWaitMachineDeploymentTopologyInput {
367
+ ClusterProxy : managementClusterProxy ,
368
+ Cluster : workloadCluster ,
369
+ Replicas : 2 ,
370
+ WaitForMachineDeployments : input .E2EConfig .GetIntervals (specName , "wait-worker-nodes" ),
371
+ })
372
+ } else {
373
+ // Cluster is not using ClusterClass, scale up via MachineDeployment.
374
+ testMachineDeployments := framework .GetMachineDeploymentsByCluster (ctx , framework.GetMachineDeploymentsByClusterInput {
375
+ Lister : managementClusterProxy .GetClient (),
376
+ ClusterName : workLoadClusterName ,
377
+ Namespace : testNamespace .Name ,
378
+ })
379
+ framework .ScaleAndWaitMachineDeployment (ctx , framework.ScaleAndWaitMachineDeploymentInput {
380
+ ClusterProxy : managementClusterProxy ,
381
+ Cluster : & clusterv1.Cluster {ObjectMeta : metav1.ObjectMeta {Namespace : testNamespace .Name }},
382
+ MachineDeployment : testMachineDeployments [0 ],
383
+ Replicas : 2 ,
384
+ WaitForMachineDeployments : input .E2EConfig .GetIntervals (specName , "wait-worker-nodes" ),
385
+ })
386
+ }
358
387
359
388
By ("THE UPGRADED MANAGEMENT CLUSTER WORKS!" )
360
389
0 commit comments