Skip to content

Commit

Permalink
feat: Add kind testing prerequisites (cloudquery#63)
Browse files Browse the repository at this point in the history
  • Loading branch information
spangenberg authored Jul 1, 2022
1 parent 5f1a4cb commit 0712212
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ cloudquery.log
terraform.tfstate
terraform.tfvars
.vscode
.kind-kubeconfig
5 changes: 5 additions & 0 deletions kind-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
nodes:
- role: control-plane
- role: worker
83 changes: 83 additions & 0 deletions scripts/e2e-kind.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 0712212

Please sign in to comment.