Skip to content

Instantly share code, notes, and snippets.

@woneill
Created October 14, 2019 14:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save woneill/e719de30e106e05d602765f35f3ad89a to your computer and use it in GitHub Desktop.
Save woneill/e719de30e106e05d602765f35f3ad89a to your computer and use it in GitHub Desktop.
Start of a Makefile for kind/helm testing
KIND_VERSION := 0.5.1
KUBECTL_VERSION := 1.16.1
HELM_VERSION := 2.14.3
UNAME := $(shell uname | tr '[:upper:]' '[:lower:]')
WAIT := 200s
BIN_PATH := $(dir $(abspath $(lastword $(MAKEFILE_LIST))))bin
TMP_PATH := $(dir $(abspath $(lastword $(MAKEFILE_LIST))))tmp
KIND := $(BIN_PATH)/kind
KUBECTL := $(BIN_PATH)/kubectl
HELM := $(BIN_PATH)/helm
APPLY = $(KUBECTL) apply --kubeconfig=$$($(KIND) get kubeconfig-path --name $@) --validate=false --filename
NAME = $$(echo $@ | cut -d "-" -f 2- | sed "s/%*$$//")
tekton tekton%: create-tekton%
@$(APPLY) https://storage.googleapis.com/tekton-releases/latest/release.yaml
gatekeeper gatekeeper%: create-gatekeeper%
@$(APPLY) https://raw.githubusercontent.com/open-policy-agent/gatekeeper/master/deploy/gatekeeper-constraint.yaml
create-%: $(KIND) $(KUBECTL) $(HELM)
-@$(KIND) create cluster --name $(NAME) --wait $(WAIT)
$(KUBECTL) --kubeconfig=$$($(KIND) get kubeconfig-path --name $(NAME)) --namespace kube-system create sa tiller
$(KUBECTL) --kubeconfig=$$($(KIND) get kubeconfig-path --name $(NAME)) create clusterrolebinding tiller-cluster-rule --clusterrole=cluster-admin --serviceaccount=kube-system:tiller
$(HELM) init --service-account tiller --upgrade --wait
delete-%: $(KIND)
@$(KIND) delete cluster --name $(NAME)
env-%: $(KIND)
@$(KIND) get kubeconfig-path --name $(NAME)
clean: $(KIND) $(BIN_PATH) $(TMP_PATH)
@$(KIND) get clusters | xargs -L1 -I% $(KIND) delete cluster --name %
@rm -rf $(BIN_PATH) $(TMP_PATH)
list: $(KIND)
@$(KIND) get clusters
$(KIND): $(BIN_PATH)
curl -Lo $(KIND) 'https://github.com/kubernetes-sigs/kind/releases/download/v$(KIND_VERSION)/kind-$(UNAME)-amd64'
chmod +x $(KIND)
$(KUBECTL): $(BIN_PATH)
curl -Lo $(KUBECTL) https://storage.googleapis.com/kubernetes-release/release/v$(KUBECTL_VERSION)/bin/$(UNAME)/amd64/kubectl
chmod +x $(KUBECTL)
$(HELM): $(BIN_PATH) $(TMP_PATH)
curl -Lo $(TMP_PATH)/helm.tgz https://get.helm.sh/helm-v$(HELM_VERSION)-$(UNAME)-amd64.tar.gz
tar zxmf $(TMP_PATH)/helm.tgz -C $(BIN_PATH) --strip-components 1 '*/helm'
chmod +x $(HELM)
$(BIN_PATH):
-@mkdir -p $(BIN_PATH)
$(TMP_PATH):
-@mkdir -p $(TMP_PATH)
.PHONY: tekton gatekeeper tekton% gatekeeper% create-% delete-% env-% clean list
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment