@@ -10,9 +10,6 @@ IMG ?= auto-discovery-kubernetes
1010# Tag used for the image
1111IMG_TAG ?= sha-$$(git rev-parse --short HEAD )
1212
13- # Produce CRDs that work back to Kubernetes 1.11 (no version conversion)
14- CRD_OPTIONS ?= "crd:trivialVersions=true,preserveUnknownFields=false"
15-
1613# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
1714ifeq (,$(shell go env GOBIN) )
1815GOBIN =$(shell go env GOPATH) /bin
2623SHELL = /usr/bin/env bash -o pipefail
2724.SHELLFLAGS = -ec
2825
26+ .PHONY : all
2927all : build
3028
3129# #@ General
@@ -41,96 +39,131 @@ all: build
4139# More info on the awk command:
4240# http://linuxcommand.org/lc3_adv_awk.php
4341
42+ .PHONY : help
4443help : # # Display this help.
4544 @awk ' BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST )
4645
4746# #@ Development
4847
48+ .PHONY : manifests
4949manifests : controller-gen # # Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects.
50- $(CONTROLLER_GEN ) $( CRD_OPTIONS ) rbac:roleName=manager-role webhook paths=" ./..." output:crd:artifacts:config=config/crd/bases
50+ $(CONTROLLER_GEN ) rbac:roleName=manager-role crd webhook paths=" ./..." output:crd:artifacts:config=config/crd/bases
5151
52+ .PHONY : generate
5253generate : controller-gen # # Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
5354 $(CONTROLLER_GEN ) object:headerFile=" hack/boilerplate.go.txt" paths=" ./..."
5455
56+ .PHONY : fmt
5557fmt : # # Run go fmt against code.
5658 go fmt ./...
5759
60+ .PHONY : vet
5861vet : # # Run go vet against code.
5962 go vet ./...
6063
6164ENVTEST_ASSETS_DIR =$(shell pwd) /testbin
6265
66+ .PHONY : test-setup
6367test-setup : manifests generate fmt vet # # Run tests.
6468 mkdir -p ${ENVTEST_ASSETS_DIR}
6569 test -f ${ENVTEST_ASSETS_DIR} /setup-envtest.sh || curl -sSLo ${ENVTEST_ASSETS_DIR} /setup-envtest.sh https://raw.githubusercontent.com/kubernetes-sigs/controller-runtime/v0.7.2/hack/setup-envtest.sh
66-
6770
71+ .PHONY : test
6872test : test-setup
6973 source ${ENVTEST_ASSETS_DIR} /setup-envtest.sh; fetch_envtest_tools $(ENVTEST_ASSETS_DIR ) ; setup_envtest_env $(ENVTEST_ASSETS_DIR ) ; go test ./... -coverprofile cover.out
74+
75+ .PHONY : ginko
7076ginkgo :
7177 source ${ENVTEST_ASSETS_DIR} /setup-envtest.sh; fetch_envtest_tools $(ENVTEST_ASSETS_DIR ) ; setup_envtest_env $(ENVTEST_ASSETS_DIR ) ; ginkgo test ./... -coverprofile cover.out -v --progress
7278
7379# #@ Build
7480
81+ .PHONY : build
7582build : generate fmt vet # # Build manager binary.
7683 go build -o bin/manager main.go
7784
85+ .PHONY : run
7886run : manifests generate fmt vet # # Run a controller from your host.
7987 go run ./main.go --config auto-discovery-config.yaml
8088
89+ .PHONY : docker-build
8190docker-build : test # # Build docker image with the manager.
8291 @echo " .: ⚙️ Build Container Images"
8392 docker build -t ${IMG_NS} /${IMG} :${IMG_TAG} .
8493
94+ .PHONY : docker-push
8595docker-push : # # Push docker image with the manager.
8696 docker push ${IMG_NS} /${IMG} :${IMG_TAG}
8797
98+ .PHONY : docker-export
8899docker-export :
89100 @echo " .: 💾 Export Container Images"
90101 docker save $(IMG_NS ) /$(IMG ) :$(IMG_TAG ) > $(IMG ) .tar
91102
92103# #@ Deployment
93104
105+ .PHONY : kind-import
94106kind-import :
95107 @echo " .: 💾 Importing the image archive to local kind cluster."
96108 kind load image-archive ./$(IMG ) .tar
97109
110+ .PHONY : helm-deploy
98111helm-deploy :
99112 @echo " .: ⚙️ Deploying auto-discovery with the Image tag '$( IMG_TAG) ' into kind."
100113 helm upgrade --install auto-discovery ./ --wait \
101- --set="image.repository =docker.io/$(IMG_NS ) /$(IMG ) " \
102- --set="image.tag=$(IMG_TAG ) " \
114+ --set=" image.repository=docker.io/$( IMG_NS) /$( IMG) " \
115+ --set=" image.tag=$( IMG_TAG) " \
103116 --set=" image.pullPolicy=IfNotPresent" \
104117
118+ ifndef ignore-not-found
119+ ignore-not-found = false
120+ endif
121+
122+ .PHONY : install
105123install : manifests kustomize # # Install CRDs into the K8s cluster specified in ~/.kube/config.
106124 $(KUSTOMIZE ) build config/crd | kubectl apply -f -
107125
108- uninstall : manifests kustomize # # Uninstall CRDs from the K8s cluster specified in ~/.kube/config.
109- $(KUSTOMIZE ) build config/crd | kubectl delete -f -
126+ .PHONY : uninstall
127+ uninstall : manifests kustomize # # Uninstall CRDs from the K8s cluster specified in ~/.kube/config. Call with ignore-not-found=true to ignore resource not found errors during deletion.
128+ $(KUSTOMIZE ) build config/crd | kubectl delete --ignore-not-found=$(ignore-not-found ) -f -
110129
130+ .PHONY : deploy
111131deploy : manifests kustomize # # Deploy controller to the K8s cluster specified in ~/.kube/config.
112132 cd config/manager && $(KUSTOMIZE ) edit set image controller=${IMG}
113133 $(KUSTOMIZE ) build config/default | kubectl apply -f -
114134
115- undeploy : # # Undeploy controller from the K8s cluster specified in ~/.kube/config.
116- $(KUSTOMIZE ) build config/default | kubectl delete -f -
117-
118-
119- CONTROLLER_GEN = $(shell pwd) /bin/controller-gen
120- controller-gen : # # Download controller-gen locally if necessary.
121- $(call go-install-tool,$(CONTROLLER_GEN ) ,sigs.k8s.io/controller-tools/cmd/controller-gen@v0.4.1)
122-
123- KUSTOMIZE = $(shell pwd) /bin/kustomize
124- kustomize : # # Download kustomize locally if necessary.
125- $(call go-install-tool,$(KUSTOMIZE ) ,sigs.k8s.io/kustomize/kustomize/v3@v3.8.7)
126-
127- # go-install-tool will 'go install' any package $2 and install it to $1.
128- # GOBIN needs to be an absolute path so an additional absolute path project dir variable is used
129- ABS_PROJECT_DIR =$(shell dirname $(abspath $(lastword $(MAKEFILE_LIST ) ) ) )
130- define go-install-tool
131- @[ -f $(1 ) ] || { \
132- set -e ;\
133- echo "Downloading $(2 ) " ;\
134- GOBIN=$(ABS_PROJECT_DIR ) /bin go install $(2 ) ;\
135- }
136- endef
135+ .PHONY : undeploy
136+ undeploy : # # Undeploy controller from the K8s cluster specified in ~/.kube/config. Call with ignore-not-found=true to ignore resource not found errors during deletion.
137+ $(KUSTOMIZE ) build config/default | kubectl delete --ignore-not-found=$(ignore-not-found ) -f -
138+
139+ # #@ Build Dependencies
140+
141+ # # Location to install dependencies to
142+ LOCALBIN ?= $(shell pwd) /bin
143+ $(LOCALBIN ) :
144+ mkdir -p $(LOCALBIN )
145+
146+ # # Tool Binaries
147+ KUSTOMIZE ?= $(LOCALBIN ) /kustomize
148+ CONTROLLER_GEN ?= $(LOCALBIN ) /controller-gen
149+ ENVTEST ?= $(LOCALBIN ) /setup-envtest
150+
151+ # # Tool Versions
152+ KUSTOMIZE_VERSION ?= v3.8.7
153+ CONTROLLER_TOOLS_VERSION ?= v0.9.2
154+
155+ KUSTOMIZE_INSTALL_SCRIPT ?= "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh"
156+ .PHONY : kustomize
157+ kustomize : $(KUSTOMIZE ) # # Download kustomize locally if necessary.
158+ $(KUSTOMIZE ) : $(LOCALBIN )
159+ test -s $(LOCALBIN ) /kustomize || { curl -s $( KUSTOMIZE_INSTALL_SCRIPT) | bash -s -- $( subst v,,$( KUSTOMIZE_VERSION) ) $( LOCALBIN) ; }
160+
161+ .PHONY : controller-gen
162+ controller-gen : $(CONTROLLER_GEN ) # # Download controller-gen locally if necessary.
163+ $(CONTROLLER_GEN ) : $(LOCALBIN )
164+ test -s $(LOCALBIN ) /controller-gen || GOBIN=$(LOCALBIN ) go install sigs.k8s.io/controller-tools/cmd/controller-gen@$(CONTROLLER_TOOLS_VERSION )
165+
166+ .PHONY : envtest
167+ envtest : $(ENVTEST ) # # Download envtest-setup locally if necessary.
168+ $(ENVTEST ) : $(LOCALBIN )
169+ test -s $(LOCALBIN ) /setup-envtest || GOBIN=$(LOCALBIN ) go install sigs.k8s.io/controller-runtime/tools/setup-envtest@latest
0 commit comments