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

Commit 683273d

Browse files
authored
Merge pull request #167 from aaronlevy/gce-conformance
tests: add GCE based conformance test scripts
2 parents db833d4 + c3a0e6e commit 683273d

File tree

5 files changed

+130
-30
lines changed

5 files changed

+130
-30
lines changed

hack/quickstart/init-master.sh

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ REMOTE_HOST=$1
55
REMOTE_PORT=${REMOTE_PORT:-22}
66
CLUSTER_DIR=${CLUSTER_DIR:-cluster}
77
IDENT=${IDENT:-${HOME}/.ssh/id_rsa}
8+
SSH_OPTS=${SSH_OPTS:-}
89

910
BOOTKUBE_REPO=quay.io/coreos/bootkube
1011
BOOTKUBE_VERSION=v0.2.4
@@ -105,19 +106,19 @@ function init_master_node() {
105106
# After assets are available on the remote host, the script will execute itself in "local" mode.
106107
if [ "${REMOTE_HOST}" != "local" ]; then
107108
# Set up the kubelet.service on remote host
108-
scp -i ${IDENT} -P ${REMOTE_PORT} kubelet.master core@${REMOTE_HOST}:/home/core/kubelet.master
109-
ssh -i ${IDENT} -p ${REMOTE_PORT} core@${REMOTE_HOST} "sudo mv /home/core/kubelet.master /etc/systemd/system/kubelet.service"
109+
scp -i ${IDENT} -P ${REMOTE_PORT} ${SSH_OPTS} kubelet.master core@${REMOTE_HOST}:/home/core/kubelet.master
110+
ssh -i ${IDENT} -p ${REMOTE_PORT} ${SSH_OPTS} core@${REMOTE_HOST} "sudo mv /home/core/kubelet.master /etc/systemd/system/kubelet.service"
110111

111112
# Copy self to remote host so script can be executed in "local" mode
112-
scp -i ${IDENT} -P ${REMOTE_PORT} ${BASH_SOURCE[0]} core@${REMOTE_HOST}:/home/core/init-master.sh
113-
ssh -i ${IDENT} -p ${REMOTE_PORT} core@${REMOTE_HOST} "sudo /home/core/init-master.sh local"
113+
scp -i ${IDENT} -P ${REMOTE_PORT} ${SSH_OPTS} ${BASH_SOURCE[0]} core@${REMOTE_HOST}:/home/core/init-master.sh
114+
ssh -i ${IDENT} -p ${REMOTE_PORT} ${SSH_OPTS} core@${REMOTE_HOST} "sudo /home/core/init-master.sh local"
114115

115116
# Copy assets from remote host to a local directory. These can be used to launch additional nodes & contain TLS assets
116117
mkdir ${CLUSTER_DIR}
117-
scp -q -i ${IDENT} -P ${REMOTE_PORT} -r core@${REMOTE_HOST}:/home/core/assets/* ${CLUSTER_DIR}
118+
scp -q -i ${IDENT} -P ${REMOTE_PORT} ${SSH_OPTS} -r core@${REMOTE_HOST}:/home/core/assets/* ${CLUSTER_DIR}
118119

119120
# Cleanup
120-
ssh -i ${IDENT} -p ${REMOTE_PORT} core@${REMOTE_HOST} "rm -rf /home/core/assets && rm -rf /home/core/init-master.sh"
121+
ssh -i ${IDENT} -p ${REMOTE_PORT} ${SSH_OPTS} core@${REMOTE_HOST} "rm -rf /home/core/assets && rm -rf /home/core/init-master.sh"
121122

122123
echo "Cluster assets copied to ${CLUSTER_DIR}"
123124
echo

hack/quickstart/init-worker.sh

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ REMOTE_HOST=$1
55
KUBECONFIG=$2
66
REMOTE_PORT=${REMOTE_PORT:-22}
77
IDENT=${IDENT:-${HOME}/.ssh/id_rsa}
8+
SSH_OPTS=${SSH_OPTS:-}
89

910
function usage() {
1011
echo "USAGE:"
@@ -34,7 +35,9 @@ function extract_master_endpoint (){
3435
grep 'client-key-data' ${KUBECONFIG} | awk '{print $2}'| base64 -d > /home/core/client.key
3536

3637
MASTER_PUB="$(awk '/server:/ {print $2}' ${KUBECONFIG} | awk -F/ '{print $3}' | awk -F: '{print $1}')"
37-
MASTER_PRIV=$(curl https://${MASTER_PUB}:443/api/v1/namespaces/default/endpoints/kubernetes \
38+
# TODO (aaron): The -k was added with the gce conformance tests - figure out why it's needed here.
39+
# The certs are seemingly signed correctly, but says no SAN for MASTER_PUB
40+
MASTER_PRIV=$(curl -k https://${MASTER_PUB}:443/api/v1/namespaces/default/endpoints/kubernetes \
3841
--cacert /home/core/ca.crt --cert /home/core/client.crt --key /home/core/client.key \
3942
| jq -r '.subsets[0].addresses[0].ip')
4043
rm -f /home/core/ca.crt /home/core/client.crt /home/core/client.key
@@ -66,15 +69,15 @@ function init_worker_node() {
6669
if [ "${REMOTE_HOST}" != "local" ]; then
6770

6871
# Copy kubelet service file and kubeconfig to remote host
69-
scp -i ${IDENT} -P ${REMOTE_PORT} kubelet.worker core@${REMOTE_HOST}:/home/core/kubelet.worker
70-
scp -i ${IDENT} -P ${REMOTE_PORT} ${KUBECONFIG} core@${REMOTE_HOST}:/home/core/kubeconfig
72+
scp -i ${IDENT} -P ${REMOTE_PORT} ${SSH_OPTS} kubelet.worker core@${REMOTE_HOST}:/home/core/kubelet.worker
73+
scp -i ${IDENT} -P ${REMOTE_PORT} ${SSH_OPTS} ${KUBECONFIG} core@${REMOTE_HOST}:/home/core/kubeconfig
7174

7275
# Copy self to remote host so script can be executed in "local" mode
73-
scp -i ${IDENT} -P ${REMOTE_PORT} ${BASH_SOURCE[0]} core@${REMOTE_HOST}:/home/core/init-worker.sh
74-
ssh -i ${IDENT} -p ${REMOTE_PORT} core@${REMOTE_HOST} "sudo /home/core/init-worker.sh local /home/core/kubeconfig"
76+
scp -i ${IDENT} -P ${REMOTE_PORT} ${SSH_OPTS} ${BASH_SOURCE[0]} core@${REMOTE_HOST}:/home/core/init-worker.sh
77+
ssh -i ${IDENT} -p ${REMOTE_PORT} ${SSH_OPTS} core@${REMOTE_HOST} "sudo /home/core/init-worker.sh local /home/core/kubeconfig"
7578

7679
# Cleanup
77-
ssh -i ${IDENT} -p ${REMOTE_PORT} core@${REMOTE_HOST} "rm /home/core/init-worker.sh"
80+
ssh -i ${IDENT} -p ${REMOTE_PORT} ${SSH_OPTS} core@${REMOTE_HOST} "rm /home/core/init-worker.sh"
7881

7982
echo
8083
echo "Node bootstrap complete. It may take a few minutes for the node to become ready. Access your kubernetes cluster using:"

hack/single-node/conformance-test.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,4 @@ set -euo pipefail
44
ssh_key="$(vagrant ssh-config | awk '/IdentityFile/ {print $2}' | tr -d '"')"
55
ssh_port="$(vagrant ssh-config | awk '/Port [0-9]+/ {print $2}')"
66

7-
export CHECK_NODE_COUNT=false
87
../tests/conformance-test.sh "127.0.0.1" "${ssh_port}" "${ssh_key}"

hack/tests/conformance-gce.sh

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
#!/bin/bash
2+
set -euo pipefail
3+
4+
# DESCRIPTION:
5+
#
6+
# This script is meant to launch GCE nodes, run bootkube to bootstrap a self-hosted k8s cluster, then run conformance tests.
7+
#
8+
# REQUIREMENTS:
9+
# - gcloud cli is installed
10+
# - rkt is available on the host
11+
# - $BUILD_ROOT environment variable is set and contains a checkout of bootkube at $BUILD_ROOT/bootkube
12+
# - $KEY_FILE environment variable is set as path to GCE service account keyfile
13+
#
14+
# PROCESS:
15+
#
16+
# Inside a rkt container:
17+
# - Use gcloud to launch master node
18+
# - Use the quickstart init-master.sh script to run bootkube on that node
19+
# - Use gcloud to launch worker node(s)
20+
# - Use the quickstart init-worker.sh script to join node to kubernetes cluster
21+
# - Run conformance tests against the launched cluster
22+
#
23+
WORKER_COUNT=4
24+
COREOS_IMAGE=${COREOS_IMAGE:-'https://www.googleapis.com/compute/v1/projects/coreos-cloud/global/images/coreos-stable-1122-2-0-v20160906'}
25+
26+
function cleanup {
27+
gcloud compute instances delete --quiet --zone us-central1-a bootkube-ci-m1 || true
28+
gcloud compute firewall-rules delete --quiet bootkube-ci-api-443 || true
29+
for i in $(seq 1 ${WORKER_COUNT}); do
30+
gcloud compute instances delete --quiet --zone us-central1-a bootkube-ci-w${i} || true
31+
done
32+
rm -rf /build/cluster
33+
}
34+
35+
function init {
36+
curl https://sdk.cloud.google.com | bash
37+
source ~/.bashrc
38+
gcloud config set project coreos-gce-testing
39+
gcloud auth activate-service-account [email protected] --key-file=/build/keyfile
40+
apt-get update && apt-get install -y jq
41+
42+
ssh-keygen -t rsa -f /root/.ssh/id_rsa -N ""
43+
awk '{print "core:" $1 " " $2 " core@bootkube-ci"}' /root/.ssh/id_rsa.pub > /root/.ssh/gce-format.pub
44+
}
45+
46+
function add_master {
47+
gcloud compute instances create bootkube-ci-m1 \
48+
--image ${COREOS_IMAGE} --zone us-central1-a --machine-type n1-standard-4 --boot-disk-size=10GB
49+
50+
gcloud compute instances add-tags --zone us-central1-a bootkube-ci-m1 --tags bootkube-ci-apiserver
51+
gcloud compute firewall-rules create bootkube-ci-api-443 --target-tags=bootkube-ci-apiserver --allow tcp:443
52+
53+
gcloud compute instances add-metadata bootkube-ci-m1 --zone us-central1-a --metadata-from-file ssh-keys=/root/.ssh/gce-format.pub
54+
55+
MASTER_IP=$(gcloud compute instances list bootkube-ci-m1 --format=json | jq --raw-output '.[].networkInterfaces[].accessConfigs[].natIP')
56+
cd /build/bootkube/hack/quickstart && SSH_OPTS="-o StrictHostKeyChecking=no" CLUSTER_DIR=/build/cluster ./init-master.sh ${MASTER_IP}
57+
}
58+
59+
function add_workers {
60+
#TODO (aaron): parallelize launching workers
61+
for i in $(seq 1 ${WORKER_COUNT}); do
62+
gcloud compute instances create bootkube-ci-w${i} \
63+
--image ${COREOS_IMAGE} --zone us-central1-a --machine-type n1-standard-1
64+
65+
gcloud compute instances add-metadata bootkube-ci-w${i} --zone us-central1-a --metadata-from-file ssh-keys=/root/.ssh/gce-format.pub
66+
67+
local WORKER_IP=$(gcloud compute instances list bootkube-ci-w${i} --format=json | jq --raw-output '.[].networkInterfaces[].accessConfigs[].natIP')
68+
cd /build/bootkube/hack/quickstart && SSH_OPTS="-o StrictHostKeyChecking=no" ./init-worker.sh ${WORKER_IP} /build/cluster/auth/kubeconfig
69+
done
70+
}
71+
72+
IN_CONTAINER=${IN_CONTAINER:-false}
73+
if [ "${IN_CONTAINER}" == true ]; then
74+
#TODO(aaron): should probably run cleanup as part of init (not just on exit). Or add some random identifier to objects created during this run.
75+
trap cleanup EXIT
76+
init
77+
add_master
78+
add_workers
79+
KUBECONFIG=/etc/kubernetes/kubeconfig WORKER_COUNT=${WORKER_COUNT} /build/bootkube/hack/tests/conformance-test.sh ${MASTER_IP} 22 /root/.ssh/id_rsa
80+
else
81+
BUILD_ROOT=${BUILD_ROOT:-}
82+
if [ -z "$BUILD_ROOT" ]; then
83+
echo "BUILD_ROOT must be set"
84+
exit 1
85+
fi
86+
if [ -z "$KEY_FILE" ]; then
87+
echo "KEY_FILE must be set"
88+
exit 1
89+
fi
90+
91+
RKT_OPTS=$(echo \
92+
"--volume buildroot,kind=host,source=${BUILD_ROOT} " \
93+
"--mount volume=buildroot,target=/build " \
94+
"--volume keyfile,kind=host,source=${KEY_FILE} " \
95+
"--mount volume=keyfile,target=/build/keyfile " \
96+
)
97+
98+
sudo rkt run --insecure-options=image ${RKT_OPTS} docker://golang:1.6.3 --exec /bin/bash -- -c "IN_CONTAINER=true /build/bootkube/hack/tests/$(basename $0)"
99+
fi

hack/tests/conformance-test.sh

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
#!/bin/bash
22
set -euo pipefail
33

4-
CHECK_NODE_COUNT=${CHECK_NODE_COUNT:-true}
54
CONFORMANCE_REPO=${CONFORMANCE_REPO:-github.com/coreos/kubernetes}
65
CONFORMANCE_VERSION=${CONFORMANCE_VERSION:-v1.4.5+coreos.0}
7-
TEST_ARGS=${TEST_ARGS:-"--ginkgo.focus='\[Conformance\]' --ginkgo.skip='\[Flaky\]|\[Feature:.+\]'"}
86

97
usage() {
108
echo "USAGE:"
@@ -22,29 +20,29 @@ ssh_host=$1
2220
ssh_port=$2
2321
ssh_key=$3
2422

23+
KUBECONFIG=${KUBECONFIG:-/home/core/cluster/auth/kubeconfig}
2524
K8S_SRC=/home/core/go/src/k8s.io/kubernetes
2625
ssh -q -o stricthostkeychecking=no -i ${ssh_key} -p ${ssh_port} core@${ssh_host} \
2726
"mkdir -p ${K8S_SRC} && [[ -d ${K8S_SRC}/.git ]] || git clone https://${CONFORMANCE_REPO} ${K8S_SRC}"
2827

29-
RKT_OPTS=$(echo \
30-
"--volume=kc,kind=host,source=/home/core/cluster/auth/kubeconfig "\
31-
"--volume=k8s,kind=host,source=${K8S_SRC} " \
32-
"--mount volume=kc,target=/kubeconfig " \
33-
"--mount volume=k8s,target=/go/src/k8s.io/kubernetes")
28+
RKT_OPTS="\
29+
--volume=kc,kind=host,source=${KUBECONFIG} \
30+
--volume=k8s,kind=host,source=${K8S_SRC} \
31+
--mount volume=kc,target=/kubeconfig \
32+
--mount volume=k8s,target=/go/src/k8s.io/kubernetes"
3433

3534
# Init steps necessary to run conformance in golang container
3635
INIT="apt-get update && apt-get install -y rsync && go get -u github.com/jteeuwen/go-bindata/go-bindata"
3736

38-
TEST_FLAGS="-v --test -check_version_skew=false -check_node_count=${CHECK_NODE_COUNT} --test_args=\"${TEST_ARGS}\""
37+
BUILD="cd /go/src/k8s.io/kubernetes && \
38+
git checkout ${CONFORMANCE_VERSION} && \
39+
make all WHAT=cmd/kubectl && \
40+
make all WHAT=vendor/github.com/onsi/ginkgo/ginkgo && \
41+
make all WHAT=test/e2e/e2e.test"
3942

40-
CONFORMANCE=$(echo \
41-
"cd /go/src/k8s.io/kubernetes && " \
42-
"git checkout ${CONFORMANCE_VERSION} && " \
43-
"make all WHAT=cmd/kubectl && " \
44-
"make all WHAT=vendor/github.com/onsi/ginkgo/ginkgo && " \
45-
"make all WHAT=test/e2e/e2e.test && " \
46-
"KUBECONFIG=/kubeconfig KUBERNETES_PROVIDER=skeleton KUBERNETES_CONFORMANCE_TEST=Y go run hack/e2e.go ${TEST_FLAGS}")
47-
48-
CMD="sudo rkt run --insecure-options=image ${RKT_OPTS} docker://golang:1.6.3 --exec /bin/bash -- -c \"${INIT} && ${CONFORMANCE}\""
43+
CONFORMANCE="\
44+
KUBECONFIG=/kubeconfig KUBERNETES_PROVIDER=skeleton KUBERNETES_CONFORMANCE_TEST=Y go run hack/e2e.go \
45+
-v --test -check_version_skew=false -check_node_count=false --test_args='--ginkgo.focus=\[Conformance\]'"
4946

47+
CMD="sudo rkt run --insecure-options=image ${RKT_OPTS} docker://golang:1.6.3 --exec /bin/bash -- -c \"${INIT} && ${BUILD} && ${CONFORMANCE}\""
5048
ssh -q -o stricthostkeychecking=no -i ${ssh_key} -p ${ssh_port} core@${ssh_host} "${CMD}"

0 commit comments

Comments
 (0)