-
Notifications
You must be signed in to change notification settings - Fork 247
Adds e2e test to check that bundledeployments are deleted #2841
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,21 @@ | ||
kind: GitRepo | ||
apiVersion: fleet.cattle.io/v1alpha1 | ||
metadata: | ||
name: simpleapplabels | ||
namespace: {{.ProjectNamespace}} | ||
labels: | ||
team: one | ||
|
||
spec: | ||
repo: https://github.com/rancher/fleet-test-data | ||
branch: master | ||
paths: | ||
- simple | ||
|
||
targetNamespace: {{.TargetNamespace}} | ||
|
||
targets: | ||
- name: test | ||
clusterSelector: | ||
matchLabels: | ||
envlabels: test |
This file contains hidden or 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,94 @@ | ||
package multicluster_test | ||
|
||
import ( | ||
"math/rand" | ||
|
||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
|
||
"github.com/rancher/fleet/e2e/testenv" | ||
"github.com/rancher/fleet/e2e/testenv/kubectl" | ||
) | ||
|
||
// This test uses labels in clusters to demonstrate that applying or | ||
// deleting the label installs or uninstalls the bundle deployment | ||
var _ = Describe("Target clusters by label", func() { | ||
var ( | ||
k kubectl.Command | ||
kd kubectl.Command | ||
|
||
asset string | ||
namespace string | ||
data any | ||
|
||
r = rand.New(rand.NewSource(GinkgoRandomSeed())) | ||
) | ||
|
||
type TemplateData struct { | ||
ProjectNamespace string | ||
TargetNamespace string | ||
} | ||
|
||
BeforeEach(func() { | ||
k = env.Kubectl.Context(env.Upstream) | ||
kd = env.Kubectl.Context(env.ManagedDownstream) | ||
}) | ||
|
||
JustBeforeEach(func() { | ||
err := testenv.ApplyTemplate(k.Namespace(env.ClusterRegistrationNamespace), testenv.AssetPath(asset), data) | ||
Expect(err).ToNot(HaveOccurred()) | ||
}) | ||
|
||
AfterEach(func() { | ||
out, err := k.Namespace(env.ClusterRegistrationNamespace).Delete("gitrepo", "simpleapplabels", "--wait=false") | ||
Expect(err).ToNot(HaveOccurred(), out) | ||
}) | ||
|
||
Context("if cluster has the expected label, bundle is deployed", func() { | ||
BeforeEach(func() { | ||
namespace = testenv.NewNamespaceName("label-not-set", r) | ||
asset = "multi-cluster/bundle-deployment-labels.yaml" | ||
data = TemplateData{env.ClusterRegistrationNamespace, namespace} | ||
// set the expected label | ||
out, err := k.Namespace(env.ClusterRegistrationNamespace).Label("clusters", "second", "envlabels=test") | ||
Expect(err).ToNot(HaveOccurred(), out) | ||
}) | ||
|
||
It("deploys to the mapped downstream cluster and when label is deleted it removes the deployment", func() { | ||
Eventually(func() string { | ||
out, _ := k.Get("bundledeployments", "-A", "-l", "fleet.cattle.io/bundle-name=simpleapplabels-simple") | ||
return out | ||
}).Should(ContainSubstring("simpleapplabels-simple")) | ||
Eventually(func() string { | ||
out, _ := kd.Get("configmaps", "-A") | ||
return out | ||
}).Should(ContainSubstring("simple-config")) | ||
|
||
// delete the label (bundledeployment should be deleted and resources in cluster deleted) | ||
out, err := k.Namespace(env.ClusterRegistrationNamespace).Label("clusters", "second", "envlabels-") | ||
Expect(err).ToNot(HaveOccurred(), out) | ||
|
||
Eventually(func() string { | ||
out, _ := k.Get("bundledeployments", "-A", "-l", "fleet.cattle.io/bundle-name=simpleapplabels-simple") | ||
return out | ||
}).ShouldNot(ContainSubstring("simpleapplabels-simple")) | ||
Eventually(func() string { | ||
out, _ := kd.Namespace(namespace).Get("configmaps") | ||
return out | ||
}).ShouldNot(ContainSubstring("simple-config")) | ||
|
||
// re-apply the label (bundledeployment should be created and applied again) | ||
out, err = k.Namespace(env.ClusterRegistrationNamespace).Label("clusters", "second", "envlabels=test") | ||
Expect(err).ToNot(HaveOccurred(), out) | ||
|
||
Eventually(func() string { | ||
out, _ := k.Get("bundledeployments", "-A", "-l", "fleet.cattle.io/bundle-name=simpleapplabels-simple") | ||
return out | ||
}).Should(ContainSubstring("simpleapplabels-simple")) | ||
Eventually(func() string { | ||
out, _ := kd.Namespace(namespace).Get("configmaps") | ||
return out | ||
}).Should(ContainSubstring("simple-config")) | ||
}) | ||
}) | ||
}) |
This file contains hidden or 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
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: this could most likely be made more lightweight by testing direct creation of a bundle, skipping
GitRepo
.