Skip to content

Commit

Permalink
[ci] Run e2e integration tests in Kind (#191)
Browse files Browse the repository at this point in the history
  • Loading branch information
schallert authored Feb 14, 2020
1 parent 606ecd3 commit fd5e604
Show file tree
Hide file tree
Showing 6 changed files with 117 additions and 6 deletions.
15 changes: 15 additions & 0 deletions .buildkite/hooks/pre-exit
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash

set -eo pipefail

# If there was a kind cluster created during CI, tear it down.
KIND="$HOME/bin/kind"
if [[ -f "$KIND" ]]; then
echo "--- :kubernetes: deleting kind cluster"
$KIND get clusters -q | while read -r CLUSTER; do
$KIND delete cluster --name "$CLUSTER"
done
fi

echo "--- :git: cleaning checkout"
git clean -dffx
10 changes: 10 additions & 0 deletions .buildkite/pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,13 @@ steps:
config: .buildkite/docker-compose.yml
workdir: /go/src/github.com/m3db/m3db-operator
<<: *common
# NB(schallert): skipped until OSS CI stack upgraded
# - name: ":kubernetes: e2e tests"
# command: make clean test-e2e
# env:
# CGO_ENABLED: 0
# GIMME_GO_VERSION: 1.13.x
# plugins:
# gopath-checkout#v1.0.1:
# import: github.com/m3db/m3db-operator
# <<: *common
9 changes: 7 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,15 @@ test-no-deps: test-base
@echo "--- $@"
@$(tools_bin_path)/gocov convert $(coverfile) | $(tools_bin_path)/gocov report

.PHONY: kind-create-cluster
kind-create-cluster:
@echo "--- Starting KIND cluster"
@./scripts/kind-create-cluster.sh

.PHONY: test-e2e
test-e2e:
test-e2e: kind-create-cluster
@echo "--- $@"
$(SELF_DIR)/scripts/run_e2e_tests.sh
PATH=$(HOME)/bin:$(PATH) $(SELF_DIR)/scripts/run_e2e_tests.sh

.PHONY: testhtml
testhtml: test-base
Expand Down
10 changes: 7 additions & 3 deletions integration/manifests/operator.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ rules:
verbs: ["create", "get", "deletecollection", "delete"]
- apiGroups: [""]
resources: ["pods"]
verbs: ["list", "get", "watch", "update"]
verbs: ["list", "get", "watch", "update", "patch"]
- apiGroups: ["apps"]
resources: ["statefulsets", "deployments"]
verbs: ["*"]
Expand Down Expand Up @@ -68,8 +68,12 @@ spec:
labels:
name: m3db-operator
spec:
securityContext:
runAsNonRoot: true
runAsUser: 65534
runAsGroup: 65534
containers:
- name: m3db-operator
image: quay.io/m3db/m3db-operator:latest
imagePullPolicy: Always
image: m3db-operator-kind
imagePullPolicy: Never
serviceAccount: operator-test-sa
72 changes: 72 additions & 0 deletions scripts/kind-create-cluster.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
#!/bin/bash

set -exo pipefail

echo "--- :kubernetes: Installing kind"

KUBE_VERSION=${KUBE_VERSION:-v1.15.7}
CLUSTER_NAME=kind
L_UNAME=$(uname | tr "[:upper:]" "[:lower:]")

mkdir -p "$HOME/bin"

if [[ ! -x "$HOME/bin/kind" || "$BUILDKITE" == "true" ]]; then
curl -sL -o "$HOME/bin/kind" "https://github.com/kubernetes-sigs/kind/releases/download/v0.7.0/kind-${L_UNAME}-amd64"
fi

if [[ ! -x "$HOME/bin/kubectl" || "$BUILDKITE" == "true" ]]; then
curl -sL -o "$HOME/bin/kubectl" "https://storage.googleapis.com/kubernetes-release/release/$KUBE_VERSION/bin/${L_UNAME}/amd64/kubectl"
fi

chmod +x "$HOME/bin/kind" "$HOME/bin/kubectl"
export PATH="$HOME/bin:$PATH"

echo "--- :kubernetes: Deleting existing kind clusters"
kind get clusters -q | while read -r CLUSTER; do
kind delete cluster --name "$CLUSTER"
done

echo "--- :kubernetes: Creating kind cluster"

cat > cluster.yaml <<EOF
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
nodes:
- role: control-plane
- role: worker
kubeadmConfigPatches:
- |
apiVersion: kubeadm.k8s.io/v1beta2
kind: JoinConfiguration
nodeRegistration:
kubeletExtraArgs:
node-labels: "failure-domain.beta.kubernetes.io/zone=us-east1-b"
- role: worker
kubeadmConfigPatches:
- |
apiVersion: kubeadm.k8s.io/v1beta2
kind: JoinConfiguration
nodeRegistration:
kubeletExtraArgs:
node-labels: "failure-domain.beta.kubernetes.io/zone=us-east1-c"
- role: worker
kubeadmConfigPatches:
- |
apiVersion: kubeadm.k8s.io/v1beta2
kind: JoinConfiguration
nodeRegistration:
kubeletExtraArgs:
node-labels: "failure-domain.beta.kubernetes.io/zone=us-east1-d"
EOF

kind create cluster --image "kindest/node:$KUBE_VERSION" --name "$CLUSTER_NAME" --config cluster.yaml

kubectl get nodes
kubectl cluster-info

echo "--- :kubernetes: Kind cluster created"

echo "--- Waiting for cluster to be ready"
while kubectl get nodes | grep -q NotReady; do
sleep 5
done
7 changes: 6 additions & 1 deletion scripts/run_e2e_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ function main() {
done

# If a kubectl proxy process is running, delete and wait until it's dead
if pgrep -fq 'kubectl proxy'; then
if pgrep -f 'kubectl proxy'; then
pkill -f 'kubectl proxy'
local PROXYCOUNT=0
while [[ $PROXYCOUNT -lt 10 ]]; do
Expand All @@ -46,6 +46,11 @@ function main() {

trap cleanup EXIT

if [[ -z "$SKIP_DOCKER_BUILD" ]]; then
docker build -t m3db-operator-kind .
kind load docker-image m3db-operator-kind
fi

kubectl proxy &
go clean -testcache
go test -v -tags integration ./integration/e2e
Expand Down

0 comments on commit fd5e604

Please sign in to comment.