From 7f4e34188523b52199730165b875d33f5e32fb74 Mon Sep 17 00:00:00 2001 From: Anna Kapuscinska Date: Mon, 15 Jul 2024 00:19:13 +0100 Subject: [PATCH] Makefile: Add kind-down target for deleting dev kind cluster Signed-off-by: Anna Kapuscinska --- Makefile | 4 +++ contrib/kind/bootstrap-kind-cluster.sh | 2 +- contrib/kind/delete-kind-cluster.sh | 40 ++++++++++++++++++++++++++ 3 files changed, 45 insertions(+), 1 deletion(-) create mode 100755 contrib/kind/delete-kind-cluster.sh diff --git a/Makefile b/Makefile index f4aea0a4756..caeb6960804 100644 --- a/Makefile +++ b/Makefile @@ -362,6 +362,10 @@ endif .PHONY: kind-setup kind-setup: kind kind-install-tetragon ## Create a kind cluster and install local version of Tetragon. +.PHONY: kind-down +kind-down: ## Delete a kind cluster for Tetragon development. + ./contrib/kind/delete-kind-cluster.sh + ##@ Chores and generated files .PHONY: codegen protogen diff --git a/contrib/kind/bootstrap-kind-cluster.sh b/contrib/kind/bootstrap-kind-cluster.sh index fe570df123b..d900544dc4a 100755 --- a/contrib/kind/bootstrap-kind-cluster.sh +++ b/contrib/kind/bootstrap-kind-cluster.sh @@ -1,4 +1,4 @@ -#! /bin/bash +#!/usr/bin/env bash error() { echo "$@" 1>&2 diff --git a/contrib/kind/delete-kind-cluster.sh b/contrib/kind/delete-kind-cluster.sh new file mode 100755 index 00000000000..417268951e8 --- /dev/null +++ b/contrib/kind/delete-kind-cluster.sh @@ -0,0 +1,40 @@ +#!/usr/bin/env bash + +error() { + echo "$@" 1>&2 + exit 1 +} + +set -eu + +PROJECT_ROOT="$(git rev-parse --show-toplevel)" +cd "$PROJECT_ROOT" +source contrib/kind/conf + +if ! command -v kind &>/dev/null; then + error "kind is not in \$PATH! Bailing out!" +fi + +usage() { + echo "usage: delete-kind-cluster.sh [OPTIONS]" 1>&2 + echo "OPTIONS:" 1>&2 + echo " --cluster override cluster name" 1>&2 +} + +while [ $# -ge 1 ]; do + if [ "$1" == "--cluster" ]; then + CLUSTER_NAME="$2" + shift 2 + else + usage + exit 1 + fi +done + + +if ! kind get clusters | grep "$CLUSTER_NAME" &>/dev/null; then + echo "Cluster $CLUSTER_NAME doesn't exist. Exiting." 1>&2 + exit 0 +else + kind delete cluster --name "$CLUSTER_NAME" +fi