|
1 | 1 |
|
| 2 | +# -include will silently skip missing files, which allows us |
| 3 | +# to load those files with a target in the Makefile. If only |
| 4 | +# "include" was used, the make command would fail and refuse |
| 5 | +# to run a target until the include commands succeeded. |
| 6 | +-include build/makelib/common.mk |
| 7 | + |
2 | 8 | # Image URL to use all building/pushing image targets
|
3 | 9 | IMG ?= quay.io/validator-labs/validator-plugin-azure:latest
|
4 | 10 |
|
5 |
| -GOARCH ?= $(shell go env GOARCH) |
6 |
| - |
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 |
| - |
14 |
| -# CONTAINER_TOOL defines the container tool to be used for building images. |
15 |
| -# Be aware that the target commands are only tested with Docker which is |
16 |
| -# scaffolded by default. However, you might want to replace it to use other |
17 |
| -# tools. (i.e. podman) |
18 |
| -CONTAINER_TOOL ?= docker |
19 |
| - |
20 |
| -# Setting SHELL to bash allows bash commands to be executed by recipes. |
21 |
| -# Options are set to exit when a recipe line exits non-zero or a piped command fails. |
22 |
| -SHELL = /usr/bin/env bash -o pipefail |
23 |
| -.SHELLFLAGS = -ec |
24 |
| - |
25 |
| -.PHONY: all |
26 |
| -all: build |
27 |
| - |
28 |
| -##@ General |
29 |
| - |
30 |
| -# The help target prints out all targets with their descriptions organized |
31 |
| -# beneath their categories. The categories are represented by '##@' and the |
32 |
| -# target descriptions by '##'. The awk commands is responsible for reading the |
33 |
| -# entire set of makefiles included in this invocation, looking for lines of the |
34 |
| -# file as xyz: ## something, and then pretty-format the target and help. Then, |
35 |
| -# if there's a line with ##@ something, that gets pretty-printed as a category. |
36 |
| -# More info on the usage of ANSI control characters for terminal formatting: |
37 |
| -# https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_parameters |
38 |
| -# More info on the awk command: |
39 |
| -# http://linuxcommand.org/lc3_adv_awk.php |
40 |
| - |
41 |
| -.PHONY: help |
42 |
| -help: ## Display this help. |
43 |
| - @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) |
44 |
| - |
45 |
| -##@ Development |
46 |
| - |
47 |
| -.PHONY: manifests |
48 |
| -manifests: controller-gen ## Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects. |
49 |
| - $(CONTROLLER_GEN) rbac:roleName=manager-role crd webhook paths="./..." output:crd:artifacts:config=config/crd/bases |
50 |
| - |
51 |
| -.PHONY: generate |
52 |
| -generate: controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations. |
53 |
| - $(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..." |
54 |
| - |
55 |
| -.PHONY: fmt |
56 |
| -fmt: ## Run go fmt against code. |
57 |
| - go fmt ./... |
58 |
| - |
59 |
| -.PHONY: vet |
60 |
| -vet: ## Run go vet against code. |
61 |
| - go vet ./... |
62 |
| - |
63 |
| -.PHONY: test |
64 |
| -test: manifests generate fmt vet envtest setup-validator ## Run tests. |
65 |
| - KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" go test ./... -coverprofile cover.out |
66 |
| - |
67 |
| -.PHONY: setup-validator |
68 |
| -setup-validator: |
69 |
| - @if [ ! -d ../validator ]; then \ |
70 |
| - git clone https://github.com/validator-labs/validator ../validator; \ |
71 |
| - fi |
72 |
| - |
73 |
| -##@ Build |
74 |
| - |
75 |
| -.PHONY: build |
76 |
| -build: manifests generate fmt vet ## Build manager binary. |
77 |
| - go build -o bin/manager cmd/main.go |
78 |
| - |
79 |
| -.PHONY: run |
80 |
| -run: manifests generate fmt vet ## Run a controller from your host. |
81 |
| - go run ./cmd/main.go |
82 |
| - |
83 |
| -# If you wish built the manager image targeting other platforms you can use the --platform flag. |
84 |
| -# (i.e. docker build --platform linux/arm64 ). However, you must enable docker buildKit for it. |
85 |
| -# More info: https://docs.docker.com/develop/develop-images/build_enhancements/ |
86 |
| -.PHONY: docker-build |
87 |
| -docker-build: test ## Build docker image with the manager. |
88 |
| - $(CONTAINER_TOOL) build -t ${IMG} . --platform linux/$(GOARCH) |
89 |
| - |
90 |
| -.PHONY: docker-push |
91 |
| -docker-push: ## Push docker image with the manager. |
92 |
| - $(CONTAINER_TOOL) push ${IMG} |
93 |
| - |
94 |
| -# PLATFORMS defines the target platforms for the manager image be build to provide support to multiple |
95 |
| -# architectures. (i.e. make docker-buildx IMG=myregistry/mypoperator:0.0.1). To use this option you need to: |
96 |
| -# - able to use docker buildx . More info: https://docs.docker.com/build/buildx/ |
97 |
| -# - have enable BuildKit, More info: https://docs.docker.com/develop/develop-images/build_enhancements/ |
98 |
| -# - be able to push the image for your registry (i.e. if you do not inform a valid value via IMG=<myregistry/image:<tag>> then the export will fail) |
99 |
| -# To properly provided solutions that supports more than one platform you should use this option. |
100 |
| -PLATFORMS ?= linux/arm64,linux/amd64,linux/s390x,linux/ppc64le |
101 |
| -.PHONY: docker-buildx |
102 |
| -docker-buildx: test ## Build and push docker image for the manager for cross-platform support |
103 |
| - # copy existing Dockerfile and insert --platform=${BUILDPLATFORM} into Dockerfile.cross, and preserve the original Dockerfile |
104 |
| - sed -e '1 s/\(^FROM\)/FROM --platform=\$$\{BUILDPLATFORM\}/; t' -e ' 1,// s//FROM --platform=\$$\{BUILDPLATFORM\}/' Dockerfile > Dockerfile.cross |
105 |
| - - $(CONTAINER_TOOL) buildx create --name project-v3-builder |
106 |
| - $(CONTAINER_TOOL) buildx use project-v3-builder |
107 |
| - - $(CONTAINER_TOOL) buildx build --push --platform=$(PLATFORMS) --tag ${IMG} -f Dockerfile.cross . |
108 |
| - - $(CONTAINER_TOOL) buildx rm project-v3-builder |
109 |
| - rm Dockerfile.cross |
110 |
| - |
111 |
| -##@ Deployment |
112 |
| - |
113 |
| -ifndef ignore-not-found |
114 |
| - ignore-not-found = false |
115 |
| -endif |
116 |
| - |
117 |
| -.PHONY: install |
118 |
| -install: manifests kustomize ## Install CRDs into the K8s cluster specified in ~/.kube/config. |
119 |
| - $(KUSTOMIZE) build config/crd | $(KUBECTL) apply -f - |
120 |
| - |
121 |
| -.PHONY: uninstall |
122 |
| -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. |
123 |
| - $(KUSTOMIZE) build config/crd | $(KUBECTL) delete --ignore-not-found=$(ignore-not-found) -f - |
124 |
| - |
125 |
| -.PHONY: deploy |
126 |
| -deploy: manifests kustomize ## Deploy controller to the K8s cluster specified in ~/.kube/config. |
127 |
| - cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG} |
128 |
| - $(KUSTOMIZE) build config/default | $(KUBECTL) apply -f - |
129 |
| - |
130 |
| -.PHONY: undeploy |
131 |
| -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. |
132 |
| - $(KUSTOMIZE) build config/default | $(KUBECTL) delete --ignore-not-found=$(ignore-not-found) -f - |
133 |
| - |
134 |
| -.PHONY: helmify |
135 |
| -helmify: manifests kustomize |
136 |
| - cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG} |
137 |
| - $(KUSTOMIZE) build config/default > chart/validator-plugin-k8s.yaml |
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 |
| -KUBECTL ?= kubectl |
148 |
| -KUSTOMIZE ?= $(LOCALBIN)/kustomize |
149 |
| -CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen |
150 |
| -ENVTEST ?= $(LOCALBIN)/setup-envtest |
151 |
| - |
152 |
| -## Tool Versions |
153 |
| -CHART_VERSION=v0.0.1 # x-release-please-version |
154 |
| -# Version recommended by kubebuilder maintainers to use with controller-runtime 0.18.x. |
155 |
| -CONTROLLER_TOOLS_VERSION ?= v0.15.0 |
156 |
| -ENVTEST_K8S_VERSION = 1.27.1 |
157 |
| -HELM_VERSION=v3.10.1 |
158 |
| -KUSTOMIZE_VERSION ?= v5.0.1 |
159 |
| - |
160 |
| -.PHONY: kustomize |
161 |
| -kustomize: $(KUSTOMIZE) ## Download kustomize locally if necessary. If wrong version is installed, it will be removed before downloading. |
162 |
| -$(KUSTOMIZE): $(LOCALBIN) |
163 |
| - @if test -x $(LOCALBIN)/kustomize && ! $(LOCALBIN)/kustomize version | grep -q $(KUSTOMIZE_VERSION); then \ |
164 |
| - echo "$(LOCALBIN)/kustomize version is not expected $(KUSTOMIZE_VERSION). Removing it before installing."; \ |
165 |
| - rm -rf $(LOCALBIN)/kustomize; \ |
166 |
| - fi |
167 |
| - test -s $(LOCALBIN)/kustomize || GOBIN=$(LOCALBIN) GO111MODULE=on go install sigs.k8s.io/kustomize/kustomize/v5@$(KUSTOMIZE_VERSION) |
168 |
| - |
169 |
| -.PHONY: controller-gen |
170 |
| -controller-gen: $(CONTROLLER_GEN) ## Download controller-gen locally if necessary. If wrong version is installed, it will be overwritten. |
171 |
| -$(CONTROLLER_GEN): $(LOCALBIN) |
172 |
| - test -s $(LOCALBIN)/controller-gen && $(LOCALBIN)/controller-gen --version | grep -q $(CONTROLLER_TOOLS_VERSION) || \ |
173 |
| - GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-tools/cmd/controller-gen@$(CONTROLLER_TOOLS_VERSION) |
174 |
| - |
175 |
| -.PHONY: envtest |
176 |
| -envtest: $(ENVTEST) ## Download envtest-setup locally if necessary. |
177 |
| -$(ENVTEST): $(LOCALBIN) |
178 |
| - test -s $(LOCALBIN)/setup-envtest || GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-runtime/tools/setup-envtest@latest |
179 |
| - |
180 |
| -OSARCH=$(shell ./hack/get-os.sh) |
181 |
| -HELM = $(shell pwd)/bin/$(OSARCH)/helm |
182 |
| -HELM_INSTALLER ?= "https://get.helm.sh/helm-$(HELM_VERSION)-$(OSARCH).tar.gz" |
183 |
| -HELMIFY ?= $(LOCALBIN)/helmify |
184 |
| - |
185 |
| -.PHONY: helm |
186 |
| -helm: $(HELM) ## Download helm locally if necessary. |
187 |
| -$(HELM): $(LOCALBIN) |
188 |
| - [ -e "$(HELM)" ] && rm -rf "$(HELM)" || true |
189 |
| - cd $(LOCALBIN) && curl -s $(HELM_INSTALLER) | tar -xzf - -C $(LOCALBIN) |
190 |
| - |
191 |
| -.PHONY: helmify |
192 |
| -helmify: $(HELMIFY) ## Download helmify locally if necessary. |
193 |
| -$(HELMIFY): $(LOCALBIN) |
194 |
| - test -s $(LOCALBIN)/helmify || GOBIN=$(LOCALBIN) go install github.com/arttor/helmify/cmd/helmify@latest |
195 |
| - |
196 |
| -.PHONY: helm-build |
197 |
| -helm-build: helm helmify manifests kustomize |
198 |
| - cd config/manager && $(KUSTOMIZE) edit set image controller=$(IMG) && cd ../../ |
199 |
| - mkdir chart |
200 |
| - $(KUSTOMIZE) build config/default | $(HELMIFY) -crd-dir chart/validator-plugin-azure |
201 |
| - cat hack/extra-values.yaml >> chart/validator-plugin-azure/values.yaml |
202 |
| - |
203 |
| -.PHONY: helm-package |
204 |
| -helm-package: generate manifests |
205 |
| - $(HELM) package --version $(CHART_VERSION) chart/validator-plugin-azure/ |
206 |
| - mkdir -p charts && mv validator-*.tgz charts |
207 |
| - $(HELM) repo index --url https://validator-labs.github.io/validator-plugin-azure ./chart |
208 |
| - mv charts/validator-plugin-azure/index.yaml index.yaml |
209 |
| - |
210 |
| -.PHONY: frigate |
211 |
| -frigate: |
212 |
| - frigate gen chart/validator-plugin-azure --no-deps -o markdown > chart/validator-plugin-azure/README.md |
| 11 | +# Helm vars |
| 12 | +CHART_NAME=validator-plugin-azure |
213 | 13 |
|
214 | 14 | .PHONY: dev
|
215 | 15 | dev:
|
|
0 commit comments