|
| 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 |
0 commit comments