Skip to content

Commit

Permalink
refactor e2e control plane initialized/ready checks
Browse files Browse the repository at this point in the history
  • Loading branch information
nojnhuh committed Nov 14, 2024
1 parent 9b99382 commit c45f03f
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 46 deletions.
26 changes: 13 additions & 13 deletions test/e2e/azure_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ var _ = Describe("Workload cluster creation", func() {
withControlPlaneMachineCount(1),
withWorkerMachineCount(1),
withControlPlaneWaiters(clusterctl.ControlPlaneWaiters{
WaitForControlPlaneInitialized: EnsureControlPlaneInitializedNoAddons,
WaitForControlPlaneMachinesReady: EnsureControlPlaneReadyNoAddons,
}),
withPostMachinesProvisioned(func() {
EnsureDaemonsets(ctx, func() DaemonsetsSpecInput {
Expand Down Expand Up @@ -210,7 +210,7 @@ var _ = Describe("Workload cluster creation", func() {
withWorkerMachineCount(2),
withControlPlaneInterval(specName, "wait-control-plane-ha"),
withControlPlaneWaiters(clusterctl.ControlPlaneWaiters{
WaitForControlPlaneInitialized: EnsureControlPlaneInitializedNoAddons,
WaitForControlPlaneMachinesReady: EnsureControlPlaneReadyNoAddons,
}),
withPostMachinesProvisioned(func() {
EnsureDaemonsets(ctx, func() DaemonsetsSpecInput {
Expand Down Expand Up @@ -308,7 +308,7 @@ var _ = Describe("Workload cluster creation", func() {
withWorkerMachineCount(2),
withControlPlaneInterval(specName, "wait-control-plane-ha"),
withControlPlaneWaiters(clusterctl.ControlPlaneWaiters{
WaitForControlPlaneInitialized: EnsureControlPlaneInitializedNoAddons,
WaitForControlPlaneMachinesReady: EnsureControlPlaneReadyNoAddons,
}),
withPostMachinesProvisioned(func() {
EnsureDaemonsets(ctx, func() DaemonsetsSpecInput {
Expand Down Expand Up @@ -367,7 +367,7 @@ var _ = Describe("Workload cluster creation", func() {
withControlPlaneMachineCount(1),
withWorkerMachineCount(1),
withControlPlaneWaiters(clusterctl.ControlPlaneWaiters{
WaitForControlPlaneInitialized: EnsureControlPlaneInitializedNoAddons,
WaitForControlPlaneMachinesReady: EnsureControlPlaneReadyNoAddons,
}),
withPostMachinesProvisioned(func() {
EnsureDaemonsets(ctx, func() DaemonsetsSpecInput {
Expand Down Expand Up @@ -405,7 +405,7 @@ var _ = Describe("Workload cluster creation", func() {
withControlPlaneMachineCount(1),
withWorkerMachineCount(1),
withControlPlaneWaiters(clusterctl.ControlPlaneWaiters{
WaitForControlPlaneInitialized: EnsureControlPlaneInitializedNoAddons,
WaitForControlPlaneMachinesReady: EnsureControlPlaneReadyNoAddons,
}),
withPostMachinesProvisioned(func() {
EnsureDaemonsets(ctx, func() DaemonsetsSpecInput {
Expand Down Expand Up @@ -442,7 +442,7 @@ var _ = Describe("Workload cluster creation", func() {
withControlPlaneMachineCount(1),
withWorkerMachineCount(1),
withControlPlaneWaiters(clusterctl.ControlPlaneWaiters{
WaitForControlPlaneInitialized: EnsureControlPlaneInitializedNoAddons,
WaitForControlPlaneMachinesReady: EnsureControlPlaneReadyNoAddons,
}),
withPostMachinesProvisioned(func() {
EnsureDaemonsets(ctx, func() DaemonsetsSpecInput {
Expand Down Expand Up @@ -480,7 +480,7 @@ var _ = Describe("Workload cluster creation", func() {
withWorkerMachineCount(1),
withControlPlaneInterval(specName, "wait-control-plane-ha"),
withControlPlaneWaiters(clusterctl.ControlPlaneWaiters{
WaitForControlPlaneInitialized: EnsureControlPlaneInitializedNoAddons,
WaitForControlPlaneMachinesReady: EnsureControlPlaneReadyNoAddons,
}),
withPostMachinesProvisioned(func() {
EnsureDaemonsets(ctx, func() DaemonsetsSpecInput {
Expand Down Expand Up @@ -540,7 +540,7 @@ var _ = Describe("Workload cluster creation", func() {
withControlPlaneInterval(specName, "wait-control-plane"),
withMachinePoolInterval(specName, "wait-machine-pool-nodes"),
withControlPlaneWaiters(clusterctl.ControlPlaneWaiters{
WaitForControlPlaneInitialized: EnsureControlPlaneInitializedNoAddons,
WaitForControlPlaneMachinesReady: EnsureControlPlaneReadyNoAddons,
}),
withPostMachinesProvisioned(func() {
EnsureDaemonsets(ctx, func() DaemonsetsSpecInput {
Expand Down Expand Up @@ -609,7 +609,7 @@ var _ = Describe("Workload cluster creation", func() {
withWorkerMachineCount(1),
withMachineDeploymentInterval(specName, "wait-gpu-nodes"),
withControlPlaneWaiters(clusterctl.ControlPlaneWaiters{
WaitForControlPlaneInitialized: EnsureControlPlaneInitializedNoAddons,
WaitForControlPlaneMachinesReady: EnsureControlPlaneReadyNoAddons,
}),
withPostMachinesProvisioned(func() {
EnsureDaemonsets(ctx, func() DaemonsetsSpecInput {
Expand Down Expand Up @@ -667,7 +667,7 @@ var _ = Describe("Workload cluster creation", func() {
withWorkerMachineCount(1),
withMachineDeploymentInterval(specName, ""),
withControlPlaneWaiters(clusterctl.ControlPlaneWaiters{
WaitForControlPlaneInitialized: EnsureControlPlaneInitializedNoAddons,
WaitForControlPlaneMachinesReady: EnsureControlPlaneReadyNoAddons,
}),
withMachinePoolInterval(specName, "wait-machine-pool-nodes"),
withControlPlaneInterval(specName, "wait-control-plane"),
Expand Down Expand Up @@ -1007,7 +1007,7 @@ var _ = Describe("Workload cluster creation", func() {
withWorkerMachineCount(1),
withControlPlaneInterval(specName, "wait-control-plane-ha"),
withControlPlaneWaiters(clusterctl.ControlPlaneWaiters{
WaitForControlPlaneInitialized: EnsureControlPlaneInitializedNoAddons,
WaitForControlPlaneMachinesReady: EnsureControlPlaneReadyNoAddons,
}),
withPostMachinesProvisioned(func() {
EnsureDaemonsets(ctx, func() DaemonsetsSpecInput {
Expand Down Expand Up @@ -1081,7 +1081,7 @@ var _ = Describe("Workload cluster creation", func() {
withControlPlaneMachineCount(1),
withWorkerMachineCount(1),
withControlPlaneWaiters(clusterctl.ControlPlaneWaiters{
WaitForControlPlaneInitialized: EnsureControlPlaneInitializedNoAddons,
WaitForControlPlaneMachinesReady: EnsureControlPlaneReadyNoAddons,
}),
withPostMachinesProvisioned(func() {
EnsureDaemonsets(ctx, func() DaemonsetsSpecInput {
Expand Down Expand Up @@ -1126,7 +1126,7 @@ var _ = Describe("Workload cluster creation", func() {
withControlPlaneMachineCount(1),
withWorkerMachineCount(1),
withControlPlaneWaiters(clusterctl.ControlPlaneWaiters{
WaitForControlPlaneInitialized: EnsureControlPlaneInitializedNoAddons,
WaitForControlPlaneMachinesReady: EnsureControlPlaneReadyNoAddons,
}),
withPostMachinesProvisioned(func() {
EnsureDaemonsets(ctx, func() DaemonsetsSpecInput {
Expand Down
24 changes: 12 additions & 12 deletions test/e2e/capi_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ var _ = Describe("Running the Cluster API E2E tests", func() {
ArtifactFolder: artifactFolder,
SkipCleanup: skipCleanup,
ControlPlaneWaiters: clusterctl.ControlPlaneWaiters{
WaitForControlPlaneInitialized: EnsureControlPlaneInitializedNoAddons,
WaitForControlPlaneMachinesReady: EnsureControlPlaneReadyNoAddons,
},
}
})
Expand All @@ -95,7 +95,7 @@ var _ = Describe("Running the Cluster API E2E tests", func() {
ArtifactFolder: artifactFolder,
SkipCleanup: skipCleanup,
ControlPlaneWaiters: clusterctl.ControlPlaneWaiters{
WaitForControlPlaneInitialized: EnsureControlPlaneInitializedNoAddons,
WaitForControlPlaneMachinesReady: EnsureControlPlaneReadyNoAddons,
},
}
})
Expand All @@ -111,7 +111,7 @@ var _ = Describe("Running the Cluster API E2E tests", func() {
ArtifactFolder: artifactFolder,
SkipCleanup: skipCleanup,
ControlPlaneWaiters: clusterctl.ControlPlaneWaiters{
WaitForControlPlaneInitialized: EnsureControlPlaneInitializedNoAddons,
WaitForControlPlaneMachinesReady: EnsureControlPlaneReadyNoAddons,
},
}
})
Expand All @@ -128,7 +128,7 @@ var _ = Describe("Running the Cluster API E2E tests", func() {
ArtifactFolder: artifactFolder,
SkipCleanup: skipCleanup,
ControlPlaneWaiters: clusterctl.ControlPlaneWaiters{
WaitForControlPlaneInitialized: EnsureControlPlaneInitializedNoAddons,
WaitForControlPlaneMachinesReady: EnsureControlPlaneReadyNoAddons,
},
}
})
Expand All @@ -143,7 +143,7 @@ var _ = Describe("Running the Cluster API E2E tests", func() {
ArtifactFolder: artifactFolder,
SkipCleanup: skipCleanup,
ControlPlaneWaiters: clusterctl.ControlPlaneWaiters{
WaitForControlPlaneInitialized: EnsureControlPlaneInitializedNoAddons,
WaitForControlPlaneMachinesReady: EnsureControlPlaneReadyNoAddons,
},
}
})
Expand All @@ -158,7 +158,7 @@ var _ = Describe("Running the Cluster API E2E tests", func() {
ArtifactFolder: artifactFolder,
SkipCleanup: skipCleanup,
ControlPlaneWaiters: clusterctl.ControlPlaneWaiters{
WaitForControlPlaneInitialized: EnsureControlPlaneInitializedNoAddons,
WaitForControlPlaneMachinesReady: EnsureControlPlaneReadyNoAddons,
},
}
})
Expand All @@ -173,7 +173,7 @@ var _ = Describe("Running the Cluster API E2E tests", func() {
ArtifactFolder: artifactFolder,
SkipCleanup: skipCleanup,
ControlPlaneWaiters: clusterctl.ControlPlaneWaiters{
WaitForControlPlaneInitialized: EnsureControlPlaneInitializedNoAddons,
WaitForControlPlaneMachinesReady: EnsureControlPlaneReadyNoAddons,
},
}
})
Expand Down Expand Up @@ -213,7 +213,7 @@ var _ = Describe("Running the Cluster API E2E tests", func() {
PreInit: getPreInitFunc(ctx),
InitWithProvidersContract: "v1beta1",
ControlPlaneWaiters: clusterctl.ControlPlaneWaiters{
WaitForControlPlaneInitialized: EnsureControlPlaneInitialized,
WaitForControlPlaneMachinesReady: EnsureControlPlaneReady,
},
InitWithKubernetesVersion: e2eConfig.GetVariable(KubernetesVersionAPIUpgradeFrom),
InitWithBinary: fmt.Sprintf("https://github.com/kubernetes-sigs/cluster-api/releases/download/%s/clusterctl-{OS}-{ARCH}", e2eConfig.GetVariable(OldCAPIUpgradeVersion)),
Expand All @@ -238,7 +238,7 @@ var _ = Describe("Running the Cluster API E2E tests", func() {
PreInit: getPreInitFunc(ctx),
InitWithProvidersContract: "v1beta1",
ControlPlaneWaiters: clusterctl.ControlPlaneWaiters{
WaitForControlPlaneInitialized: EnsureControlPlaneInitialized,
WaitForControlPlaneMachinesReady: EnsureControlPlaneReady,
},
InitWithKubernetesVersion: e2eConfig.GetVariable(KubernetesVersionAPIUpgradeFrom),
InitWithBinary: fmt.Sprintf("https://github.com/kubernetes-sigs/cluster-api/releases/download/%s/clusterctl-{OS}-{ARCH}", e2eConfig.GetVariable(LatestCAPIUpgradeVersion)),
Expand All @@ -263,7 +263,7 @@ var _ = Describe("Running the Cluster API E2E tests", func() {
SkipCleanup: skipCleanup,
SkipConformanceTests: true,
ControlPlaneWaiters: clusterctl.ControlPlaneWaiters{
WaitForControlPlaneInitialized: EnsureControlPlaneInitialized,
WaitForControlPlaneMachinesReady: EnsureControlPlaneReady,
},
}
})
Expand All @@ -281,7 +281,7 @@ var _ = Describe("Running the Cluster API E2E tests", func() {
SkipCleanup: skipCleanup,
SkipConformanceTests: true,
ControlPlaneWaiters: clusterctl.ControlPlaneWaiters{
WaitForControlPlaneInitialized: EnsureControlPlaneInitialized,
WaitForControlPlaneMachinesReady: EnsureControlPlaneReady,
},
}
})
Expand All @@ -300,7 +300,7 @@ var _ = Describe("Running the Cluster API E2E tests", func() {
SkipConformanceTests: true,
Flavor: ptr.To("kcp-scale-in"),
ControlPlaneWaiters: clusterctl.ControlPlaneWaiters{
WaitForControlPlaneInitialized: EnsureControlPlaneInitialized,
WaitForControlPlaneMachinesReady: EnsureControlPlaneReady,
},
}
})
Expand Down
37 changes: 17 additions & 20 deletions test/e2e/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,27 +249,27 @@ func createRestConfig(ctx context.Context, tmpdir, namespace, clusterName string
return config
}

// EnsureControlPlaneInitialized waits for the cluster KubeadmControlPlane object to be initialized
// and then installs cloud-provider-azure components via Helm.
// EnsureControlPlaneReady waits for the cluster KubeadmControlPlane object to be initialized, installs
// cloud-provider-azure components via Helm, then waits for the control plane to become ready.
// Fulfills the clusterctl.Waiter type so that it can be used as ApplyClusterTemplateAndWaitInput data
// in the flow of a clusterctl.ApplyClusterTemplateAndWait E2E test scenario.
func EnsureControlPlaneInitialized(ctx context.Context, input clusterctl.ApplyCustomClusterTemplateAndWaitInput, result *clusterctl.ApplyCustomClusterTemplateAndWaitResult) {
ensureControlPlaneInitialized(ctx, input, result, true)
func EnsureControlPlaneReady(ctx context.Context, input clusterctl.ApplyCustomClusterTemplateAndWaitInput, result *clusterctl.ApplyCustomClusterTemplateAndWaitResult) {
ensureControlPlaneReady(ctx, input, result, true)
}

// EnsureControlPlaneInitializedNoAddons waits for the cluster KubeadmControlPlane object to be initialized
// and then installs cloud-provider-azure components via Helm.
// EnsureControlPlaneReadyNoAddons waits for the cluster KubeadmControlPlane object to be initialized, installs
// cloud-provider-azure components via Helm, then waits for the control plane to become ready.
// Fulfills the clusterctl.Waiter type so that it can be used as ApplyClusterTemplateAndWaitInput data
// in the flow of a clusterctl.ApplyClusterTemplateAndWait E2E test scenario.
func EnsureControlPlaneInitializedNoAddons(ctx context.Context, input clusterctl.ApplyCustomClusterTemplateAndWaitInput, result *clusterctl.ApplyCustomClusterTemplateAndWaitResult) {
ensureControlPlaneInitialized(ctx, input, result, false)
func EnsureControlPlaneReadyNoAddons(ctx context.Context, input clusterctl.ApplyCustomClusterTemplateAndWaitInput, result *clusterctl.ApplyCustomClusterTemplateAndWaitResult) {
ensureControlPlaneReady(ctx, input, result, false)
}

// ensureControlPlaneInitialized waits for the cluster KubeadmControlPlane object to be initialized
// and then installs cloud-provider-azure components via Helm.
// ensureControlPlaneReady waits for the cluster KubeadmControlPlane object to be initialized, installs
// cloud-provider-azure components via Helm, then waits for the control plane to become ready.
// Fulfills the clusterctl.Waiter type so that it can be used as ApplyClusterTemplateAndWaitInput data
// in the flow of a clusterctl.ApplyClusterTemplateAndWait E2E test scenario.
func ensureControlPlaneInitialized(ctx context.Context, input clusterctl.ApplyCustomClusterTemplateAndWaitInput, result *clusterctl.ApplyCustomClusterTemplateAndWaitResult, installHelmCharts bool) {
func ensureControlPlaneReady(ctx context.Context, input clusterctl.ApplyCustomClusterTemplateAndWaitInput, result *clusterctl.ApplyCustomClusterTemplateAndWaitResult, installHelmCharts bool) {
getter := input.ClusterProxy.GetClient()
cluster := framework.GetClusterByName(ctx, framework.GetClusterByNameInput{
Getter: getter,
Expand Down Expand Up @@ -303,9 +303,13 @@ func ensureControlPlaneInitialized(ctx context.Context, input clusterctl.ApplyCu
} else {
EnsureCNI(ctx, input, installHelmCharts, cluster.Spec.ClusterNetwork.Pods.CIDRBlocks, hasWindows)
}
controlPlane := discoveryAndWaitForControlPlaneInitialized(ctx, input, result)
EnsureAzureDiskCSIDriverHelmChart(ctx, input, installHelmCharts, hasWindows)
result.ControlPlane = controlPlane

framework.WaitForControlPlaneAndMachinesReady(ctx, framework.WaitForControlPlaneAndMachinesReadyInput{
GetLister: input.ClusterProxy.GetClient(),
Cluster: result.Cluster,
ControlPlane: result.ControlPlane,
}, input.WaitForControlPlaneIntervals...)
}

// CheckTestBeforeCleanup checks to see if the current running Ginkgo test failed, and prints
Expand All @@ -317,13 +321,6 @@ func CheckTestBeforeCleanup() {
Logf("Cleaning up after \"%s\" spec", CurrentSpecReport().FullText())
}

func discoveryAndWaitForControlPlaneInitialized(ctx context.Context, input clusterctl.ApplyCustomClusterTemplateAndWaitInput, result *clusterctl.ApplyCustomClusterTemplateAndWaitResult) *kubeadmv1.KubeadmControlPlane {
return framework.DiscoveryAndWaitForControlPlaneInitialized(ctx, framework.DiscoveryAndWaitForControlPlaneInitializedInput{
Lister: input.ClusterProxy.GetClient(),
Cluster: result.Cluster,
}, input.WaitForControlPlaneIntervals...)
}

func createApplyClusterTemplateInput(specName string, changes ...func(*clusterctl.ApplyClusterTemplateAndWaitInput)) clusterctl.ApplyClusterTemplateAndWaitInput {
input := clusterctl.ApplyClusterTemplateAndWaitInput{
ClusterProxy: bootstrapClusterProxy,
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/conformance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ var _ = Describe("Conformance Tests", func() {
withControlPlaneMachineCount(controlPlaneMachineCount),
withWorkerMachineCount(linuxWorkerMachineCount),
withControlPlaneWaiters(clusterctl.ControlPlaneWaiters{
WaitForControlPlaneInitialized: EnsureControlPlaneInitializedNoAddons,
WaitForControlPlaneInitialized: EnsureControlPlaneReadyNoAddons,
}),
), result)
stopwatch.Record("cluster creation")
Expand Down

0 comments on commit c45f03f

Please sign in to comment.