Skip to content

Commit 386a852

Browse files
authored
Merge pull request #4719 from shysank/control_plane_decouple_wait
🌱 E2E: Decouple control plane status check logic
2 parents 369c3ca + 7f15ab9 commit 386a852

File tree

1 file changed

+36
-9
lines changed

1 file changed

+36
-9
lines changed

test/framework/clusterctl/clusterctl_helpers.go

Lines changed: 36 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,16 @@ type ApplyClusterTemplateAndWaitInput struct {
185185
WaitForMachineDeployments []interface{}
186186
WaitForMachinePools []interface{}
187187
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
188198
}
189199

190200
type ApplyClusterTemplateAndWaitResult struct {
@@ -197,6 +207,7 @@ type ApplyClusterTemplateAndWaitResult struct {
197207
// ApplyClusterTemplateAndWait gets a cluster template using clusterctl, and waits for the cluster to be ready.
198208
// Important! this method assumes the cluster uses a KubeadmControlPlane and MachineDeployments.
199209
func ApplyClusterTemplateAndWait(ctx context.Context, input ApplyClusterTemplateAndWaitInput, result *ApplyClusterTemplateAndWaitResult) {
210+
setDefaults(&input)
200211
Expect(ctx).NotTo(BeNil(), "ctx is required for ApplyClusterTemplateAndWait")
201212
Expect(input.ClusterProxy).ToNot(BeNil(), "Invalid argument. input.ClusterProxy can't be nil when calling ApplyClusterTemplateAndWait")
202213
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
237248
}, input.WaitForClusterIntervals...)
238249

239250
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)
244252

245253
if input.CNIManifestPath != "" {
246254
log.Logf("Installing a CNI plugin to the workload cluster")
@@ -253,11 +261,7 @@ func ApplyClusterTemplateAndWait(ctx context.Context, input ApplyClusterTemplate
253261
}
254262

255263
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)
261265

262266
log.Logf("Waiting for the machine deployments to be provisioned")
263267
result.MachineDeployments = framework.DiscoveryAndWaitForMachineDeployments(ctx, framework.DiscoveryAndWaitForMachineDeploymentsInput{
@@ -272,3 +276,26 @@ func ApplyClusterTemplateAndWait(ctx context.Context, input ApplyClusterTemplate
272276
Cluster: result.Cluster,
273277
}, input.WaitForMachineDeployments...)
274278
}
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

Comments
 (0)