Skip to content

Commit ad62f90

Browse files
authored
Merge pull request #205 from squat/test_multi_cluster
Test multi cluster
2 parents 6de6b37 + 19b0797 commit ad62f90

3 files changed

Lines changed: 69 additions & 2 deletions

File tree

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@
44
.push*
55
bin/
66
tmp/
7-
e2e/kind.yaml
7+
e2e/kind.yaml*

Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ EMBEDMD_BINARY := bin/embedmd
4343
KIND_BINARY := $(shell pwd)/bin/kind
4444
KUBECTL_BINARY := $(shell pwd)/bin/kubectl
4545
BASH_UNIT := $(shell pwd)/bin/bash_unit
46+
BASH_UNIT_FLAGS :=
4647

4748
BUILD_IMAGE ?= golang:1.16.5-alpine
4849
BASE_IMAGE ?= alpine:3.13
@@ -208,7 +209,7 @@ $(BASH_UNIT):
208209
chmod +x $@
209210

210211
e2e: container $(KIND_BINARY) $(KUBECTL_BINARY) $(BASH_UNIT) bin/$(OS)/$(ARCH)/kgctl
211-
KILO_IMAGE=$(IMAGE):$(ARCH)-$(VERSION) KIND_BINARY=$(KIND_BINARY) KUBECTL_BINARY=$(KUBECTL_BINARY) KGCTL_BINARY=$(shell pwd)/bin/$(OS)/$(ARCH)/kgctl $(BASH_UNIT) ./e2e/setup.sh ./e2e/full-mesh.sh ./e2e/location-mesh.sh ./e2e/teardown.sh
212+
KILO_IMAGE=$(IMAGE):$(ARCH)-$(VERSION) KIND_BINARY=$(KIND_BINARY) KUBECTL_BINARY=$(KUBECTL_BINARY) KGCTL_BINARY=$(shell pwd)/bin/$(OS)/$(ARCH)/kgctl $(BASH_UNIT) $(BASH_UNIT_FLAGS) ./e2e/setup.sh ./e2e/full-mesh.sh ./e2e/location-mesh.sh ./e2e/multi-cluster.sh ./e2e/teardown.sh
212213

213214
header: .header
214215
@HEADER=$$(cat .header); \

e2e/multi-cluster.sh

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
#!/usr/bin/env bash
2+
# shellcheck disable=SC1091
3+
. lib.sh
4+
5+
# shellcheck disable=SC2153
6+
KUBECONFIG2="$KUBECONFIG"2
7+
# shellcheck disable=SC2153
8+
KIND_CLUSTER2="$KIND_CLUSTER"2
9+
10+
setup_suite() {
11+
KUBECONFIG=$KUBECONFIG2 KIND_CLUSTER=$KIND_CLUSTER2 create_cluster "$(build_kind_config 1 6444 10.44.0.0/16 10.45.0.0/16)"
12+
# shellcheck disable=SC2016
13+
KUBECONFIG=$KUBECONFIG2 _kubectl patch ds -n kube-system kilo -p '{"spec": {"template":{"spec":{"containers":[{"name":"kilo","args":["--hostname=$(NODE_NAME)","--create-interface=false","--kubeconfig=/etc/kubernetes/kubeconfig","--mesh-granularity=full","--subnet=10.6.0.0/16"]}]}}}}'
14+
KUBECONFIG=$KUBECONFIG2 block_until_ready_by_name kube-system kilo-userspace
15+
# Register the nodes in cluster1 as peers of cluster2.
16+
for n in $(_kubectl get no -o name | cut -d'/' -f2); do
17+
# Specify the service CIDR as an extra IP range that should be routable.
18+
$KGCTL_BINARY --kubeconfig "$KUBECONFIG" showconf node "$n" --as-peer -o yaml --allowed-ips 10.43.0.0/16 | $KUBECTL_BINARY --kubeconfig "$KUBECONFIG2" apply -f -
19+
done
20+
# Register the nodes in cluster2 as peers of cluster1.
21+
for n in $(KUBECONFIG=$KUBECONFIG2 _kubectl get no -o name | cut -d'/' -f2); do
22+
# Specify the service CIDR as an extra IP range that should be routable.
23+
$KGCTL_BINARY --kubeconfig "$KUBECONFIG2" showconf node "$n" --as-peer -o yaml --allowed-ips 10.45.0.0/16 | $KUBECTL_BINARY --kubeconfig "$KUBECONFIG" apply -f -
24+
done
25+
}
26+
27+
test_multi_cluster_pod_connectivity() {
28+
for ip in $(KUBECONFIG=$KUBECONFIG2 _kubectl get pods -l app.kubernetes.io/name=adjacency -o jsonpath='{.items[*].status.podIP}'); do
29+
assert_equals pong "$(retry 10 5 "$ip is not yet routable" curl_pod -m 1 -s http://"$ip":8080/ping)" "should be able to make HTTP request from cluster 1 to Pod in cluster 2"
30+
done
31+
for ip in $(_kubectl get pods -l app.kubernetes.io/name=adjacency -o jsonpath='{.items[*].status.podIP}'); do
32+
assert_equals pong "$(KUBECONFIG="$KUBECONFIG2" retry 10 5 "$ip is not yet routable" curl_pod -m 1 -s http://"$ip":8080/ping)" "should be able to make HTTP request from cluster 2 to Pod in cluster 1"
33+
done
34+
}
35+
36+
test_multi_cluster_service_connectivity() {
37+
# Mirror the Kubernetes API service from cluster1 into cluster2.
38+
cat <<EOF | $KUBECTL_BINARY --kubeconfig "$KUBECONFIG2" apply -f -
39+
apiVersion: v1
40+
kind: Service
41+
metadata:
42+
name: mirrored-kubernetes
43+
spec:
44+
ports:
45+
- port: 443
46+
---
47+
apiVersion: v1
48+
kind: Endpoints
49+
metadata:
50+
name: mirrored-kubernetes
51+
subsets:
52+
- addresses:
53+
- ip: $(_kubectl get service kubernetes -o jsonpath='{.spec.clusterIP}') # The cluster IP of the Kubernetes API service on cluster1.
54+
ports:
55+
- port: 443
56+
EOF
57+
assert_equals ok "$(KUBECONFIG="$KUBECONFIG2" retry 10 5 "service is not yet routable" curl_pod -m 1 -s -k https://mirrored-kubernetes/readyz)" "should be able to make HTTP request from cluster 2 to service in cluster 1"
58+
}
59+
60+
teardown_suite () {
61+
# Remove the nodes in cluster2 as peers of cluster1.
62+
for n in $(KUBECONFIG=$KUBECONFIG2 _kubectl get no -o name | cut -d'/' -f2); do
63+
_kubectl delete peer "$n"
64+
done
65+
KUBECONFIG=$KUBECONFIG2 KIND_CLUSTER=$KIND_CLUSTER2 delete_cluster
66+
}

0 commit comments

Comments
 (0)