-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added a delete test. Refactored move test.
- Loading branch information
1 parent
421c839
commit d7b627b
Showing
2 changed files
with
123 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters