Skip to content

Commit

Permalink
Inject registered cluster name into multi-cluster tests
Browse files Browse the repository at this point in the history
Depending on the context in which multi-cluster end-to-end tests are
run, there may not be any registered downstream cluster called `second`.
In such cases, such as when testing Fleet in Rancher, the CI workflow
computes the name of the registered cluster and exports it as an
environment variable, for the tests to use instead of `second`.
  • Loading branch information
weyfonk committed Nov 12, 2024
1 parent a23bd57 commit 0aaba0e
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/e2e-test-fleet-in-rancher.yml
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,9 @@ jobs:
run: |
kubectl config use-context k3d-upstream
ginkgo --github-output e2e/acceptance/single-cluster-examples
export CI_REGISTERED_CLUSTER=$(kc get clusters.fleet.cattle.io -n $FLEET_E2E_NS_DOWNSTREAM -o jsonpath='{..name}')
ginkgo --github-output e2e/multi-cluster
-
Expand Down
6 changes: 3 additions & 3 deletions e2e/multi-cluster/not_matching_targets_delete_bd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ var _ = Describe("Target clusters by label", func() {
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")
out, err := k.Namespace(env.ClusterRegistrationNamespace).Label("clusters", dsCluster, "envlabels=test")
Expect(err).ToNot(HaveOccurred(), out)
})

Expand All @@ -65,7 +65,7 @@ var _ = Describe("Target clusters by label", func() {
}).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-")
out, err := k.Namespace(env.ClusterRegistrationNamespace).Label("clusters", dsCluster, "envlabels-")
Expect(err).ToNot(HaveOccurred(), out)

Eventually(func() string {
Expand All @@ -78,7 +78,7 @@ var _ = Describe("Target clusters by label", func() {
}).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")
out, err = k.Namespace(env.ClusterRegistrationNamespace).Label("clusters", dsCluster, "envlabels=test")
Expect(err).ToNot(HaveOccurred(), out)

Eventually(func() string {
Expand Down
8 changes: 7 additions & 1 deletion e2e/multi-cluster/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
package multicluster_test

import (
"os"
"testing"

"github.com/rancher/fleet/e2e/testenv"
Expand All @@ -16,12 +17,17 @@ func TestE2E(t *testing.T) {
}

var (
env *testenv.Env
env *testenv.Env
dsCluster = "second"
)

var _ = BeforeSuite(func() {
SetDefaultEventuallyTimeout(testenv.Timeout)
testenv.SetRoot("../..")

env = testenv.New()

if dsClusterEnvVar := os.Getenv("CI_REGISTERED_CLUSTER"); dsClusterEnvVar != "" {
dsClusterEnvVar = dsClusterEnvVar

Check failure on line 31 in e2e/multi-cluster/suite_test.go

View workflow job for this annotation

GitHub Actions / golangci-lint

assign: self-assignment of dsClusterEnvVar to dsClusterEnvVar (govet)
}
})

0 comments on commit 0aaba0e

Please sign in to comment.