Skip to content

Commit b660b9a

Browse files
authored
Extend integration test to support service import (#76)
1 parent 9e7aa13 commit b660b9a

File tree

5 files changed

+70
-8
lines changed

5 files changed

+70
-8
lines changed

integration/scripts/ensure-jq.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/usr/bin/env bash
2+
3+
# Ensure jq is available to parse json output. Installs jq on debian/ubuntu
4+
5+
if ! which -s jq ; then
6+
echo "jq not found, attempting to install"
7+
if ! sudo apt-get install -y jq ; then
8+
echo "failed to install jq, ensure it is available before running tests"
9+
exit 1
10+
fi
11+
fi
12+
13+
exit 0

integration/scripts/poll-endpoints.sh

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,15 @@ do
1515
fi
1616

1717
sleep 2s
18-
if ! addresses=$($KUBECTL_BIN describe endpoints --namespace "$NAMESPACE" | grep " Addresses: ")
18+
if ! addresses=$($KUBECTL_BIN get endpointslices -o json --namespace "$NAMESPACE" | \
19+
jq '.items[] | select(.metadata.ownerReferences[].name=="e2e-service") | .endpoints[].addresses[0]' 2> /dev/null)
1920
then
2021
# no endpoints ready
2122
continue
2223
fi
2324

24-
endpts=$(echo "$addresses" | tr -s " " | cut -f 3 -d " ")
25-
26-
endpt_count=$(echo "$endpts" | tr ',' '\n' | wc -l | xargs)
25+
endpt_count=$(echo "$addresses" | wc -l | xargs)
2726
done
2827

29-
echo "$endpts"
28+
echo "$addresses" | tr -d '"' | paste -sd "," -
3029
exit 0

integration/scripts/run-tests.sh

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,29 @@
22

33
# Runs the AWS Cloud Map MCS Controller for K8s as a background process and tests services have been exported
44

5-
set -eo pipefail
6-
75
source ./integration/scripts/common.sh
86

97
$KUBECTL_BIN apply -f "$CONFIGS/e2e-deployment.yaml"
108
$KUBECTL_BIN apply -f "$CONFIGS/e2e-service.yaml"
119
$KUBECTL_BIN apply -f "$CONFIGS/e2e-export.yaml"
1210

13-
endpts=$(./integration/scripts/poll-endpoints.sh "$EXPECTED_ENDPOINT_COUNT")
11+
if ! endpts=$(./integration/scripts/poll-endpoints.sh "$EXPECTED_ENDPOINT_COUNT") ; then
12+
exit $?
13+
fi
1414

1515
mkdir -p "$LOGS"
1616
./bin/manager &> "$LOGS/ctl.log" &
1717
CTL_PID=$!
18+
echo "controller PID:$CTL_PID"
1819

1920
go run $SCENARIOS/runner/main.go $NAMESPACE $SERVICE $ENDPT_PORT "$endpts"
21+
exit_code=$?
22+
23+
if [ "$exit_code" -eq 0 ] ; then
24+
./integration/scripts/test-import.sh "$endpts"
25+
exit_code=$?
26+
fi
2027

28+
echo "killing controller PID:$CTL_PID"
2129
kill $CTL_PID
30+
exit $exit_code

integration/scripts/setup-kind.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ set -e
77

88
source ./integration/scripts/common.sh
99

10+
./integration/scripts/ensure-jq.sh
11+
1012
$KIND_BIN create cluster --name "$KIND_SHORT" --image "$IMAGE"
1113
$KUBECTL_BIN config use-context "$CLUSTER"
1214
$KUBECTL_BIN create namespace "$NAMESPACE"

integration/scripts/test-import.sh

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#!/usr/bin/env bash
2+
3+
# Test service imports were created during e2e test
4+
5+
set -e
6+
7+
source ./integration/scripts/common.sh
8+
9+
if [ "$#" -ne 1 ]; then
10+
echo "test script expects endpoint IP list as single argument"
11+
exit 1
12+
fi
13+
14+
endpts=$1
15+
echo "checking service imports..."
16+
17+
imports=$($KUBECTL_BIN get endpointslices -o json --namespace $NAMESPACE | \
18+
jq '.items[] | select(.metadata.ownerReferences[].name | startswith("imported")) | .endpoints[].addresses[0]')
19+
import_count=$(echo "$imports" | wc -l | xargs)
20+
21+
if ((import_count != EXPECTED_ENDPOINT_COUNT)) ; then
22+
echo "expected $EXPECTED_ENDPOINT_COUNT imports but found $import_count"
23+
exit 1
24+
fi
25+
26+
echo "$imports" | tr -d '"' | while read -r import; do
27+
echo "checking import: $import"
28+
if ! echo "$endpts" | grep -q "$import" ; then
29+
echo "exported endpoint not found: $import"
30+
exit 1
31+
fi
32+
done
33+
34+
if [ $? -ne 0 ]; then
35+
exit $?
36+
fi
37+
38+
echo "matched all imports to exported endpoints"
39+
exit 0

0 commit comments

Comments
 (0)