This repository was archived by the owner on May 23, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMakefile
More file actions
346 lines (271 loc) · 12.7 KB
/
Makefile
File metadata and controls
346 lines (271 loc) · 12.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
# Image URL to use all building/pushing image targets
REPOSITORY ?= localhost:5005
TAG ?= dev-$(shell git describe --match='' --always --abbrev=6 --dirty)
PLATFORM ?= linux/$(shell go env GOARCH)
CHAINSAW_ARGS ?=
# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
ifeq (,$(shell go env GOBIN))
GOBIN=$(shell go env GOPATH)/bin
else
GOBIN=$(shell go env GOBIN)
endif
# CONTAINER_TOOL defines the container tool to be used for building images.
# Be aware that the target commands are only tested with Docker which is
# scaffolded by default. However, you might want to replace it to use other
# tools. (i.e. podman)
CONTAINER_TOOL ?= docker
# Setting SHELL to bash allows bash commands to be executed by recipes.
# Options are set to exit when a recipe line exits non-zero or a piped command fails.
SHELL = /usr/bin/env bash -o pipefail
.SHELLFLAGS = -ec
.PHONY: all
all: manifests generate api-docs
.PHONY: clean
clean:
-rm -r bin/
##@ General
# The help target prints out all targets with their descriptions organized
# beneath their categories. The categories are represented by '##@' and the
# target descriptions by '##'. The awk command is responsible for reading the
# entire set of makefiles included in this invocation, looking for lines of the
# file as xyz: ## something, and then pretty-format the target and help. Then,
# if there's a line with ##@ something, that gets pretty-printed as a category.
# More info on the usage of ANSI control characters for terminal formatting:
# https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_parameters
# More info on the awk command:
# http://linuxcommand.org/lc3_adv_awk.php
.PHONY: help
help: ## Display this help.
@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)
##@ Development
.PHONY: manifests
manifests: controller-gen ## Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects.
$(CONTROLLER_GEN) rbac:roleName=manager-role crd webhook paths="./..." output:crd:artifacts:config=config/crd/bases
.PHONY: generate
generate: controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..."
.PHONY: test
test: manifests generate ## Run tests.
go test -coverprofile cover.out ./...
.PHONY: test-e2e
test-e2e: chainsaw ## Run the e2e tests against a k8s instance using Kyverno Chainsaw.
$(CHAINSAW) test ${CHAINSAW_ARGS}
BUCKET_NAME ?= test
.PHONY: mc-play-test
mc-play-test: mc
$(MC) mb --ignore-existing play/$(BUCKET_NAME)
.PHONY: mc-play-test-cleanup
mc-play-test-cleanup: mc
$(MC) rb --force play/$(BUCKET_NAME)
.PHONY: fmt
fmt: golangci-lint ## Run golangci-lint formatters.
$(GOLANGCI_LINT) fmt
.PHONY: lint
lint: golangci-lint ## Run golangci-lint linters.
$(GOLANGCI_LINT) run
.PHONY: lint-fix
lint-fix: golangci-lint ## Run golangci-lint linters and perform fixes.
$(GOLANGCI_LINT) run --fix
.PHONY: lint-manifests
lint-manifests: kustomize kube-linter ## Run kube-linter on Kubernetes manifests.
$(KUSTOMIZE) build config/default/manager |\
$(KUBE_LINTER) lint --config=./config/.kube-linter.yaml -
.PHONY: hadolint
hadolint: hadolint-manager hadolint-builder-linuxkit hadolint-gitfetcher hadolint-objfetcher ## Run hadolint on all Dockerfiles.
.PHONY: hadolint-manager
hadolint-manager: ## Run hadolint on manager Dockerfile.
$(CONTAINER_TOOL) run --rm -i hadolint/hadolint < Dockerfile
hadolint-builder-%: ## Run hadolint on builder Dockerfile.
$(CONTAINER_TOOL) run --rm -i hadolint/hadolint < ./pkg/builder/$*/Dockerfile
hadolint-%: ## Run hadolint on init Dockerfile.
$(CONTAINER_TOOL) run --rm -i hadolint/hadolint < ./pkg/init/$*/Dockerfile
.PHONY: verify-licenses
verify-licenses: addlicense ## Run addlicense to verify if files have license headers.
find -type f -name "*.go" ! -path "*/vendor/*" | xargs $(ADDLICENSE) -check || (echo 'Run "make update"' && exit 1)
.PHONY: add-licenses
add-licenses: addlicense ## Run addlicense to append license headers to files missing one.
find -type f -name "*.go" ! -path "*/vendor/*" | xargs $(ADDLICENSE) -c "anza-labs contributors."
.PHONY: serve-docs
serve-docs: ## Serve dev documentation on port 8000
ln -f README.md docs/index.md
$(CONTAINER_TOOL) run \
--rm \
--volume $(shell pwd):/app:ro \
--publish 8000:8000 \
--pull=always \
docker.io/library/python:latest \
bash -c "cd /app && \
pip install -r docs/requirements.txt && \
mkdocs serve \
--dev-addr 0.0.0.0:8000 \
--livereload"
##@ CI
.PHONY: diff
diff: ## Run git diff-index to check if any changes are made.
git --no-pager diff --exit-code HEAD --
VERSION ?= main
.PHONY: publish
publish: ## Runs the script that publishes the latest documentation.
go run ./hack/cmd/publish -version $(VERSION)
.PHONY: release
release: ## Runs the script that generates new release.
go run ./hack/cmd/release -version $(VERSION)
##@ Build
# If you wish to build the manager image targeting other platforms you can use the --platform flag.
# (i.e. docker build --platform linux/arm64). However, you must enable docker buildKit for it.
# More info: https://docs.docker.com/develop/develop-images/build_enhancements/
.PHONY: docker-build
docker-build: docker-build-controller docker-build-builder-linuxkit docker-build-init-gitfetcher docker-build-init-objfetcher ## Build all docker images.
.PHONY: docker-build-controller
docker-build-controller: ## Build docker image with the controller.
$(CONTAINER_TOOL) build \
--platform=${PLATFORM} \
--file=./Dockerfile \
--build-arg=VERSION=$(TAG) \
--build-arg=OCI_REPOSITORY=$(REPOSITORY) \
--tag=$(REPOSITORY)/image-builder-controller:$(TAG) .
docker-build-builder-%: ## Build docker image for the builder.
$(CONTAINER_TOOL) build \
--platform=${PLATFORM} \
--file=./pkg/builder/$*/Dockerfile \
--tag=$(REPOSITORY)/image-builder-$*:$(TAG) .
docker-build-init-%: ## Build docker image for init container.
$(CONTAINER_TOOL) build \
--platform=${PLATFORM} \
--file=./pkg/init/$*/Dockerfile \
--tag=$(REPOSITORY)/image-builder-init-$*:$(TAG) .
.PHONY: docker-push
docker-push: docker-push-controller docker-push-builder-linuxkit docker-push-init-gitfetcher docker-push-init-objfetcher ## Push all docker images.
.PHONY: docker-push-controller
docker-push-controller: ## Push docker image with the controller.
$(CONTAINER_TOOL) push $(REPOSITORY)/image-builder-controller:$(TAG)
docker-push-builder-%: ## Push docker image for the builder.
$(CONTAINER_TOOL) push $(REPOSITORY)/image-builder-$*:$(TAG)
docker-push-init-%: ## Push docker image for init container.
$(CONTAINER_TOOL) push $(REPOSITORY)/image-builder-init-$*:$(TAG)
.PHONY: build-installer
build-installer: manifests generate kustomize ## Generate a consolidated YAML with CRDs and deployment.
mkdir -p dist
cd config/default/manager && $(KUSTOMIZE) edit set image controller=$(REPOSITORY)/image-builder-controller:$(TAG)
$(KUSTOMIZE) build config/default/manager > dist/install.yaml
##@ Documentation
.PHONY: api-docs
api-docs: crd-ref-docs ## Generate API Reference documentation.
ln -f README.md docs/index.md
$(CRD_REF_DOCS) \
--config=./docs/.crd-ref-docs.yaml \
--source-path=./api/ \
--renderer=markdown \
--output-path=./docs/reference/
##@ Deployment
ifndef ignore-not-found
ignore-not-found = false
endif
.PHONY: cluster
cluster: kind ctlptl
@PATH=${LOCALBIN}:$(PATH) $(CTLPTL) apply -f hack/kind.yaml
$(KUBECTL) apply -f https://github.com/cert-manager/cert-manager/releases/download/$(CERT_MANAGER_VERSION)/cert-manager.yaml
.PHONY: cluster-reset
cluster-reset: kind ctlptl
@PATH=${LOCALBIN}:$(PATH) $(CTLPTL) delete -f hack/kind.yaml
.PHONY: deploy
deploy: manifests kustomize ## Deploy controller to the K8s cluster specified in ~/.kube/config.
cd config/default/manager && $(KUSTOMIZE) edit set image controller=$(REPOSITORY)/image-builder-controller:$(TAG)
$(KUSTOMIZE) build config/default/manager | $(KUBECTL) apply -f -
.PHONY: undeploy
undeploy: kustomize ## Undeploy controller from the K8s cluster specified in ~/.kube/config. Call with ignore-not-found=true to ignore resource not found errors during deletion.
$(KUSTOMIZE) build config/default/manager | $(KUBECTL) delete --ignore-not-found=$(ignore-not-found) -f -
##@ Dependencies
## Location to install dependencies to
LOCALBIN ?= $(shell pwd)/bin
$(LOCALBIN):
mkdir -p $(LOCALBIN)
## Tool Binaries
KUBECTL ?= kubectl
ADDLICENSE ?= $(LOCALBIN)/addlicense
CHAINSAW ?= $(LOCALBIN)/chainsaw
CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen
CRD_REF_DOCS ?= $(LOCALBIN)/crd-ref-docs
CTLPTL ?= $(LOCALBIN)/ctlptl
KIND ?= $(LOCALBIN)/kind
KUBE_LINTER ?= $(LOCALBIN)/kube-linter
KUSTOMIZE ?= $(LOCALBIN)/kustomize
GOLANGCI_LINT ?= $(LOCALBIN)/golangci-lint
MC ?= $(LOCALBIN)/mc
## Tool Versions
# renovate: datasource=github-tags depName=google/addlicense
ADDLICENSE_VERSION ?= v1.1.1
# renovate: datasource=github-tags depName=kyverno/chainsaw
CHAINSAW_VERSION ?= v0.2.12
# renovate: datasource=github-tags depName=cert-manager/cert-manager
CERT_MANAGER_VERSION ?= v1.17.2
# renovate: datasource=github-tags depName=kubernetes-sigs/controller-tools
CONTROLLER_TOOLS_VERSION ?= v0.18.0
# renovate: datasource=github-tags depName=elastic/crd-ref-docs
CRD_REF_DOCS_VERSION ?= v0.1.0
# renovate: datasource=github-tags depName=tilt-dev/ctlptl
CTLPTL_VERSION ?= v0.8.42
# renovate: datasource=github-tags depName=golangci/golangci-lint
GOLANGCI_LINT_VERSION ?= v2.1.6
# renovate: datasource=github-tags depName=kubernetes-sigs/kind
KIND_VERSION ?= v0.29.0
# renovate: datasource=github-tags depName=stackrox/kube-linter
KUBE_LINTER_VERSION ?= v0.7.2
# renovate: datasource=github-tags depName=kubernetes-sigs/kustomize
KUSTOMIZE_VERSION ?= v5.6.0
MC_VERSION ?= latest
.PHONY: addlicense
addlicense: $(ADDLICENSE)-$(ADDLICENSE_VERSION) ## Download addlicense locally if necessary.
$(ADDLICENSE)-$(ADDLICENSE_VERSION): $(LOCALBIN)
$(call go-install-tool,$(ADDLICENSE),github.com/google/addlicense,$(ADDLICENSE_VERSION))
.PHONY: chainsaw
chainsaw: $(CHAINSAW)-$(CHAINSAW_VERSION) ## Download chainsaw locally if necessary.
$(CHAINSAW)-$(CHAINSAW_VERSION): $(LOCALBIN)
$(call go-install-tool,$(CHAINSAW),github.com/kyverno/chainsaw,$(CHAINSAW_VERSION))
.PHONY: controller-gen
controller-gen: $(CONTROLLER_GEN)-$(CONTROLLER_TOOLS_VERSION) ## Download controller-gen locally if necessary.
$(CONTROLLER_GEN)-$(CONTROLLER_TOOLS_VERSION): $(LOCALBIN)
$(call go-install-tool,$(CONTROLLER_GEN),sigs.k8s.io/controller-tools/cmd/controller-gen,$(CONTROLLER_TOOLS_VERSION))
.PHONY: crd-ref-docs
crd-ref-docs: $(CRD_REF_DOCS)-$(CRD_REF_DOCS_VERSION) ## Download crd-ref-docs locally if necessary.
$(CRD_REF_DOCS)-$(CRD_REF_DOCS_VERSION): $(LOCALBIN)
$(call go-install-tool,$(CRD_REF_DOCS),github.com/elastic/crd-ref-docs,$(CRD_REF_DOCS_VERSION))
.PHONY: ctlptl
ctlptl: $(CTLPTL)-$(CTLPTL_VERSION) ## Download ctlptl locally if necessary.
$(CTLPTL)-$(CTLPTL_VERSION): $(LOCALBIN)
$(call go-install-tool,$(CTLPTL),github.com/tilt-dev/ctlptl/cmd/ctlptl,$(CTLPTL_VERSION))
.PHONY: golangci-lint
golangci-lint: $(GOLANGCI_LINT)-$(GOLANGCI_LINT_VERSION) ## Download golangci-lint locally if necessary.
$(GOLANGCI_LINT)-$(GOLANGCI_LINT_VERSION): $(LOCALBIN)
./hack/install-golangci-lint.sh $(LOCALBIN) $(GOLANGCI_LINT) $(GOLANGCI_LINT_VERSION)
.PHONY: kind
kind: $(KIND)-$(KIND_VERSION) ## Download kind locally if necessary.
$(KIND)-$(KIND_VERSION): $(LOCALBIN)
$(call go-install-tool,$(KIND),sigs.k8s.io/kind,$(KIND_VERSION))
.PHONY: kube-linter
kube-linter: $(KUBE_LINTER)-$(KUBE_LINTER_VERSION)
$(KUBE_LINTER)-$(KUBE_LINTER_VERSION): $(LOCALBIN)
$(call go-install-tool,$(KUBE_LINTER),golang.stackrox.io/kube-linter/cmd/kube-linter,$(KUBE_LINTER_VERSION))
.PHONY: kustomize
kustomize: $(KUSTOMIZE)-$(KUSTOMIZE_VERSION) ## Download kustomize locally if necessary.
$(KUSTOMIZE)-$(KUSTOMIZE_VERSION): $(LOCALBIN)
$(call go-install-tool,$(KUSTOMIZE),sigs.k8s.io/kustomize/kustomize/v5,$(KUSTOMIZE_VERSION))
.PHONY: mc
mc: $(MC)-$(MC_VERSION) ## Download kustomize locally if necessary.
$(MC)-$(MC_VERSION): $(LOCALBIN)
$(call go-install-tool,$(MC),github.com/minio/mc,$(MC_VERSION))
# go-install-tool will 'go install' any package with custom target and name of binary, if it doesn't exist
# $1 - target path with name of binary
# $2 - package url which can be installed
# $3 - specific version of package
define go-install-tool
@[ -f "$(1)-$(3)" ] || { \
set -e; \
package=$(2)@$(3) ;\
echo "Downloading $${package}" ;\
rm -f $(1) || true ;\
GOBIN=$(LOCALBIN) go install $${package} ;\
mv $(1) $(1)-$(3) ;\
} ;\
ln -sf $(1)-$(3) $(1)
endef