Skip to content

Commit fc3a6d9

Browse files
author
Fawad Khaliq
authored
Add kinD support to run integration tests (#378)
1 parent 1a97168 commit fc3a6d9

13 files changed

+403
-3
lines changed

.github/workflows/integration-test.yaml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
steps:
1212
- name: clean work dir from previous runs
1313
run: |
14-
rm -rf *
14+
rm -rf *
1515
- name: setup go 1.14
1616
uses: actions/setup-go@v2
1717
with:
@@ -22,5 +22,7 @@ jobs:
2222
source ~/.bashrc
2323
- name: checkout code
2424
uses: actions/checkout@v2
25-
- name: make test
26-
run: make test
25+
- name: setup kind and run integration tests
26+
run: make integration-test
27+
- name: cleanup all the kind clusters
28+
run: make delete-all-kind-clusters

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
*.so
77
*.dylib
88
bin
9+
build
910

1011
# Test binary, build with `go test -c`
1112
*.test

Makefile

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,16 @@ docker-build: check-env test
6767
docker-push: check-env
6868
docker push $(IMAGE)
6969

70+
integration-test: ## Run the integration using kind clusters
71+
@./scripts/test-with-kind.sh
72+
73+
delete-all-kind-clusters: ## Delete all local kind clusters
74+
@kind get clusters | \
75+
while read name ; do \
76+
kind delete cluster --name $$name; \
77+
done
78+
@rm -rf build/tmp-test*
79+
7080
setup-appmesh-sdk-override:
7181
@if [ "$(APPMESH_SDK_OVERRIDE)" = "y" ] ; then \
7282
./appmesh_models_override/setup.sh ; \

scripts/delete-kind-cluster.sh

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#!/bin/bash
2+
set -eo pipefail
3+
4+
SCRIPTPATH="$( cd "$(dirname "$0")" ; pwd -P )"
5+
6+
USAGE=$(cat << 'EOM'
7+
Usage: delete-cluster [-c <CLUSTER_CONTEXT>] [-o]
8+
Deletes a kind cluster and context dir
9+
Example: delete-cluster -c build/tmp-cluster-1234
10+
Required:
11+
-c Cluster context directory
12+
Optional:
13+
-o Override path w/ your own kubectl and kind binaries
14+
EOM
15+
)
16+
17+
# Process our input arguments
18+
while getopts "c:o" opt; do
19+
case ${opt} in
20+
c ) # Cluster context directory
21+
TMP_DIR=$OPTARG
22+
CLUSTER_NAME=$(cat $TMP_DIR/clustername)
23+
;;
24+
o ) # Override path with your own kubectl and kind binaries
25+
OVERRIDE_PATH=1
26+
export PATH=$PATH:$TMP_DIR
27+
;;
28+
\? )
29+
echoerr "$USAGE" 1>&2
30+
exit
31+
;;
32+
esac
33+
done
34+
35+
echo "🥑 Deleting k8s cluster using \"kind\""
36+
kind delete cluster --name "$CLUSTER_NAME"
37+
rm -r $TMP_DIR

scripts/install-cert-manager.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/usr/bin/env bash
2+
3+
# ./scripts/install-cert-manager.sh
4+
#
5+
# Installs a stable version of cert-manager
6+
7+
set -Eo pipefail
8+
9+
CERT_MANAGER_VERSION="v0.14.3"
10+
11+
kubectl apply --validate=false -f https://github.com/jetstack/cert-manager/releases/download/${CERT_MANAGER_VERSION}/cert-manager.yaml

scripts/install-controller-gen.sh

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#!/usr/bin/env bash
2+
3+
# ./scripts/install-controller-gen.sh
4+
#
5+
# Checks that the `controller-gen` binary is available on the host system and
6+
# if it is, that it matches the exact version that we require in order to
7+
# standardize the YAML manifests for CRDs and Kubernetes Roles.
8+
#
9+
# If the locally-installed controller-gen does not match the required version,
10+
# prints an error message asking the user to uninstall it.
11+
#
12+
# NOTE: We use this technique of building using `go build` within a temp
13+
# directory because controller-tools does not have a binary release artifact
14+
# for controller-gen.
15+
#
16+
# See: https://github.com/kubernetes-sigs/controller-tools/issues/500
17+
18+
set -Eo pipefail
19+
20+
SCRIPTS_DIR=$(cd "$(dirname "$0")"; pwd)
21+
ROOT_DIR="$SCRIPTS_DIR/.."
22+
CONTROLLER_TOOLS_VERSION="v0.4.0"
23+
24+
source "$SCRIPTS_DIR/lib/common.sh"
25+
26+
if ! is_installed controller-gen; then
27+
# GOBIN not always set... so default to installing into $GOPATH/bin if
28+
# not...
29+
__install_dir=${GOBIN:-$GOPATH/bin}
30+
__install_path="$__install_dir/controller-gen"
31+
__work_dir=$(mktemp -d /tmp/controller-gen-XXX)
32+
33+
echo -n "installing controller-gen ${CONTROLLER_TOOLS_VERSION} ... "
34+
cd "$__work_dir"
35+
36+
go mod init tmp 1>/dev/null 2>&1
37+
go get -d "sigs.k8s.io/controller-tools/cmd/controller-gen@${CONTROLLER_TOOLS_VERSION}" 1>/dev/null 2>&1
38+
go build -o "$__work_dir/controller-gen" sigs.k8s.io/controller-tools/cmd/controller-gen 1>/dev/null 2>&1
39+
mv "$__work_dir/controller-gen" "$__install_path"
40+
41+
rm -rf "$WORK_DIR"
42+
echo "ok."
43+
fi

