Skip to content

Commit 597c233

Browse files
authored
Headless services local integration test (#194)
1 parent 8c2cb0e commit 597c233

18 files changed

+324
-36
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ kind-integration-setup: build kind ## Setup the integration test using kind clus
9494
@./integration/kind-test/scripts/setup-kind.sh
9595

9696
kind-integration-run: ## Run the integration test controller
97-
@./integration/kind-test/scripts/run-tests.sh
97+
@./integration/kind-test/scripts/run-helper.sh
9898

9999
kind-integration-cleanup: kind ## Cleanup integration test resources in Cloud Map and local kind cluster
100100
@./integration/kind-test/scripts/cleanup-kind.sh

integration/eks-test/scripts/eks-common.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ export SCENARIOS='./integration/shared/scenarios'
88
export NAMESPACE='aws-cloud-map-mcs-eks-e2e'
99
export MCS_NAMESPACE='cloud-map-mcs-system'
1010
export SERVICE='nginx-hello'
11+
export SERVICE_TYPE='ClusterSetIP'
1112
export CLIENT_POD='client-hello'
1213
export ENDPT_PORT=80
1314
export SERVICE_PORT=80 # from nginx-service.yaml

integration/eks-test/scripts/eks-run-tests.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ if ! endpts=$(./integration/shared/scripts/poll-endpoints.sh "$EXPECTED_ENDPOINT
1111
fi
1212

1313
# Runner to verify expected endpoints are exported to Cloud Map
14-
go run $SCENARIOS/runner/main.go $NAMESPACE $SERVICE $CLUSTERID1 $CLUSTERSETID1 $ENDPT_PORT $SERVICE_PORT "$endpts"
14+
go run $SCENARIOS/runner/main.go $NAMESPACE $SERVICE $CLUSTERID1 $CLUSTERSETID1 $ENDPT_PORT $SERVICE_PORT $SERVICE_TYPE "$endpts"
1515
exit_code=$?
1616

1717
# Check imported endpoints in importing cluster
@@ -47,7 +47,7 @@ if [ "$exit_code" -eq 0 ] ; then
4747
fi
4848

4949
if [ "$exit_code" -eq 0 ] ; then
50-
go run $SCENARIOS/runner/main.go $NAMESPACE $SERVICE $CLUSTERID1 $CLUSTERSETID1 $ENDPT_PORT $SERVICE_PORT "$updated_endpoints"
50+
go run $SCENARIOS/runner/main.go $NAMESPACE $SERVICE $CLUSTERID1 $CLUSTERSETID1 $ENDPT_PORT $SERVICE_PORT $SERVICE_TYPE "$updated_endpoints"
5151
exit_code=$?
5252
fi
5353

integration/eks-test/scripts/eks-setup.sh

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,17 @@
22

33
source ./integration/eks-test/scripts/eks-common.sh
44

5+
# Call helper for service account and controller installation
6+
./integration/eks-test/scripts/eks-setup-helper.sh $EXPORT_CLS
7+
./integration/eks-test/scripts/eks-setup-helper.sh $IMPORT_CLS
8+
59
# Apply ClusterProperties
610
$KUBECTL_BIN config use-context $EXPORT_CLS
7-
make install
811
$KUBECTL_BIN apply -f "$CONFIGS/e2e-clusterproperty-1.yaml"
912

1013
$KUBECTL_BIN config use-context $IMPORT_CLS
11-
make install
1214
$KUBECTL_BIN apply -f "$CONFIGS/e2e-clusterproperty-2.yaml"
1315

14-
# Call helper for service account and controller installation
15-
./integration/eks-test/scripts/eks-setup-helper.sh $EXPORT_CLS
16-
./integration/eks-test/scripts/eks-setup-helper.sh $IMPORT_CLS
17-
1816
# Installing service
1917
$KUBECTL_BIN config use-context $EXPORT_CLS
2018
$KUBECTL_BIN create namespace $NAMESPACE
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
apiVersion: v1
2+
kind: Pod
3+
metadata:
4+
name: client-hello
5+
namespace: aws-cloud-map-mcs-e2e
6+
spec:
7+
containers:
8+
- command:
9+
- sleep
10+
- "1d"
11+
image: alpine
12+
name: client-hello
Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
apiVersion: apps/v1
2+
kind: Deployment
3+
metadata:
4+
labels:
5+
# eks.amazonaws.com/component: coredns
6+
k8s-app: kube-dns
7+
kubernetes.io/name: CoreDNS
8+
name: coredns
9+
namespace: kube-system
10+
spec:
11+
progressDeadlineSeconds: 600
12+
replicas: 2
13+
revisionHistoryLimit: 10
14+
selector:
15+
matchLabels:
16+
# eks.amazonaws.com/component: coredns
17+
k8s-app: kube-dns
18+
strategy:
19+
rollingUpdate:
20+
maxSurge: 25%
21+
maxUnavailable: 1
22+
type: RollingUpdate
23+
template:
24+
metadata:
25+
# annotations:
26+
# eks.amazonaws.com/compute-type: ec2
27+
creationTimestamp: null
28+
labels:
29+
# eks.amazonaws.com/component: coredns
30+
k8s-app: kube-dns
31+
spec:
32+
affinity:
33+
nodeAffinity:
34+
requiredDuringSchedulingIgnoredDuringExecution:
35+
nodeSelectorTerms:
36+
- matchExpressions:
37+
- key: beta.kubernetes.io/os
38+
operator: In
39+
values:
40+
- linux
41+
- key: beta.kubernetes.io/arch
42+
operator: In
43+
values:
44+
- amd64
45+
- arm64
46+
podAntiAffinity:
47+
preferredDuringSchedulingIgnoredDuringExecution:
48+
- podAffinityTerm:
49+
labelSelector:
50+
matchExpressions:
51+
- key: k8s-app
52+
operator: In
53+
values:
54+
- kube-dns
55+
topologyKey: kubernetes.io/hostname
56+
weight: 100
57+
containers:
58+
- args:
59+
- -conf
60+
- /etc/coredns/Corefile
61+
image: ghcr.io/aws/aws-cloud-map-mcs-controller-for-k8s/coredns-multicluster/coredns:v1.8.4
62+
imagePullPolicy: IfNotPresent
63+
livenessProbe:
64+
failureThreshold: 5
65+
httpGet:
66+
path: /health
67+
port: 8080
68+
scheme: HTTP
69+
initialDelaySeconds: 60
70+
periodSeconds: 10
71+
successThreshold: 1
72+
timeoutSeconds: 5
73+
name: coredns
74+
ports:
75+
- containerPort: 53
76+
name: dns
77+
protocol: UDP
78+
- containerPort: 53
79+
name: dns-tcp
80+
protocol: TCP
81+
- containerPort: 9153
82+
name: metrics
83+
protocol: TCP
84+
readinessProbe:
85+
failureThreshold: 3
86+
httpGet:
87+
path: /health
88+
port: 8080
89+
scheme: HTTP
90+
periodSeconds: 10
91+
successThreshold: 1
92+
timeoutSeconds: 1
93+
resources:
94+
limits:
95+
memory: 170Mi
96+
requests:
97+
cpu: 100m
98+
memory: 70Mi
99+
securityContext:
100+
allowPrivilegeEscalation: false
101+
capabilities:
102+
add:
103+
- NET_BIND_SERVICE
104+
drop:
105+
- all
106+
readOnlyRootFilesystem: true
107+
terminationMessagePath: /dev/termination-log
108+
terminationMessagePolicy: File
109+
volumeMounts:
110+
- mountPath: /etc/coredns
111+
name: config-volume
112+
readOnly: true
113+
- mountPath: /tmp
114+
name: tmp
115+
dnsPolicy: Default
116+
priorityClassName: system-cluster-critical
117+
restartPolicy: Always
118+
schedulerName: default-scheduler
119+
securityContext: {}
120+
serviceAccount: coredns
121+
serviceAccountName: coredns
122+
terminationGracePeriodSeconds: 30
123+
tolerations:
124+
- effect: NoSchedule
125+
key: node-role.kubernetes.io/master
126+
- key: CriticalAddonsOnly
127+
operator: Exists
128+
volumes:
129+
- emptyDir: {}
130+
name: tmp
131+
- configMap:
132+
defaultMode: 420
133+
items:
134+
- key: Corefile
135+
path: Corefile
136+
name: coredns
137+
name: config-volume
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
kind: ServiceExport
2+
apiVersion: multicluster.x-k8s.io/v1alpha1
3+
metadata:
4+
namespace: aws-cloud-map-mcs-e2e
5+
name: e2e-headless
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
kind: Service
2+
apiVersion: v1
3+
metadata:
4+
namespace: aws-cloud-map-mcs-e2e
5+
name: e2e-headless
6+
spec:
7+
clusterIP: None
8+
selector:
9+
app: coredns
10+
ports:
11+
- port: 8080
12+
targetPort: 80
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
#!/usr/bin/env bash
2+
3+
# Testing service consumption with dnsutils pod
4+
5+
echo "verifying single-cluster service consumption..."
6+
7+
# Helper function to verify DNS results
8+
checkDNS() {
9+
endpt_count=$(echo "$1" | wc -l | xargs)
10+
11+
if [ "$2" = "Headless" ]; then
12+
if [ "$endpt_count" -ne "$3" ]; then
13+
echo "ERROR: Found $endpt_count endpoints, expected $3 endpoints"
14+
exit 1
15+
fi
16+
fi
17+
18+
if [ "$2" = "ClusterSetIP" ]; then
19+
if [ "$endpt_count" -ne 1 ]; then
20+
echo "ERROR: Found $endpt_count endpoints, expected 1 endpoint"
21+
exit 1
22+
fi
23+
fi
24+
}
25+
26+
# Add pod
27+
$KUBECTL_BIN apply -f "$KIND_CONFIGS/e2e-client-hello.yaml"
28+
$KUBECTL_BIN wait --for=condition=ready pod/$DNS_POD -n $NAMESPACE # wait until pod is deployed
29+
30+
# Install dig if not installed
31+
$KUBECTL_BIN exec $DNS_POD -n $NAMESPACE -- dig -v &>/dev/null
32+
exit_code=$?
33+
if [ "$exit_code" -ne 0 ]; then
34+
echo "dig not installed, installing..."
35+
$KUBECTL_BIN exec $DNS_POD -n $NAMESPACE -- apk add --update bind-tools
36+
fi
37+
38+
# Perform a dig to cluster-local CoreDNS
39+
# TODO: parse dig outputs for more precise verification - check specifics IPs?
40+
echo "performing dig for A/AAAA records..."
41+
addresses=$($KUBECTL_BIN exec $DNS_POD -n $NAMESPACE -- dig +all +ans $SERVICE.$NAMESPACE.svc.clusterset.local +short)
42+
exit_code=$?
43+
echo "$addresses"
44+
45+
if [ "$exit_code" -ne 0 ]; then
46+
echo "ERROR: Unable to dig service $SERVICE.$NAMESPACE.svc.clusterset.local"
47+
exit $exit_code
48+
fi
49+
50+
# verify DNS results
51+
checkDNS "$addresses" "$SERVICE_TYPE" "$1"
52+
53+
echo "performing dig for SRV records..."
54+
addresses=$($KUBECTL_BIN exec $DNS_POD -n $NAMESPACE -- dig +all +ans $SERVICE.$NAMESPACE.svc.clusterset.local. SRV +short)
55+
exit_code=$?
56+
echo "$addresses"
57+
58+
if [ "$exit_code" -ne 0 ]; then
59+
echo "ERROR: Unable to dig service $SERVICE.$NAMESPACE.svc.clusterset.local"
60+
exit $exit_code
61+
fi
62+
63+
# verify DNS results
64+
checkDNS "$addresses" "$SERVICE_TYPE" "$1"
65+
66+
echo "confirmed service consumption"
67+
exit 0

integration/kind-test/scripts/common.sh

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,19 @@
33
export KIND_BIN='./bin/kind'
44
export KUBECTL_BIN='kubectl'
55
export LOGS='./integration/kind-test/testlog'
6-
export CONFIGS='./integration/kind-test/configs'
6+
export KIND_CONFIGS='./integration/kind-test/configs'
7+
export SHARED_CONFIGS='./integration/shared/configs'
78
export SCENARIOS='./integration/shared/scenarios'
89
export NAMESPACE='aws-cloud-map-mcs-e2e'
9-
export SERVICE='e2e-service'
1010
export ENDPT_PORT=80
1111
export SERVICE_PORT=8080
12+
export CLUSTERIP_SERVICE='e2e-service'
13+
export HEADLESS_SERVICE='e2e-headless'
1214
export KIND_SHORT='cloud-map-e2e'
1315
export CLUSTER='kind-cloud-map-e2e'
1416
export CLUSTERID1='kind-e2e-clusterid-1'
1517
export CLUSTERSETID1='kind-e2e-clustersetid-1'
16-
export IMAGE='kindest/node:v1.20.15@sha256:a6ce604504db064c5e25921c6c0fffea64507109a1f2a512b1b562ac37d652f3'
18+
export DNS_POD='client-hello'
19+
export IMAGE='kindest/node:v1.21.12@sha256:f316b33dd88f8196379f38feb80545ef3ed44d9197dca1bfd48bcb1583210207'
1720
export EXPECTED_ENDPOINT_COUNT=5
1821
export UPDATED_ENDPOINT_COUNT=6

0 commit comments

Comments
 (0)