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