|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +# Copyright 2017 by the contributors |
| 4 | +# |
| 5 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | +# you may not use this file except in compliance with the License. |
| 7 | +# You may obtain a copy of the License at |
| 8 | +# |
| 9 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +# |
| 11 | +# Unless required by applicable law or agreed to in writing, software |
| 12 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | +# See the License for the specific language governing permissions and |
| 15 | +# limitations under the License. |
| 16 | + |
| 17 | +# This runs integration tests for the local repository, deploying it to |
| 18 | +# CloudFormation and testing various bits of functionality underneath. |
| 19 | + |
| 20 | +set -o errexit |
| 21 | +set -o nounset |
| 22 | +set -o pipefail |
| 23 | +set -o verbose |
| 24 | + |
| 25 | +if ! grep -q Alpine /etc/issue 2>/dev/null; then |
| 26 | + echo "This script is must be run in a docker container (and will make changes to the filesystem, including /root/.ssh). Exiting." |
| 27 | + exit 1 |
| 28 | +fi |
| 29 | + |
| 30 | +REGION="${REGION:-us-west-2}" |
| 31 | +AZ="${AZ:-us-west-2c}" |
| 32 | +S3_BUCKET="${S3_BUCKET:-"heptio-aws-quickstart-test"}" |
| 33 | +S3_PREFIX="${S3_PREFIX:-"heptio/kubernetes"}" |
| 34 | +SSH_KEY="${SSH_KEY:-/tmp/ssh/id_rsa}" |
| 35 | +SSH_KEY_NAME="${SSH_KEY_NAME:-jenkins}" |
| 36 | + |
| 37 | +STACK_NAME="${STACK_NAME:-}" |
| 38 | +if [[ -z "${STACK_NAME}" ]]; then |
| 39 | + STACK_NAME="qs-ci-$(git rev-parse --short HEAD)" |
| 40 | +fi |
| 41 | + |
| 42 | +# Set/ensure env vars needed by AWS, etc |
| 43 | +export AWS_DEFAULT_REGION="${REGION}" |
| 44 | + |
| 45 | +# Setup ssh. Due to SSH being incredibly paranoid about filesystem permissions |
| 46 | +# we just create our own ssh directory and set it from there. (This also |
| 47 | +# allows the docker volume mounts to be read-only.) |
| 48 | +mkdir -p /root/.ssh |
| 49 | +chmod 0700 /root/.ssh |
| 50 | +cp "${SSH_KEY}" /root/.ssh/identity |
| 51 | +export SSH_KEY=/root/.ssh/identity |
| 52 | +chmod 0600 $SSH_KEY |
| 53 | + |
| 54 | +aws --version |
| 55 | +kubectl version --client |
| 56 | + |
| 57 | +aws s3 sync --acl=public-read --delete ./templates "s3://${S3_BUCKET}/${S3_PREFIX}/${STACK_NAME}/templates/" |
| 58 | +aws s3 sync --acl=public-read --delete ./scripts "s3://${S3_BUCKET}/${S3_PREFIX}/${STACK_NAME}/scripts/" |
| 59 | + |
| 60 | +aws cloudformation create-stack \ |
| 61 | + --disable-rollback \ |
| 62 | + --region "${REGION}" \ |
| 63 | + --stack-name "${STACK_NAME}" \ |
| 64 | + --template-url "https://${S3_BUCKET}.s3.amazonaws.com/${S3_PREFIX}/${STACK_NAME}/templates/kubernetes-cluster-with-new-vpc.template" \ |
| 65 | + --parameters \ |
| 66 | + ParameterKey=AvailabilityZone,ParameterValue="${AZ}" \ |
| 67 | + ParameterKey=KeyName,ParameterValue="${SSH_KEY_NAME}" \ |
| 68 | + ParameterKey=QSS3BucketName,ParameterValue="${S3_BUCKET}" \ |
| 69 | + ParameterKey=QSS3KeyPrefix,ParameterValue="${S3_PREFIX}/${STACK_NAME}" \ |
| 70 | + ParameterKey=AdminIngressLocation,ParameterValue=0.0.0.0/0 \ |
| 71 | + ParameterKey=NetworkingProvider,ParameterValue=calico \ |
| 72 | + --capabilities=CAPABILITY_IAM |
| 73 | + |
| 74 | +aws cloudformation wait stack-create-complete --stack-name "${STACK_NAME}" |
| 75 | + |
| 76 | +# Pre-load the SSH host keys |
| 77 | +BASTION_IP=$(aws cloudformation describe-stacks \ |
| 78 | + --query 'Stacks[*].Outputs[?OutputKey == `BastionHostPublicIp`].OutputValue' \ |
| 79 | + --output text --stack-name $STACK_NAME |
| 80 | +) |
| 81 | +MASTER_IP=$(aws cloudformation describe-stacks \ |
| 82 | + --query 'Stacks[*].Outputs[?OutputKey == `MasterPrivateIp`].OutputValue' \ |
| 83 | + --output text --stack-name $STACK_NAME |
| 84 | +) |
| 85 | +ssh -i "$SSH_KEY" -o StrictHostKeyChecking=no -o ProxyCommand="ssh -i ${SSH_KEY} -o StrictHostKeyChecking=no ubuntu@${BASTION_IP} nc %h %p" ubuntu@${MASTER_IP} exit 0 |
| 86 | + |
| 87 | +# TODO: this is a hack... GetKubeConfigCommand has a fake |
| 88 | +# "SSH_KEY=path/to/blah.pem" output, we want to override that with our actual |
| 89 | +# one. |
| 90 | +KUBECONFIG_COMMAND=$(aws cloudformation describe-stacks \ |
| 91 | + --query 'Stacks[*].Outputs[?OutputKey == `GetKubeConfigCommand`].OutputValue' \ |
| 92 | + --output text --stack-name $STACK_NAME \ |
| 93 | + | sed "s!path/to/${SSH_KEY_NAME}.pem!${SSH_KEY}!" |
| 94 | +) |
| 95 | +eval "${KUBECONFIG_COMMAND}" |
| 96 | +export KUBECONFIG=./kubeconfig |
| 97 | + |
| 98 | +# Tests start here |
| 99 | +kubectl get pods --all-namespaces |
0 commit comments