Skip to content

Commit 1b88db9

Browse files
Makefile: install kustomize if not installed (#22)
1 parent 733f1ca commit 1b88db9

File tree

1 file changed

+32
-10
lines changed

1 file changed

+32
-10
lines changed

example/Makefile

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,34 @@ IMG ?= quay.io/joelanford/nginx-operator
44

55
all: docker-build
66

7+
# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
8+
ifeq (,$(shell go env GOBIN))
9+
GOBIN=$(shell go env GOPATH)/bin
10+
else
11+
GOBIN=$(shell go env GOBIN)
12+
endif
13+
714
# Run against the configured Kubernetes cluster in ~/.kube/config
815
run:
916
go run ../main.go
1017

1118
# Install CRDs into a cluster
12-
install:
13-
kustomize build config/crd | kubectl apply -f -
19+
install: kustomize
20+
$(KUSTOMIZE) build config/crd | kubectl apply -f -
1421

1522
# Uninstall CRDs from a cluster
16-
uninstall:
17-
kustomize build config/crd | kubectl delete -f -
23+
uninstall: kustomize
24+
$(KUSTOMIZE) build config/crd | kubectl delete -f -
1825

1926
# Deploy controller in the configured Kubernetes cluster in ~/.kube/config
20-
deploy:
21-
cd config/manager && kustomize edit set image controller=${IMG}
22-
kustomize build config/default | kubectl apply -f -
27+
deploy: kustomize
28+
cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG}
29+
$(KUSTOMIZE) build config/default | kubectl apply -f -
2330

2431
# Undeploy controller in the configured Kubernetes cluster in ~/.kube/config
25-
undeploy:
26-
cd config/manager && kustomize edit set image controller=${IMG}
27-
kustomize build config/default | kubectl delete -f -
32+
undeploy: kustomize
33+
cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG}
34+
$(KUSTOMIZE) build config/default | kubectl delete -f -
2835

2936
# Build the docker image
3037
docker-build:
@@ -33,3 +40,18 @@ docker-build:
3340
# Push the docker image
3441
docker-push:
3542
docker push ${IMG}
43+
44+
kustomize:
45+
ifeq (, $(shell which kustomize))
46+
@{ \
47+
set -e ;\
48+
KUSTOMIZE_GEN_TMP_DIR=$$(mktemp -d) ;\
49+
cd $$KUSTOMIZE_GEN_TMP_DIR ;\
50+
go mod init tmp ;\
51+
go get sigs.k8s.io/kustomize/kustomize/[email protected] ;\
52+
rm -rf $$KUSTOMIZE_GEN_TMP_DIR ;\
53+
}
54+
KUSTOMIZE=$(GOBIN)/kustomize
55+
else
56+
KUSTOMIZE=$(shell which kustomize)
57+
endif

0 commit comments

Comments
 (0)