diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 07de040..f3fca72 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -6,10 +6,15 @@ jobs: ci_job: name: test runs-on: ubuntu-22.04 - container: - image: golang:1.22 steps: - name: Checkout uses: actions/checkout@v4 + - name: Create kind cluster + uses: helm/kind-action@v1 + with: + cluster_name: kvs-test + install_only: true + - name: Prepare env + run: make bootstrap - name: Test run: make test diff --git a/Makefile b/Makefile index fe26ed9..4014683 100644 --- a/Makefile +++ b/Makefile @@ -3,11 +3,15 @@ BINARY := kubectl-view-secret build: kubectl-view-secret +bootstrap: + ./hack/kind-bootstrap.sh + test: $(SOURCES) go test -v -short -race -timeout 30s ./... clean: @rm -rf $(BINARY) + @kind delete cluster --name kvs-test $(BINARY): $(SOURCES) CGO_ENABLED=0 go build -o $(BINARY) -ldflags="-s -w" ./cmd/$(BINARY).go diff --git a/hack/kind-bootstrap.sh b/hack/kind-bootstrap.sh new file mode 100755 index 0000000..5b34238 --- /dev/null +++ b/hack/kind-bootstrap.sh @@ -0,0 +1,42 @@ +#!/usr/bin/env bash + +set -euo pipefail + +CLUSTER_NAME="kvs-test" + +# Check if kind & kubectl are installed +which kind &>/dev/null || { echo "failed to find 'kind' binary, please install it" && exit 1; } +which kubectl &>/dev/null || { echo "failed to find 'kubectl' binary, please install it" && exit 1; } + +# Ensure the cluster exists +[[ $(kind get clusters) == *$CLUSTER_NAME* ]] || kind create cluster --name $CLUSTER_NAME + +# Set context in case there are mulitple +kubectl config set-context kind-${CLUSTER_NAME} + +# Seed test secrets + +## secret 'test' in namespace 'default' (multiple keys) +kubectl apply -f - <