-
Notifications
You must be signed in to change notification settings - Fork 239
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add e2e tests for the deleteNamespace feature
- Loading branch information
1 parent
732ebb4
commit c853a2f
Showing
4 changed files
with
160 additions
and
0 deletions.
There are no files selected for viewing
18 changes: 18 additions & 0 deletions
18
e2e/assets/single-cluster/delete-namespace/do-not-delete/gitrepo.yaml
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,18 @@ | ||
kind: GitRepo | ||
apiVersion: fleet.cattle.io/v1alpha1 | ||
metadata: | ||
name: my-gitrepo | ||
spec: | ||
repo: https://github.com/rancher/fleet-test-data | ||
branch: master | ||
paths: | ||
- helm-verify | ||
targetNamespace: my-custom-namespace | ||
deleteNamespace: false | ||
targets: | ||
- clusterSelector: | ||
matchExpressions: | ||
- key: provider.cattle.io | ||
operator: NotIn | ||
values: | ||
- harvester |
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,18 @@ | ||
kind: GitRepo | ||
apiVersion: fleet.cattle.io/v1alpha1 | ||
metadata: | ||
name: my-gitrepo | ||
spec: | ||
repo: https://github.com/rancher/fleet-test-data | ||
branch: master | ||
paths: | ||
- helm-verify | ||
targetNamespace: {{.TargetNamespace}} | ||
deleteNamespace: {{.DeleteNamespace}} | ||
targets: | ||
- clusterSelector: | ||
matchExpressions: | ||
- key: provider.cattle.io | ||
operator: NotIn | ||
values: | ||
- harvester |
17 changes: 17 additions & 0 deletions
17
e2e/assets/single-cluster/delete-namespace/without-target-namespace/gitrepo.yaml
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,17 @@ | ||
kind: GitRepo | ||
apiVersion: fleet.cattle.io/v1alpha1 | ||
metadata: | ||
name: my-gitrepo | ||
spec: | ||
repo: https://github.com/rancher/fleet-test-data | ||
branch: master | ||
paths: | ||
- helm-verify | ||
deleteNamespace: true | ||
targets: | ||
- clusterSelector: | ||
matchExpressions: | ||
- key: provider.cattle.io | ||
operator: NotIn | ||
values: | ||
- harvester |
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,107 @@ | ||
package singlecluster_test | ||
|
||
import ( | ||
"errors" | ||
"strings" | ||
|
||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
"github.com/rancher/fleet/e2e/testenv" | ||
"github.com/rancher/fleet/e2e/testenv/kubectl" | ||
) | ||
|
||
var _ = Describe("delete namespaces", func() { | ||
var ( | ||
k kubectl.Command | ||
targetNamespace string | ||
deleteNamespace bool | ||
) | ||
|
||
type TemplateData struct { | ||
TargetNamespace string | ||
DeleteNamespace bool | ||
} | ||
|
||
BeforeEach(func() { | ||
k = env.Kubectl.Namespace(env.Namespace) | ||
deleteNamespace = false | ||
|
||
DeferCleanup(func() { | ||
_, _ = k.Delete("ns", "my-custom-namespace", "--wait=false") | ||
}) | ||
}) | ||
|
||
JustBeforeEach(func() { | ||
err := testenv.ApplyTemplate(k, testenv.AssetPath("single-cluster/delete-namespace/gitrepo.yaml"), | ||
TemplateData{targetNamespace, deleteNamespace}) | ||
|
||
Expect(err).ToNot(HaveOccurred()) | ||
Eventually(func() error { | ||
out, err := k.Namespace(targetNamespace).Get("configmaps") | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if !strings.Contains(out, "app-config") { | ||
return errors.New("expected configmap is not found") | ||
} | ||
|
||
return nil | ||
}).ShouldNot(HaveOccurred()) | ||
}) | ||
|
||
When("delete namespaces is false", func() { | ||
BeforeEach(func() { | ||
targetNamespace = "my-custom-namespace" | ||
}) | ||
|
||
It("targetNamespace is preserved when GitRepo is deleted", func() { | ||
out, err := k.Delete("gitrepo", "my-gitrepo", "-n", "fleet-local") | ||
Expect(err).ToNot(HaveOccurred(), out) | ||
|
||
Eventually(func() string { | ||
out, _ := k.Get("namespaces", targetNamespace) | ||
return out | ||
}).Should(ContainSubstring(targetNamespace)) | ||
}) | ||
}) | ||
|
||
When("delete namespaces is true", func() { | ||
BeforeEach(func() { | ||
deleteNamespace = true | ||
}) | ||
|
||
It("targetNamespace is deleted after deleting gitRepo", func() { | ||
_, err := k.Get("namespaces", targetNamespace) | ||
Expect(err).To(BeNil()) | ||
|
||
out, err := k.Delete("gitrepo", "my-gitrepo", "-n", "fleet-local") | ||
Expect(err).ToNot(HaveOccurred(), out) | ||
|
||
Eventually(func() error { | ||
_, err = k.Get("namespaces", targetNamespace) | ||
return err | ||
}).ShouldNot(BeNil()) | ||
}) | ||
}) | ||
|
||
When("delete namespaces is true but resources are deployed in default namespace", func() { | ||
BeforeEach(func() { | ||
deleteNamespace = true | ||
targetNamespace = "default" | ||
}) | ||
|
||
It("default namespace exists", func() { | ||
out, err := k.Delete("gitrepo", "my-gitrepo", "-n", "fleet-local") | ||
Expect(err).ToNot(HaveOccurred(), out) | ||
|
||
Eventually(func() string { | ||
out, _ = k.Namespace(targetNamespace).Get("configmap", "app-config", "-o", "yaml") | ||
return out | ||
}).Should(ContainSubstring("Error from server (NotFound)")) | ||
|
||
_, err = k.Get("namespaces", targetNamespace) | ||
Expect(err).ToNot(HaveOccurred()) | ||
}) | ||
}) | ||
}) |