Skip to content

Commit

Permalink
[e2e] Move cluster cleanups from AfterEach() to AfterSuite()
Browse files Browse the repository at this point in the history
  • Loading branch information
Sedef committed Mar 13, 2020
1 parent 5252a7a commit f3540e2
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 37 deletions.
24 changes: 24 additions & 0 deletions test/infrastructure/docker/e2e/docker_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,30 @@ var _ = BeforeSuite(func() {
})

var _ = AfterSuite(func() {
deleteClusterInput := framework.DeleteClusterInput{
Deleter: mgmtClient,
Cluster: cluster,
}
framework.DeleteCluster(ctx, deleteClusterInput)

waitForClusterDeletedInput := framework.WaitForClusterDeletedInput{
Getter: mgmtClient,
Cluster: cluster,
}
framework.WaitForClusterDeleted(ctx, waitForClusterDeletedInput)

assertAllClusterAPIResourcesAreGoneInput := framework.AssertAllClusterAPIResourcesAreGoneInput{
Lister: mgmtClient,
Cluster: cluster,
}
framework.AssertAllClusterAPIResourcesAreGone(ctx, assertAllClusterAPIResourcesAreGoneInput)

ensureDockerDeletedInput := ensureDockerArtifactsDeletedInput{
Lister: mgmtClient,
Cluster: cluster,
}
ensureDockerArtifactsDeleted(ensureDockerDeletedInput)

// Dump the logs of the providers before deleting them.
Expect(writeLogs(mgmt, "capi-system", "capi-controller-manager", logPath)).To(Succeed())
Expect(writeLogs(mgmt, "capi-kubeadm-bootstrap-system", "capi-kubeadm-bootstrap-controller-manager", logPath)).To(Succeed())
Expand Down
52 changes: 15 additions & 37 deletions test/infrastructure/docker/e2e/docker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,14 @@ import (
ctrlclient "sigs.k8s.io/controller-runtime/pkg/client"
)

var mgmtClient ctrlclient.Client
var cluster *clusterv1.Cluster

var _ = Describe("Docker", func() {
Describe("Cluster Creation", func() {
var (
namespace string
client ctrlclient.Client
clusterGen = &ClusterGenerator{}
cluster *clusterv1.Cluster
)
SetDefaultEventuallyTimeout(3 * time.Minute)
SetDefaultEventuallyPollingInterval(10 * time.Second)
Expand All @@ -65,30 +66,6 @@ var _ = Describe("Docker", func() {
"DockerMachineTemplate": &infrav1.DockerMachineTemplateList{},
}
Expect(framework.DumpProviderResources(mgmt, resources, resourcesPath, GinkgoWriter)).To(Succeed())

deleteClusterInput := framework.DeleteClusterInput{
Deleter: client,
Cluster: cluster,
}
framework.DeleteCluster(ctx, deleteClusterInput)

waitForClusterDeletedInput := framework.WaitForClusterDeletedInput{
Getter: client,
Cluster: cluster,
}
framework.WaitForClusterDeleted(ctx, waitForClusterDeletedInput)

assertAllClusterAPIResourcesAreGoneInput := framework.AssertAllClusterAPIResourcesAreGoneInput{
Lister: client,
Cluster: cluster,
}
framework.AssertAllClusterAPIResourcesAreGone(ctx, assertAllClusterAPIResourcesAreGoneInput)

ensureDockerDeletedInput := ensureDockerArtifactsDeletedInput{
Lister: client,
Cluster: cluster,
}
ensureDockerArtifactsDeleted(ensureDockerDeletedInput)
})

Describe("Multi-node controlplane cluster", func() {
Expand All @@ -113,35 +90,35 @@ var _ = Describe("Docker", func() {
md, infraTemplate, bootstrapTemplate := GenerateMachineDeployment(cluster, 1)

// Set up the client to the management cluster
client, err = mgmt.GetClient()
mgmtClient, err = mgmt.GetClient()
Expect(err).NotTo(HaveOccurred())

// Set up the cluster object
createClusterInput := framework.CreateClusterInput{
Creator: client,
Creator: mgmtClient,
Cluster: cluster,
InfraCluster: infraCluster,
}
framework.CreateCluster(ctx, createClusterInput)

// Set up the KubeadmControlPlane
createKubeadmControlPlaneInput := framework.CreateKubeadmControlPlaneInput{
Creator: client,
Creator: mgmtClient,
ControlPlane: controlPlane,
MachineTemplate: template,
}
framework.CreateKubeadmControlPlane(ctx, createKubeadmControlPlaneInput)

// Wait for the cluster to provision.
assertClusterProvisionsInput := framework.WaitForClusterToProvisionInput{
Getter: client,
Getter: mgmtClient,
Cluster: cluster,
}
framework.WaitForClusterToProvision(ctx, assertClusterProvisionsInput)

// Wait for at least one control plane node to be ready
waitForOneKubeadmControlPlaneMachineToExistInput := framework.WaitForOneKubeadmControlPlaneMachineToExistInput{
Lister: client,
Lister: mgmtClient,
Cluster: cluster,
ControlPlane: controlPlane,
}
Expand All @@ -160,15 +137,15 @@ var _ = Describe("Docker", func() {

// Wait for the controlplane nodes to exist
assertKubeadmControlPlaneNodesExistInput := framework.WaitForKubeadmControlPlaneMachinesToExistInput{
Lister: client,
Lister: mgmtClient,
Cluster: cluster,
ControlPlane: controlPlane,
}
framework.WaitForKubeadmControlPlaneMachinesToExist(ctx, assertKubeadmControlPlaneNodesExistInput, "10m", "10s")

// Create the workload nodes
createMachineDeploymentinput := framework.CreateMachineDeploymentInput{
Creator: client,
Creator: mgmtClient,
MachineDeployment: md,
BootstrapConfigTemplate: bootstrapTemplate,
InfraMachineTemplate: infraTemplate,
Expand All @@ -177,15 +154,15 @@ var _ = Describe("Docker", func() {

// Wait for the workload nodes to exist
waitForMachineDeploymentNodesToExistInput := framework.WaitForMachineDeploymentNodesToExistInput{
Lister: client,
Lister: mgmtClient,
Cluster: cluster,
MachineDeployment: md,
}
framework.WaitForMachineDeploymentNodesToExist(ctx, waitForMachineDeploymentNodesToExistInput)

// Wait for the control plane to be ready
waitForControlPlaneToBeReadyInput := framework.WaitForControlPlaneToBeReadyInput{
Getter: client,
Getter: mgmtClient,
ControlPlane: controlPlane,
}
framework.WaitForControlPlaneToBeReady(ctx, waitForControlPlaneToBeReadyInput)
Expand All @@ -202,11 +179,12 @@ var _ = Describe("Docker", func() {
},
}
framework.AssertControlPlaneFailureDomains(ctx, assertControlPlaneFailureDomainInput)

})

Specify("Full upgrade", func() {
By("upgrading the control plane object to a new version")
patchHelper, err := patch.NewHelper(controlPlane, client)
patchHelper, err := patch.NewHelper(controlPlane, mgmtClient)
Expect(err).ToNot(HaveOccurred())
controlPlane.Spec.Version = "1.17.2"
Expect(patchHelper.Patch(ctx, controlPlane)).To(Succeed())
Expand All @@ -220,7 +198,7 @@ var _ = Describe("Docker", func() {

Eventually(func() (int, error) {
machineList := &clusterv1.MachineList{}
if err := client.List(ctx, machineList, inClustersNamespaceListOption, matchClusterListOption); err != nil {
if err := mgmtClient.List(ctx, machineList, inClustersNamespaceListOption, matchClusterListOption); err != nil {
fmt.Println(err)
return 0, err
}
Expand Down

0 comments on commit f3540e2

Please sign in to comment.