@@ -185,6 +185,16 @@ type ApplyClusterTemplateAndWaitInput struct {
185
185
WaitForMachineDeployments []interface {}
186
186
WaitForMachinePools []interface {}
187
187
Args []string // extra args to be used during `kubectl apply`
188
+ ControlPlaneWaiters
189
+ }
190
+
191
+ // Waiter is a function that runs and waits for a long running operation to finish and updates the result.
192
+ type Waiter func (ctx context.Context , input ApplyClusterTemplateAndWaitInput , result * ApplyClusterTemplateAndWaitResult )
193
+
194
+ // ControlPlaneWaiters are Waiter functions for the control plane.
195
+ type ControlPlaneWaiters struct {
196
+ WaitForControlPlaneInitialized Waiter
197
+ WaitForControlPlaneMachinesReady Waiter
188
198
}
189
199
190
200
type ApplyClusterTemplateAndWaitResult struct {
@@ -197,6 +207,7 @@ type ApplyClusterTemplateAndWaitResult struct {
197
207
// ApplyClusterTemplateAndWait gets a cluster template using clusterctl, and waits for the cluster to be ready.
198
208
// Important! this method assumes the cluster uses a KubeadmControlPlane and MachineDeployments.
199
209
func ApplyClusterTemplateAndWait (ctx context.Context , input ApplyClusterTemplateAndWaitInput , result * ApplyClusterTemplateAndWaitResult ) {
210
+ setDefaults (& input )
200
211
Expect (ctx ).NotTo (BeNil (), "ctx is required for ApplyClusterTemplateAndWait" )
201
212
Expect (input .ClusterProxy ).ToNot (BeNil (), "Invalid argument. input.ClusterProxy can't be nil when calling ApplyClusterTemplateAndWait" )
202
213
Expect (result ).ToNot (BeNil (), "Invalid argument. result can't be nil when calling ApplyClusterTemplateAndWait" )
@@ -237,10 +248,7 @@ func ApplyClusterTemplateAndWait(ctx context.Context, input ApplyClusterTemplate
237
248
}, input .WaitForClusterIntervals ... )
238
249
239
250
log .Logf ("Waiting for control plane to be initialized" )
240
- result .ControlPlane = framework .DiscoveryAndWaitForControlPlaneInitialized (ctx , framework.DiscoveryAndWaitForControlPlaneInitializedInput {
241
- Lister : input .ClusterProxy .GetClient (),
242
- Cluster : result .Cluster ,
243
- }, input .WaitForControlPlaneIntervals ... )
251
+ input .WaitForControlPlaneInitialized (ctx , input , result )
244
252
245
253
if input .CNIManifestPath != "" {
246
254
log .Logf ("Installing a CNI plugin to the workload cluster" )
@@ -253,11 +261,7 @@ func ApplyClusterTemplateAndWait(ctx context.Context, input ApplyClusterTemplate
253
261
}
254
262
255
263
log .Logf ("Waiting for control plane to be ready" )
256
- framework .WaitForControlPlaneAndMachinesReady (ctx , framework.WaitForControlPlaneAndMachinesReadyInput {
257
- GetLister : input .ClusterProxy .GetClient (),
258
- Cluster : result .Cluster ,
259
- ControlPlane : result .ControlPlane ,
260
- }, input .WaitForControlPlaneIntervals ... )
264
+ input .WaitForControlPlaneMachinesReady (ctx , input , result )
261
265
262
266
log .Logf ("Waiting for the machine deployments to be provisioned" )
263
267
result .MachineDeployments = framework .DiscoveryAndWaitForMachineDeployments (ctx , framework.DiscoveryAndWaitForMachineDeploymentsInput {
@@ -272,3 +276,26 @@ func ApplyClusterTemplateAndWait(ctx context.Context, input ApplyClusterTemplate
272
276
Cluster : result .Cluster ,
273
277
}, input .WaitForMachineDeployments ... )
274
278
}
279
+
280
+ // setDefaults sets the default values for ApplyClusterTemplateAndWaitInput if not set.
281
+ // Currently, we set the default ControlPlaneWaiters here, which are implemented for KubeadmControlPlane.
282
+ func setDefaults (input * ApplyClusterTemplateAndWaitInput ) {
283
+ if input .WaitForControlPlaneInitialized == nil {
284
+ input .WaitForControlPlaneInitialized = func (ctx context.Context , input ApplyClusterTemplateAndWaitInput , result * ApplyClusterTemplateAndWaitResult ) {
285
+ result .ControlPlane = framework .DiscoveryAndWaitForControlPlaneInitialized (ctx , framework.DiscoveryAndWaitForControlPlaneInitializedInput {
286
+ Lister : input .ClusterProxy .GetClient (),
287
+ Cluster : result .Cluster ,
288
+ }, input .WaitForControlPlaneIntervals ... )
289
+ }
290
+ }
291
+
292
+ if input .WaitForControlPlaneMachinesReady == nil {
293
+ input .WaitForControlPlaneMachinesReady = func (ctx context.Context , input ApplyClusterTemplateAndWaitInput , result * ApplyClusterTemplateAndWaitResult ) {
294
+ framework .WaitForControlPlaneAndMachinesReady (ctx , framework.WaitForControlPlaneAndMachinesReadyInput {
295
+ GetLister : input .ClusterProxy .GetClient (),
296
+ Cluster : result .Cluster ,
297
+ ControlPlane : result .ControlPlane ,
298
+ }, input .WaitForControlPlaneIntervals ... )
299
+ }
300
+ }
301
+ }
0 commit comments