Skip to content

Commit e9f25d6

Browse files
committed
Disconnect cluster instead of scaling Fleet agent deployment
Taking advantage of k3d, multi-cluster end-to-end tests are able to simulate disconnection of a cluster by disconnecting the cluster node container from its Docker network, and reconnecting it. Disconnecting the server node is enough, as this blocks outbound traffic, in this case the agent's check-in requests to the controller. Disconnecting the load balancer node, to block inbound traffic, is not necessary. This should represent a more realistic use case than scaling Fleet agent deployments.
1 parent c24b91e commit e9f25d6

3 files changed

Lines changed: 21 additions & 13 deletions

File tree

.github/workflows/e2e-multicluster-ci.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ jobs:
8383
-p "443:443@agent:0:direct" \
8484
--api-port 6443 \
8585
--agents 1 \
86-
--network "nw01"
86+
--network "fleet"
8787
-
8888
name: Provision k3d Downstream Cluster for agent-initiated registration
8989
run: |
@@ -92,7 +92,7 @@ jobs:
9292
-p "444:443@agent:0:direct" \
9393
--api-port 6644 \
9494
--agents 1 \
95-
--network "nw01"
95+
--network "fleet"
9696
-
9797
name: Provision k3d Downstream Cluster for manager-initiated registration
9898
run: |
@@ -101,7 +101,7 @@ jobs:
101101
-p "445:443@agent:0:direct" \
102102
--api-port 6645 \
103103
--agents 1 \
104-
--network "nw01"
104+
--network "fleet"
105105
-
106106
name: Import Images Into k3d
107107
run: |
@@ -214,6 +214,7 @@ jobs:
214214
env:
215215
FLEET_E2E_NS: fleet-local
216216
FLEET_E2E_NS_DOWNSTREAM: fleet-default
217+
FLEET_E2E_CLUSTER_DOWNSTREAM: k3d-downstream
217218
run: |
218219
# Force use of non-managed downstream cluster for portability
219220
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)

e2e/multi-cluster/offline_cluster_test.go

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package multicluster_test
22

33
import (
44
"encoding/json"
5+
"os/exec"
56
"time"
67

78
. "github.com/onsi/ginkgo/v2"
@@ -18,14 +19,12 @@ import (
1819
var _ = Describe("Offline cluster detection", func() {
1920
var (
2021
k kubectl.Command
21-
kd kubectl.Command
2222
asset string
2323
name string
2424
)
2525

2626
BeforeEach(func() {
2727
k = env.Kubectl.Context(env.Upstream)
28-
kd = env.Kubectl.Context(env.Downstream).Namespace("fleet-default")
2928
})
3029

3130
Context("cluster with deployed workload becomes offline", func() {
@@ -55,8 +54,8 @@ var _ = Describe("Offline cluster detection", func() {
5554
Expect(err).ToNot(HaveOccurred())
5655

5756
DeferCleanup(func() {
58-
out, err := kd.Namespace("cattle-fleet-system").Run("scale", "deployment", "fleet-agent", "--replicas=1", "--timeout=60s")
59-
Expect(err).ToNot(HaveOccurred(), out)
57+
connectCmd := exec.Command("docker", "network", "connect", "fleet", "k3d-"+k3dDownstreamCluster+"-server-0")
58+
_, _ = connectCmd.CombinedOutput() // will fail if the node is already connected.
6059

6160
_, _ = k.Namespace(env.ClusterRegistrationNamespace).Delete("helmop", name)
6261
})
@@ -88,8 +87,9 @@ var _ = Describe("Offline cluster detection", func() {
8887
}).To(Succeed())
8988

9089
By("taking the cluster offline")
91-
out, err := kd.Namespace("cattle-fleet-system").Run("scale", "deployment", "fleet-agent", "--replicas=0", "--timeout=60s")
92-
Expect(err).ToNot(HaveOccurred(), out)
90+
disconnectCmd := exec.Command("docker", "network", "disconnect", "fleet", "k3d-"+k3dDownstreamCluster+"-server-0")
91+
out, err := disconnectCmd.CombinedOutput()
92+
Expect(err).ToNot(HaveOccurred(), string(out))
9393

9494
By("checking that the bundle deployment and the cluster appear offline")
9595
// Cluster should be offline
@@ -117,8 +117,9 @@ var _ = Describe("Offline cluster detection", func() {
117117
}).To(Succeed())
118118

119119
By("taking the cluster back online")
120-
out, err = kd.Namespace("cattle-fleet-system").Run("scale", "deployment", "fleet-agent", "--replicas=1", "--timeout=60s")
121-
Expect(err).ToNot(HaveOccurred(), out)
120+
connectCmd := exec.Command("docker", "network", "connect", "fleet", "k3d-"+k3dDownstreamCluster+"-server-0")
121+
out, err = connectCmd.CombinedOutput()
122+
Expect(err).ToNot(HaveOccurred(), string(out))
122123

123124
By("checking the new online state of the cluster")
124125
// Cluster should be ready again

e2e/multi-cluster/suite_test.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package multicluster_test
33

44
import (
55
"os"
6+
"strings"
67
"testing"
78

89
"github.com/rancher/fleet/e2e/testenv"
@@ -17,8 +18,9 @@ func TestE2E(t *testing.T) {
1718
}
1819

1920
var (
20-
env *testenv.Env
21-
dsCluster = "second"
21+
env *testenv.Env
22+
dsCluster = "second" // name of the Fleet Cluster resource
23+
k3dDownstreamCluster = "downstream"
2224
)
2325

2426
var _ = BeforeSuite(func() {
@@ -30,4 +32,8 @@ var _ = BeforeSuite(func() {
3032
if dsClusterEnvVar := os.Getenv("CI_REGISTERED_CLUSTER"); dsClusterEnvVar != "" {
3133
dsCluster = dsClusterEnvVar
3234
}
35+
36+
if k3dDSClusterEnvVar := os.Getenv("FLEET_E2E_CLUSTER_DOWNSTREAM"); k3dDSClusterEnvVar != "" {
37+
k3dDownstreamCluster = strings.TrimPrefix(k3dDSClusterEnvVar, "k3d-")
38+
}
3339
})

0 commit comments

Comments
 (0)