From 0712212173dc02d944b3cfa09e73aba2a207dd6c Mon Sep 17 00:00:00 2001 From: Daniel Spangenberg Date: Fri, 1 Jul 2022 14:01:51 +0200 Subject: [PATCH] feat: Add kind testing prerequisites (#63) --- .gitignore | 1 + kind-config.yaml | 5 +++ scripts/e2e-kind.sh | 83 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 89 insertions(+) create mode 100644 kind-config.yaml create mode 100755 scripts/e2e-kind.sh diff --git a/.gitignore b/.gitignore index 1d31f301..1b831787 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ cloudquery.log terraform.tfstate terraform.tfvars .vscode +.kind-kubeconfig diff --git a/kind-config.yaml b/kind-config.yaml new file mode 100644 index 00000000..cebee6d5 --- /dev/null +++ b/kind-config.yaml @@ -0,0 +1,5 @@ +kind: Cluster +apiVersion: kind.x-k8s.io/v1alpha4 +nodes: + - role: control-plane + - role: worker diff --git a/scripts/e2e-kind.sh b/scripts/e2e-kind.sh new file mode 100755 index 00000000..f1654a4d --- /dev/null +++ b/scripts/e2e-kind.sh @@ -0,0 +1,83 @@ +#!/usr/bin/env bash + +set -o errexit +set -o nounset +set -o pipefail + +readonly CT_VERSION=v3.6.0 +readonly KIND_VERSION=v0.14.0 +readonly CLUSTER_NAME=chart-testing +readonly K8S_VERSION=v1.24.2 + +run_ct_container() { + echo 'Running or reusing ct container...' + + docker ps -f name=ct | grep -w ct || docker run --rm --interactive --detach --network host --name ct \ + --volume "$(pwd)/ct.yaml:/etc/ct/ct.yaml" \ + --volume "$(pwd):/workdir" \ + --workdir /workdir \ + "quay.io/helmpack/chart-testing:$CT_VERSION" \ + cat + echo +} + +cleanup_ct_container() { + echo 'Removing ct container...' + docker kill ct > /dev/null 2>&1 + + echo 'Done!' +} + +cleanup_kind_cluster() { + cleanup_ct_container + + echo 'Removing kind cluster...' + kind delete cluster --name "$CLUSTER_NAME" > /dev/null 2>&1 + + echo 'Done!' +} + +docker_exec() { + docker exec --interactive ct "$@" +} + +create_kind_cluster() { + if ! command -v kind > /dev/null 2>&1; then + 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 + fi + + echo 'Creating or reusing kind cluster...' + kind get clusters | grep -v 'No kind clusters found.' || kind create cluster --name "$CLUSTER_NAME" --config kind-config.yaml --image "kindest/node:$K8S_VERSION" --wait 60s --kubeconfig .kind-kubeconfig + + echo 'Copying kubeconfig to container...' + docker_exec mkdir /root/.kube || echo + docker cp .kind-kubeconfig ct:/root/.kube/config + + docker_exec kubectl cluster-info + echo + + docker_exec kubectl get nodes + echo + + echo 'Cluster ready!' + echo +} + +install_charts() { + docker_exec ct install --all + echo +} + +main() { + run_ct_container + trap cleanup_ct_container EXIT + + create_kind_cluster + trap cleanup_kind_cluster EXIT + install_charts +} + +main