From 2fd92d8cc5dd0d6dbf24fb2e774e0d16a4ecc935 Mon Sep 17 00:00:00 2001 From: Sedef Date: Thu, 12 Mar 2020 08:54:10 -0700 Subject: [PATCH] [e2e] Avoid deleting the shared cluster after each test --- .../docker/e2e/docker_suite_test.go | 6 +-- test/infrastructure/docker/e2e/docker_test.go | 54 ++++++++++--------- 2 files changed, 32 insertions(+), 28 deletions(-) diff --git a/test/infrastructure/docker/e2e/docker_suite_test.go b/test/infrastructure/docker/e2e/docker_suite_test.go index 95ed9ee0d9eb..6fb47cad1152 100644 --- a/test/infrastructure/docker/e2e/docker_suite_test.go +++ b/test/infrastructure/docker/e2e/docker_suite_test.go @@ -42,7 +42,7 @@ import ( "sigs.k8s.io/cluster-api/test/framework" infrav1 "sigs.k8s.io/cluster-api/test/infrastructure/docker/api/v1alpha3" "sigs.k8s.io/cluster-api/util" - "sigs.k8s.io/controller-runtime/pkg/client" + cl "sigs.k8s.io/controller-runtime/pkg/client" ) func TestDocker(t *testing.T) { @@ -134,7 +134,7 @@ func writeLogs(mgmt *CAPDCluster, namespace, deploymentName, logDir string) erro return err } deployment := &appsv1.Deployment{} - if err := c.Get(context.TODO(), client.ObjectKey{Namespace: namespace, Name: deploymentName}, deployment); err != nil { + if err := c.Get(context.TODO(), cl.ObjectKey{Namespace: namespace, Name: deploymentName}, deployment); err != nil { return err } @@ -144,7 +144,7 @@ func writeLogs(mgmt *CAPDCluster, namespace, deploymentName, logDir string) erro } pods := &corev1.PodList{} - if err := c.List(context.TODO(), pods, client.InNamespace(namespace), client.MatchingLabels(selector)); err != nil { + if err := c.List(context.TODO(), pods, cl.InNamespace(namespace), cl.MatchingLabels(selector)); err != nil { return err } diff --git a/test/infrastructure/docker/e2e/docker_test.go b/test/infrastructure/docker/e2e/docker_test.go index a6bb5f017e97..7c9f2341022c 100644 --- a/test/infrastructure/docker/e2e/docker_test.go +++ b/test/infrastructure/docker/e2e/docker_test.go @@ -41,13 +41,14 @@ import ( ctrlclient "sigs.k8s.io/controller-runtime/pkg/client" ) +var client 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) @@ -66,29 +67,6 @@ var _ = Describe("Docker", func() { } 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() { @@ -240,6 +218,32 @@ var _ = Describe("Docker", func() { }) }) +var _ = AfterSuite(func() { + 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) +}) + func GenerateMachineDeployment(cluster *clusterv1.Cluster, replicas int32) (*clusterv1.MachineDeployment, *infrav1.DockerMachineTemplate, *bootstrapv1.KubeadmConfigTemplate) { namespace := cluster.GetNamespace() generatedName := fmt.Sprintf("%s-md", cluster.GetName())