Skip to content

Commit

Permalink
[e2e] Avoid deleting the shared cluster after each test
Browse files Browse the repository at this point in the history
  • Loading branch information
Sedef committed Mar 12, 2020
1 parent 7d724ee commit 2fd92d8
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 28 deletions.
6 changes: 3 additions & 3 deletions test/infrastructure/docker/e2e/docker_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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
}

Expand All @@ -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
}

Expand Down
54 changes: 29 additions & 25 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 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)
Expand All @@ -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() {
Expand Down Expand Up @@ -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())
Expand Down

0 comments on commit 2fd92d8

Please sign in to comment.