Skip to content
This repository was archived by the owner on Sep 30, 2020. It is now read-only.

Commit 8d6d0a4

Browse files
committed
feat(test): cd e2e && ./run all to run e2e tests for kube-aws
1 parent e90609d commit 8d6d0a4

File tree

3 files changed

+200
-0
lines changed

3 files changed

+200
-0
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@
44
*~
55
/config/templates.go
66
.idea/
7+
.envrc

e2e/README.md

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# End-to-end testing for kube-aws
2+
3+
This directory contains a set of tools to run end-to-end testing for kube-aws.
4+
It is composed of:
5+
6+
* Cluster creation using `kube-aws`
7+
* [Kubernetes Conformance Tests](https://github.com/kubernetes/kubernetes/blob/master/docs/devel/e2e-tests.md#conformance-tests)
8+
9+
To run e2e tests, you should have set all he required env vars.
10+
For convenience, creating `.envrc` used by `direnv` like as follows would be good.
11+
12+
```
13+
export KUBE_AWS_KEY_NAME=...
14+
export KUBE_AWS_KMS_KEY_ARN=arn:aws:kms:us-west-1:<account id>:key/<id>
15+
export KUBE_AWS_DOMAIN=example.com
16+
export KUBE_AWS_REGION=us-west-1
17+
export KUBE_AWS_AVAILABILITY_ZONE=us-west-1b
18+
export KUBE_AWS_HOSTED_ZONE_ID=...
19+
20+
export DOCKER_REPO=quay.io/mumoshu/
21+
export SSH_PRIVATE_KEY=path/to/private/key/matching/key/name
22+
```
23+
24+
Finally, run e2e tests like:
25+
26+
```
27+
$ KUBE_AWS_CLUSTER_NAME=kubeawstest ./run all
28+
```

e2e/run

+171
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,171 @@
1+
#!/bin/bash
2+
3+
KUBE_AWS_CMD=${KUBE_AWS_CMD:-$GOPATH/src/github.com/coreos/kube-aws/bin/kube-aws}
4+
E2E_DIR=$(cd $(dirname $0); pwd)
5+
WORK_DIR=${E2E_DIR}/assets/${KUBE_AWS_CLUSTER_NAME}
6+
KUBECONFIG=${WORK_DIR}/kubeconfig
7+
8+
export KUBECONFIG
9+
10+
USAGE_EXAMPLE="KUBE_AWS_CLUSTER_NAME=kubeawstest1 KUBE_AWS_KEY_NAME=name/of/ec2/key KUBE_AWS_KMS_KEY_ARN=arn:aws:kms:us-west-1:<account id>:key/your-key KUBE_AWS_REGION=us-west-1 KUBE_AWS_AVAILABILITY_ZONE=us-west-1b ./$0 [prepare|configure|start|all]"
11+
12+
if [ "${KUBE_AWS_CLUSTER_NAME}" == "" ]; then
13+
echo KUBE_AWS_CLUSTER_NAME is not set. Run this command like $USAGE_EXAMPLE 1>&2
14+
exit 1
15+
fi
16+
17+
if [ "${KUBE_AWS_KEY_NAME}" == "" ]; then
18+
echo KUBE_AWS_KEY_NAME is not set. Run this command like $USAGE_EXAMPLE 1>&2
19+
exit 1
20+
fi
21+
22+
if [ "${KUBE_AWS_REGION}" == "" ]; then
23+
echo KUBE_AWS_REGION is not set. Run this command like $USAGE_EXAMPLE 1>&2
24+
exit 1
25+
fi
26+
27+
if [ "${KUBE_AWS_AVAILABILITY_ZONE}" == "" ]; then
28+
echo KUBE_AWS_REGION is not set. Run this command like $USAGE_EXAMPLE 1>&2
29+
exit 1
30+
fi
31+
32+
if [ ! -e "${KUBE_AWS_CMD}" ]; then
33+
echo ${KUBE_AWS_CMD} does not exist. 1>&2
34+
exit 1
35+
fi
36+
37+
KUBE_AWS_VERSION=$($KUBE_AWS_CMD version)
38+
echo Using the kube-aws command at ${KUBE_AWS_CMD}"($KUBE_AWS_VERSION)". Set KUBE_AWS_CMD=path/to/kube-aws to override.
39+
40+
EXTERNAL_DNS_NAME=${KUBE_AWS_CLUSTER_NAME}.${KUBE_AWS_DOMAIN}
41+
echo The kubernetes API would be accessible via ${EXTERNAL_DNS_NAME}
42+
43+
prepare() {
44+
echo Creating or ensuring existence of the kube-aws assets directory ${WORK_DIR}
45+
mkdir -p ${WORK_DIR}
46+
}
47+
48+
configure() {
49+
cd ${WORK_DIR}
50+
51+
${KUBE_AWS_CMD} init \
52+
--cluster-name ${KUBE_AWS_CLUSTER_NAME} \
53+
--external-dns-name ${EXTERNAL_DNS_NAME} \
54+
--region ${KUBE_AWS_REGION} \
55+
--availability-zone ${KUBE_AWS_AVAILABILITY_ZONE} \
56+
--key-name ${KUBE_AWS_KEY_NAME} \
57+
--kms-key-arn ${KUBE_AWS_KMS_KEY_ARN}
58+
59+
echo "hostedZoneId: ${KUBE_AWS_HOSTED_ZONE_ID}" >> cluster.yaml
60+
echo 'createRecordSet: true' >> cluster.yaml
61+
62+
# required to run kube-aws update
63+
echo 'workerCount: 4' >> cluster.yaml
64+
echo 'controllerCount: 2' >> cluster.yaml
65+
66+
${KUBE_AWS_CMD} render
67+
68+
${KUBE_AWS_CMD} validate
69+
70+
echo Generated configuration files in ${WORK_DIR}:
71+
find .
72+
}
73+
74+
clean() {
75+
cd ${WORK_DIR}/..
76+
if [ -d "${KUBE_AWS_CLUSTER_NAME}" ]; then
77+
echo Removing the directory "${WORK_DIR}"
78+
rm -Rf ./${KUBE_AWS_CLUSTER_NAME}/*
79+
fi
80+
}
81+
82+
up() {
83+
cd ${WORK_DIR}
84+
85+
${KUBE_AWS_CMD} up
86+
87+
printf 'Waiting for the Kubernetes API to be accessible'
88+
89+
while ! kubectl get no 2>/dev/null; do
90+
sleep 10
91+
printf '.'
92+
done
93+
echo done
94+
}
95+
96+
destroy() {
97+
aws cloudformation delete-stack --stack-name ${KUBE_AWS_CLUSTER_NAME}
98+
aws cloudformation wait stack-delete-complete --stack-name ${KUBE_AWS_CLUSTER_NAME}
99+
}
100+
101+
test-upgrade() {
102+
SED_CMD="sed -e 's/workerCount: 2/workerCount: 4/' -e 's/controllerCount: 2/controllerCount: 3/'"
103+
diff --unified cluster.yaml <(cat cluster.yaml | sh -c "${SED_CMD}")
104+
sh -c "${SED_CMD} -i bak cluster.yaml"
105+
${KUBE_AWS_CMD} update
106+
aws cloudformation wait stack-update-complete --stack-name ${KUBE_AWS_CLUSTER_NAME}
107+
}
108+
109+
test-destruction() {
110+
aws cloudformation wait stack-delete-complete --stack-name ${KUBE_AWS_CLUSTER_NAME}
111+
}
112+
113+
# Usage: DOCKER_REPO=quay.io/mumoshu/ SSH_PRIVATE_KEY=path/to/private/key ./e2e run conformance
114+
conformance() {
115+
cd ${E2E_DIR}/kubernetes
116+
117+
if [ "$DOCKER_REPO" == "" ]; then
118+
echo DOCKER_REPO is not set.
119+
exit 1
120+
fi
121+
122+
if [ "$SSH_PRIVATE_KEY" == "" ]; then
123+
echo SSH_PRIVATE_KEY is not set.
124+
exit 1
125+
fi
126+
127+
if [ ! -f "$SSH_PRIVATE_KEY" ]; then
128+
echo ${SSH_PRIVATE_KEY} does not exist.
129+
exit 1
130+
fi
131+
132+
master_host=$(aws ec2 describe-instances --output json --query "Reservations[].Instances[]
133+
| [?Tags[?Key==\`aws:cloudformation:stack-name\`].Value|[0]==\`${KUBE_AWS_CLUSTER_NAME}\`]
134+
| [?Tags[?Key==\`aws:cloudformation:logical-id\`].Value|[0]==\`AutoScaleController\`][]
135+
| []" | jq -r 'map({InstanceId: .InstanceId, PublicIpAddress: .PublicIpAddress}) | first | .PublicIpAddress'
136+
)
137+
138+
echo Connecting to $master_host via SSH
139+
140+
KUBE_AWS_ASSETS=${WORK_DIR} MASTER_HOST=$master_host make run-remotely
141+
}
142+
143+
conformance_result() {
144+
cd ${E2E_DIR}/kubernetes
145+
146+
master_host=$(aws ec2 describe-instances --output json --query "Reservations[].Instances[]
147+
| [?Tags[?Key==\`aws:cloudformation:stack-name\`].Value|[0]==\`${KUBE_AWS_CLUSTER_NAME}\`]
148+
| [?Tags[?Key==\`aws:cloudformation:logical-id\`].Value|[0]==\`AutoScaleController\`][]
149+
| []" | jq -r 'map({InstanceId: .InstanceId, PublicIpAddress: .PublicIpAddress}) | first | .PublicIpAddress'
150+
)
151+
152+
echo Connecting to $master_host via SSH
153+
154+
KUBE_AWS_ASSETS=${WORK_DIR} MASTER_HOST=$master_host make show-log
155+
}
156+
157+
all() {
158+
prepare
159+
configure
160+
up
161+
conformance
162+
}
163+
164+
if [ "$1" == "" ]; then
165+
echo Usage: $USAGE_EXAMPLE
166+
exit 1
167+
fi
168+
169+
set -vxe
170+
171+
"$@"

0 commit comments

Comments
 (0)