scripts/install-kind.sh

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/usr/bin/env bash
2+
3+
# ./scripts/install-kind.sh [<kind version>]
4+
#
5+
# Installs KinD if not installed. Optional parameter specifies the version of
6+
# KinD to install. Defaults to the value of the environment variable
7+
# "KIND_VERSION" and if that is not set, the value of the DEFAULT_KIND_VERSION
8+
# variable.
9+
#
10+
# NOTE: uses `sudo mv` to relocate a downloaded binary to /usr/local/bin/kind
11+
12+
set -Eo pipefail
13+
14+
SCRIPTS_DIR=$(cd "$(dirname "$0")"; pwd)
15+
ROOT_DIR="$SCRIPTS_DIR/.."
16+
DEFAULT_KIND_VERSION="0.9.0"
17+
18+
source "$SCRIPTS_DIR/lib/common.sh"
19+
20+
__kind_version="$1"
21+
if [ "x$__kind_version" == "x" ]; then
22+
__kind_version=${KIND_VERSION:-$DEFAULT_KIND_VERSION}
23+
fi
24+
25+
if ! is_installed kind; then
26+
__kind_url="https://kind.sigs.k8s.io/dl/v${__kind_version}/kind-linux-amd64"
27+
echo -n "installing kind from $__kind_url ... "
28+
curl --silent -Lo ./kind "$__kind_url"
29+
chmod +x ./kind
30+
sudo mv ./kind /usr/local/bin/kind
31+
echo "ok."
32+
fi

scripts/install-kubectl.sh

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/usr/bin/env bash
2+
3+
# ./scripts/install-kubectl.sh
4+
#
5+
# Installs the latest stable version kubectl if not installed.
6+
#
7+
# NOTE: uses `sudo mv` to relocate a downloaded binary to /usr/local/bin/kubectl
8+
9+
set -Eo pipefail
10+
11+
SCRIPTS_DIR=$(cd "$(dirname "$0")"; pwd)
12+
ROOT_DIR="$SCRIPTS_DIR/.."
13+
14+
source "$SCRIPTS_DIR/lib/common.sh"
15+
16+
if ! is_installed kubectl; then
17+
__platform=$(uname | tr '[:upper:]' '[:lower:]')
18+
__stable_k8s_version=$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)
19+
__kubectl_url="https://storage.googleapis.com/kubernetes-release/release/$__stable_k8s_version/bin/$__platform/amd64/kubectl"
20+
echo -n "installing kubectl from $__kubectl_url ... "
21+
curl --silent -Lo ./kubectl "$__kubectl_url"
22+
chmod +x ./kubectl
23+
sudo mv ./kubectl /usr/local/bin/kubectl
24+
echo "ok."
25+
fi

scripts/install-kustomize.sh

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/usr/bin/env bash
2+
3+
# ./scripts/install-kustomize.sh
4+
#
5+
# Installs the latest version kustomize if not installed.
6+
#
7+
# NOTE: uses `sudo mv` to relocate a downloaded binary to /usr/local/bin/kustomize
8+
9+
set -Eo pipefail
10+
11+
SCRIPTS_DIR=$(cd "$(dirname "$0")"; pwd)
12+
ROOT_DIR="$SCRIPTS_DIR/.."
13+
14+
source "$SCRIPTS_DIR/lib/common.sh"
15+
16+
if ! is_installed kustomize ; then
17+
__kustomize_url="https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh"
18+
echo -n "installing kustomize from $__kustomize_url ... "
19+
curl --silent "$__kustomize_url" | bash 1>/dev/null
20+
chmod +x kustomize
21+
sudo mv kustomize /usr/local/bin/kustomize
22+
echo "ok."
23+
fi

scripts/kind-two-node-cluster.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
kind: Cluster
2+
apiVersion: kind.x-k8s.io/v1alpha4
3+
nodes:
4+
- role: control-plane
5+
kubeadmConfigPatches:
6+
- |
7+
apiVersion: kubeadm.k8s.io/v1beta2
8+
kind: ClusterConfiguration
9+
metadata:
10+
name: config
11+
- role: worker

0 commit comments

Comments
 (0)