Skip to content

Commit

Permalink
Added a delete test. Refactored move test.
Browse files Browse the repository at this point in the history
  • Loading branch information
Arvinderpal committed Feb 9, 2020
1 parent 421c839 commit d7b627b
Show file tree
Hide file tree
Showing 2 changed files with 123 additions and 20 deletions.
108 changes: 108 additions & 0 deletions cmd/clusterctl/test/e2e/delete_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
// +build e2e

/*
Copyright 2020 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package e2e

import (
"fmt"
"time"

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"

appsv1 "k8s.io/api/apps/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
"sigs.k8s.io/cluster-api/test/framework"
"sigs.k8s.io/cluster-api/test/framework/management/kind"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/kind/pkg/cluster"

clusterctlclient "sigs.k8s.io/cluster-api/cmd/clusterctl/pkg/client"
)

var _ = Describe("clusterctl delete", func() {
var (
cfgFile string
mgmtCluster *kind.Cluster
mgmtClient client.Client
deleteOptions clusterctlclient.DeleteOptions
cctlClient clusterctlclient.Client
)

BeforeEach(func() {
var err error
// Create the mgmt cluster and client
mgmtCluster, err = CreateKindCluster(kindConfigFile)
Expect(err).ToNot(HaveOccurred())
mgmtClient, err = mgmtCluster.GetClient()
Expect(err).NotTo(HaveOccurred())
cctlClient, err = clusterctlclient.New(cfgFile)
Expect(err).ToNot(HaveOccurred())
initOptmgmtCluster := clusterctlclient.InitOptions{
Kubeconfig: mgmtCluster.KubeconfigPath,
CoreProvider: "cluster-api:v0.3.0",
BootstrapProviders: []string{"kubeadm-bootstrap:v0.3.0"},
ControlPlaneProviders: []string{"kubeadm-control-plane:v0.3.0"},
InfrastructureProviders: []string{"docker:v0.3.0"},
}
_, err = cctlClient.Init(initOptmgmtCluster)
Expect(err).ToNot(HaveOccurred())
framework.WaitForAPIServiceAvailable(ctx, mgmtCluster, "v1beta1.webhook.cert-manager.io")
CheckAndWaitCAPITestDeploymentsExist(mgmtClient)
// Create a capi Cluster and capd objects
err = mgmtCluster.Apply(ctx, []byte(testClusterYAML))
Expect(err).ToNot(HaveOccurred())

}, setupTimeout)

JustBeforeEach(func() {
err := cctlClient.Delete(deleteOptions)
Expect(err).ToNot(HaveOccurred())
})

AfterEach(func() {
fmt.Fprintf(GinkgoWriter, "Tearing down kind clusters\n")
mgmtCluster.Teardown(ctx)
fmt.Fprintf(GinkgoWriter, "Tearing down kind workload cluster\n")
if err := cluster.NewProvider().Delete("foo-cluster", ""); err != nil {
// Treat this as a non critical error
fmt.Fprintf(GinkgoWriter, "Deleting the kind cluster \"foo-cluster\" failed. You may need to remove this by hand.\n")
}
})

Context("deletes the infra provider", func() {
BeforeEach(func() {
deleteOptions = clusterctlclient.DeleteOptions{
Kubeconfig: mgmtCluster.KubeconfigPath,
Providers: []string{"docker"},
}
})
It("should delete of all infra provider components except the hosting namespace and the CRDs.", func() {
Eventually(
func() error {
err := mgmtClient.Get(ctx, client.ObjectKey{Namespace: "capd-system", Name: "capd-controller-manager"}, &appsv1.Deployment{})
if err == nil || !apierrors.IsNotFound(err) {
// deployment still exists or some other error other than not found occured.
return fmt.Errorf("%v", err)
}
return nil
}, 3*time.Minute, 5*time.Second,
).ShouldNot(HaveOccurred())
})
})
})
35 changes: 15 additions & 20 deletions cmd/clusterctl/test/e2e/move_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,30 +145,25 @@ var _ = Describe("clusterctl move", func() {
// Should delete all Cluster API objects from the previous management cluster.
Eventually(
func() error {
if err := fromMgmtClient.Get(ctx, client.ObjectKey{Namespace: "default", Name: "foo-cluster"}, &clusterv1.Cluster{}); err != nil {
if !apierrors.IsNotFound(err) {
return err
}
err := fromMgmtClient.Get(ctx, client.ObjectKey{Namespace: "default", Name: "foo-cluster"}, &clusterv1.Cluster{})
if err == nil || !apierrors.IsNotFound(err) {
return fmt.Errorf("%v", err)
}
if err := fromMgmtClient.Get(ctx, client.ObjectKey{Namespace: "default", Name: "controlplane-0"}, &clusterv1.Machine{}); err != nil {
if !apierrors.IsNotFound(err) {
return err
}
err = fromMgmtClient.Get(ctx, client.ObjectKey{Namespace: "default", Name: "controlplane-0"}, &clusterv1.Machine{})
if err == nil || !apierrors.IsNotFound(err) {
return fmt.Errorf("%v", err)
}
if err := fromMgmtClient.Get(ctx, client.ObjectKey{Namespace: "default", Name: "controlplane-0-config"}, &bootstrapv1.KubeadmConfig{}); err != nil {
if !apierrors.IsNotFound(err) {
return err
}
err = fromMgmtClient.Get(ctx, client.ObjectKey{Namespace: "default", Name: "controlplane-0-config"}, &bootstrapv1.KubeadmConfig{})
if err == nil || !apierrors.IsNotFound(err) {
return fmt.Errorf("%v", err)
}
if err := fromMgmtClient.Get(ctx, client.ObjectKey{Namespace: "default", Name: "foo-cluster"}, &infrav1.DockerCluster{}); err != nil {
if !apierrors.IsNotFound(err) {
return err
}
err = fromMgmtClient.Get(ctx, client.ObjectKey{Namespace: "default", Name: "foo-cluster"}, &infrav1.DockerCluster{})
if err == nil || !apierrors.IsNotFound(err) {
return fmt.Errorf("%v", err)
}
if err := fromMgmtClient.Get(ctx, client.ObjectKey{Namespace: "default", Name: "controlplane-0"}, &infrav1.DockerMachine{}); err != nil {
if !apierrors.IsNotFound(err) {
return err
}
err = fromMgmtClient.Get(ctx, client.ObjectKey{Namespace: "default", Name: "controlplane-0"}, &infrav1.DockerMachine{})
if err == nil || !apierrors.IsNotFound(err) {
return fmt.Errorf("%v", err)
}
return nil
}, 3*time.Minute, 5*time.Second,
Expand Down

0 comments on commit d7b627b

Please sign in to comment.