From fed04ad692ea5cca65ffddbc6be6404d9bc16e7f Mon Sep 17 00:00:00 2001 From: stefanprodan Date: Tue, 6 Aug 2019 21:22:58 +0300 Subject: [PATCH] Add e2e testing with Kubernetes Kind and Helm --- .circleci/config.yml | 9 +++++++++ README.md | 3 ++- e2e/bootstrap.sh | 34 ++++++++++++++++++++++++++++++++++ e2e/install.sh | 17 +++++++++++++++++ e2e/test.sh | 12 ++++++++++++ 5 files changed, 74 insertions(+), 1 deletion(-) create mode 100755 e2e/bootstrap.sh create mode 100755 e2e/install.sh create mode 100755 e2e/test.sh diff --git a/.circleci/config.yml b/.circleci/config.yml index e06f074..e7531f5 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -1,5 +1,13 @@ version: 2.1 jobs: + e2e-kubernetes: + machine: true + steps: + - checkout + - run: e2e/bootstrap.sh + - run: e2e/install.sh + - run: e2e/test.sh + build-container: docker: - image: circleci/golang:1.12 @@ -71,6 +79,7 @@ workflows: build-test: jobs: - build-container + - e2e-kubernetes release: jobs: - build-container: diff --git a/README.md b/README.md index 8dcd84e..0462d98 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,8 @@ Specifications: * Structured logging with zap * 12-factor app with viper * Fault injection (random errors and latency) -* Helm chart +* Helm and Kustomize installers +* End-to-End testing with Kubernetes Kind and Helm Web API: diff --git a/e2e/bootstrap.sh b/e2e/bootstrap.sh new file mode 100755 index 0000000..7fa66c6 --- /dev/null +++ b/e2e/bootstrap.sh @@ -0,0 +1,34 @@ +#!/usr/bin/env bash + +set -o errexit + +REPO_ROOT=$(git rev-parse --show-toplevel) +KIND_VERSION=v0.4.0 + +if [[ "$1" ]]; then + KIND_VERSION=$1 +fi + +echo ">>> Installing kubectl" +curl -sLO https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl && \ +chmod +x kubectl && \ +sudo mv kubectl /usr/local/bin/ + +echo ">>> Installing kind" +curl -sSLo kind "https://github.com/kubernetes-sigs/kind/releases/download/$KIND_VERSION/kind-linux-amd64" +chmod +x kind +sudo mv kind /usr/local/bin/kind + +echo ">>> Creating kind cluster" +kind create cluster --wait 5m + +export KUBECONFIG="$(kind get kubeconfig-path --name="kind")" +kubectl get pods --all-namespaces + +echo ">>> Installing Helm" +curl https://raw.githubusercontent.com/kubernetes/helm/master/scripts/get | bash + +echo '>>> Installing Tiller' +kubectl --namespace kube-system create sa tiller +kubectl create clusterrolebinding tiller-cluster-rule --clusterrole=cluster-admin --serviceaccount=kube-system:tiller +helm init --service-account tiller --upgrade --wait diff --git a/e2e/install.sh b/e2e/install.sh new file mode 100755 index 0000000..3d2f9ac --- /dev/null +++ b/e2e/install.sh @@ -0,0 +1,17 @@ +#!/usr/bin/env bash + +set -o errexit + +REPO_ROOT=$(git rev-parse --show-toplevel) +export KUBECONFIG="$(kind get kubeconfig-path --name="kind")" + +echo ">>> Building container" +docker build -t test/podinfo:latest . + +echo '>>> Loading image in Kind' +kind load docker-image test/podinfo:latest + +echo '>>> Installing' +helm upgrade -i podinfo ${REPO_ROOT}/charts/podinfo --namespace=default +kubectl set image deployment/podinfo podinfo=test/podinfo:latest +kubectl rollout status deployment/podinfo diff --git a/e2e/test.sh b/e2e/test.sh new file mode 100755 index 0000000..3dcb459 --- /dev/null +++ b/e2e/test.sh @@ -0,0 +1,12 @@ +#!/usr/bin/env bash + +set -o errexit + +REPO_ROOT=$(git rev-parse --show-toplevel) +export KUBECONFIG="$(kind get kubeconfig-path --name="kind")" + +echo '>>> Testing' +helm test podinfo + +echo '>>> Test logs' +kubectl logs -l app=podinfo