Skip to content

Commit

Permalink
Inject registered cluster name into multi-cluster tests (#3071)
Browse files Browse the repository at this point in the history
* Inject registered cluster name into multi-cluster tests

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`.

* Refer explicitly to Fleet API when labeling clusters

This prevents ambiguity by specifying the `fleet.cattle.io` domain when
labeling clusters in multi-cluster end-to-end tests, with `kubectl`
looking for `clusters.cluster.x-k8s.io` by default.

* Use non-managed downstream cluster in multi-cluster label tests

This makes the multi-cluster end-to-end test suite compatible with
setups in which only one, non-managed downstream cluster exists, such as
the test-Fleet-in-Rancher CI workflow.

* Use`dev-v2.10` as default base for test Fleet charts

This updates the default base test charts branch to match the current
state of Rancher releases.
  • Loading branch information
weyfonk authored and manno committed Dec 9, 2024
1 parent 7c9cf98 commit e01b546
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 7 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/e2e-multicluster-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,9 @@ jobs:
FLEET_E2E_NS: fleet-local
FLEET_E2E_NS_DOWNSTREAM: fleet-default
run: |
# Force use of non-managed downstream cluster for portability
export CI_REGISTERED_CLUSTER=$(kubectl get clusters.fleet.cattle.io -n $FLEET_E2E_NS_DOWNSTREAM -o jsonpath='{range .items[*]}{.metadata.name}{"\n"}' | grep -v second)
kubectl config use-context k3d-upstream
ginkgo --github-output e2e/multi-cluster
-
Expand Down
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=$(kubectl get clusters.fleet.cattle.io -n $FLEET_E2E_NS_DOWNSTREAM -o jsonpath='{..name}')
ginkgo --github-output e2e/multi-cluster
-
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/release-against-test-charts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ on:
charts_base_branch:
description: "Use the following rancher/charts branch as a base (e.g. dev-v2.7)"
required: true
default: "dev-v2.9"
default: "dev-v2.10"
charts_repo:
description: "Push to the following Rancher charts repo (which must exist)"
required: true
Expand All @@ -39,7 +39,7 @@ jobs:
ref=${tmp:-${{github.ref}}}
tmp=${{github.event.inputs.charts_base_branch}}
charts_base_branch=${tmp:-'dev-v2.8'}
charts_base_branch=${tmp:-'dev-v2.10'}
tmp=${{github.event.inputs.charts_repo}}
charts_repo=${tmp:-fleetrepoci/charts}
Expand Down
8 changes: 4 additions & 4 deletions e2e/multi-cluster/not_matching_targets_delete_bd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ var _ = Describe("Target clusters by label", func() {

BeforeEach(func() {
k = env.Kubectl.Context(env.Upstream)
kd = env.Kubectl.Context(env.ManagedDownstream)
kd = env.Kubectl.Context(env.Downstream)
})

JustBeforeEach(func() {
Expand All @@ -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("cluster.fleet.cattle.io", 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("cluster.fleet.cattle.io", 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("cluster.fleet.cattle.io", 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 != "" {
dsCluster = dsClusterEnvVar
}
})

0 comments on commit e01b546

Please sign in to comment.