@@ -74,10 +74,8 @@ func (f *Makefile) SetTemplateDefaults() error {
7474const makefileTemplate = `
7575# Image URL to use all building/pushing image targets
7676IMG ?= {{ .Image }}
77- # Produce CRDs that work back to Kubernetes 1.11 (no version conversion)
78- CRD_OPTIONS ?= "crd:trivialVersions=true,preserveUnknownFields=false"
7977# ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary.
80- ENVTEST_K8S_VERSION = 1.24
78+ ENVTEST_K8S_VERSION = 1.24.2
8179
8280# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
8381ifeq (,$(shell go env GOBIN))
@@ -87,11 +85,12 @@ GOBIN=$(shell go env GOBIN)
8785endif
8886
8987# Setting SHELL to bash allows bash commands to be executed by recipes.
90- # This is a requirement for 'setup-envtest.sh' in the test target.
9188# Options are set to exit when a recipe line exits non-zero or a piped command fails.
9289SHELL = /usr/bin/env bash -o pipefail
9390.SHELLFLAGS = -ec
9491
92+ .PHONY: all
93+ all: build
9594
9695##@ General
9796
@@ -106,95 +105,99 @@ SHELL = /usr/bin/env bash -o pipefail
106105# More info on the awk command:
107106# http://linuxcommand.org/lc3_adv_awk.php
108107
108+ .PHONY: help
109109help: ## Display this help.
110110 @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)
111111
112- ##@ Build
113-
114- run: helm-operator ## Run against the configured Kubernetes cluster in ~/.kube/config
115- $(HELM_OPERATOR) run
116-
117- docker-build: ## Build docker image with the manager.
118- docker build -t ${IMG} .
119-
120- docker-push: ## Push docker image with the manager.
121- docker push ${IMG}
122-
123112##@ Development
124113
114+ .PHONY: manifests
125115manifests: controller-gen ## Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects.
126- $(CONTROLLER_GEN) $(CRD_OPTIONS) rbac:roleName=manager-role webhook paths="./..." output:crd:artifacts:config=config/crd/bases
116+ $(CONTROLLER_GEN) rbac:roleName=manager-role crd webhook paths="./..." output:crd:artifacts:config=config/crd/bases
127117
118+ .PHONY: generate
128119generate: controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
129120 $(CONTROLLER_GEN) object:headerFile={{printf "%q" .BoilerplatePath}} paths="./..."
130121
122+ .PHONY: fmt
131123fmt: ## Run go fmt against code.
132124 go fmt ./...
133125
126+ .PHONY: vet
134127vet: ## Run go vet against code.
135128 go vet ./...
136129
130+ .PHONY: test
137131test: manifests generate fmt vet envtest ## Run tests.
138132 KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) -p path)" go test ./... -coverprofile cover.out
133+
134+
135+ ##@ Build
136+ .PHONY: run
137+ run: manifests generate fmt vet ## Run against the configured Kubernetes cluster in ~/.kube/config
138+ helm-operator
139+ $(HELM_OPERATOR) run
139140
141+ .PHONY: docker-build
142+ docker-build: test ## Build docker image with the manager.
143+ docker build -t ${IMG}
144+
145+ .PHONY: docker-push
146+ docker-push: ## Push docker image with the manager.
147+ docker push ${IMG}
148+
140149##@ Deployment
141150
142- install: kustomize ## Install CRDs into the K8s cluster specified in ~/.kube/config.
151+ ifndef ignore-not-found
152+ ignore-not-found = false
153+ endif
154+
155+ .PHONY: install
156+ install: manifests kustomize ## Install CRDs into the K8s cluster specified in ~/.kube/config.
143157 $(KUSTOMIZE) build config/crd | kubectl apply -f -
144158
145- uninstall: kustomize ## Uninstall CRDs from the K8s cluster specified in ~/.kube/config.
146- $(KUSTOMIZE) build config/crd | kubectl delete -f -
159+ .PHONY: uninstall
160+ 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.
161+ $(KUSTOMIZE) build config/crd | kubectl delete --ignore-not-found=$(ignore-not-found) -f -
147162
148- deploy: kustomize ## Deploy controller to the K8s cluster specified in ~/.kube/config.
163+ .PHONY: deploy
164+ deploy: manifests kustomize ## Deploy controller to the K8s cluster specified in ~/.kube/config.
149165 cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG}
150166 $(KUSTOMIZE) build config/default | kubectl apply -f -
151167
152- undeploy: ## Undeploy controller from the K8s cluster specified in ~/.kube/config.
153- $(KUSTOMIZE) build config/default | kubectl delete -f -
154-
155- OS := $(shell uname -s | tr '[:upper:]' '[:lower:]')
156- ARCH := $(shell uname -m | sed 's/x86_64/amd64/')
157-
158- CONTROLLER_GEN = $(shell pwd)/bin/controller-gen
159- controller-gen: ## Download controller-gen locally if necessary.
160- $(call go-get-tool,$(CONTROLLER_GEN),sigs.k8s.io/controller-tools/cmd/[email protected] ) 161-
162- KUSTOMIZE = $(shell pwd)/bin/kustomize
163- kustomize: ## Download kustomize locally if necessary.
164- $(call go-get-tool,$(KUSTOMIZE),sigs.k8s.io/kustomize/kustomize/[email protected] ) 165-
166- ENVTEST = $(shell pwd)/bin/setup-envtest
167- envtest: ## Download envtest-setup locally if necessary.
168- $(call go-get-tool,$(ENVTEST),sigs.k8s.io/controller-runtime/tools/setup-envtest@latest)
169-
170- # go-get-tool will 'go get' any package $2 and install it to $1.
171- PROJECT_DIR := $(shell dirname $(abspath $(lastword $(MAKEFILE_LIST))))
172- define go-get-tool
173- @[ -f $(1) ] || { \
174- set -e ;\
175- TMP_DIR=$$(mktemp -d) ;\
176- cd $$TMP_DIR ;\
177- go mod init tmp ;\
178- echo "Downloading $(2)" ;\
179- GOBIN=$(PROJECT_DIR)/bin go get $(2) && GOBIN=$(PROJECT_DIR)/bin go install $(2) ;\
180- rm -rf $$TMP_DIR ;\
181- }
182- endef
183-
184- .PHONY: helm-operator
185- HELM_OPERATOR = $(shell pwd)/bin/helm-operator
186- helm-operator: ## Download helm-operator locally if necessary, preferring the $(pwd)/bin path over global if both exist.
187- ifeq (,$(wildcard $(HELM_OPERATOR)))
188- ifeq (,$(shell which helm-operator 2>/dev/null))
189- @{ \
190- set -e ;\
191- mkdir -p $(dir $(HELM_OPERATOR)) ;\
192- curl -sSLo $(HELM_OPERATOR) https://github.com/operator-framework/operator-sdk/releases/download/v1.9.0/helm-operator_$(OS)_$(ARCH) ;\
193- chmod +x $(HELM_OPERATOR) ;\
194- }
195- else
196- HELM_OPERATOR = $(shell which helm-operator)
197- endif
198- endif
199-
168+ .PHONY: undeploy
169+ 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.
170+ $(KUSTOMIZE) build config/default | kubectl delete --ignore-not-found=$(ignore-not-found) -f -
171+
172+ ##@ Build Dependencies
173+
174+ ## Location to install dependencies to
175+ LOCALBIN ?= $(shell pwd)/bin
176+ $(LOCALBIN):
177+ mkdir -p $(LOCALBIN)
178+
179+ ## Tool Binaries
180+ KUSTOMIZE ?= $(LOCALBIN)/kustomize
181+ CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen
182+ ENVTEST ?= $(LOCALBIN)/setup-envtest
183+
184+ ## Tool Versions
185+ KUSTOMIZE_VERSION ?= {{ .KustomizeVersion }}
186+ CONTROLLER_TOOLS_VERSION ?= {{ .ControllerToolsVersion }}
187+
188+ KUSTOMIZE_INSTALL_SCRIPT ?= "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh"
189+ .PHONY: kustomize
190+ kustomize: $(KUSTOMIZE) ## Download kustomize locally if necessary.
191+ $(KUSTOMIZE): $(LOCALBIN)
192+ test -s $(LOCALBIN)/kustomize || { curl -s $(KUSTOMIZE_INSTALL_SCRIPT) | bash -s -- $(subst v,,$(KUSTOMIZE_VERSION)) $(LOCALBIN); }
193+
194+ .PHONY: controller-gen
195+ controller-gen: $(CONTROLLER_GEN) ## Download controller-gen locally if necessary.
196+ $(CONTROLLER_GEN): $(LOCALBIN)
197+ test -s $(LOCALBIN)/controller-gen || GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-tools/cmd/controller-gen@$(CONTROLLER_TOOLS_VERSION)
198+
199+ .PHONY: envtest
200+ envtest: $(ENVTEST) ## Download envtest-setup locally if necessary.
201+ $(ENVTEST): $(LOCALBIN)
202+ test -s $(LOCALBIN)/setup-envtest || GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-runtime/tools/setup-envtest@latest
200203`
0 commit comments