-
Notifications
You must be signed in to change notification settings - Fork 26
/
Makefile
273 lines (211 loc) · 10.3 KB
/
Makefile
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
aperture_path := $(dir $(abspath $(lastword $(MAKEFILE_LIST))))
SHELL := /bin/bash
# use GOMAXPROCS from environment if set, otherwise default to 8
export GOMAXPROCS ?= 8
GIT_ROOT := $(shell git rev-parse --show-toplevel)
DOCS_OPENAPI := $(GIT_ROOT)/docs/content/assets/openapiv2
DOCS_ROOT := $(GIT_ROOT)/docs
generate-api:
@echo Generating API
@cd api && $(MAKE) generate
@#generate api docs
@rm -rfd $(DOCS_OPENAPI)
@mv $(GIT_ROOT)/api/gen/openapiv2 $(DOCS_OPENAPI)
@{ \
set -e; \
go run $(GIT_ROOT)/api/enrich-api-swagger.go $(DOCS_OPENAPI)/aperture.swagger.yaml; \
go run $(DOCS_ROOT)/tools/swagger/process-go-tags.go $(DOCS_OPENAPI)/aperture.swagger.yaml; \
for process in aperture-agent aperture-controller; do \
yq eval "del(.paths | .[] | select(.*.tags | contains([\"$$process\"]) | not))" $(DOCS_OPENAPI)/aperture.swagger.yaml > $(DOCS_OPENAPI)/$$process.swagger.yaml; \
yq eval -i "del(.tags)" $(DOCS_OPENAPI)/$$process.swagger.yaml; \
yq eval -i ".host = \"$$process\"" $(DOCS_OPENAPI)/$$process.swagger.yaml; \
yq eval -i '.schemes = ["https"]' $(DOCS_OPENAPI)/$$process.swagger.yaml; \
swagger flatten --with-flatten=remove-unused $(DOCS_OPENAPI)/$$process.swagger.yaml --output=$(DOCS_OPENAPI)/$$process.swagger.json; \
go run $(DOCS_ROOT)/tools/jsonnet/json2yaml.go $(DOCS_OPENAPI)/$$process.swagger.json $(DOCS_OPENAPI)/$$process.swagger.yaml; \
rm $(DOCS_OPENAPI)/$$process.swagger.json; \
done; \
}
@git add $(DOCS_OPENAPI)
@git add $(GIT_ROOT)/api/gen/*
go-generate:
@echo Generating go code
@./scripts/go_generate.sh
go-mod-tidy:
@echo Download go.mod dependencies
@./scripts/go_mod_tidy.sh
go-test:
@echo Running go tests
@{ \
export KUBEBUILDER_ASSETS=$(shell make operator-setup_envtest -s); \
PKGS=$$(go list ./...); \
gotestsum \
--format=pkgname \
--packages="$${PKGS}" \
-- \
-ldflags='-extldflags "-Wl,--allow-multiple-definition"'; \
}
go-lint:
@echo Linting go code
@./scripts/golangci_lint.sh --fix
go-build:
@echo Building go code
@./scripts/go_build.sh
go-build-plugins:
@echo Building go plugins
@./scripts/go_build_plugins.sh
install-asdf-tools:
@./scripts/install_asdf_tools.sh setup
install-go-tools:
@./scripts/install_go_tools.sh
install-node-tools:
@./scripts/install_node_tools.sh
install-python-tools:
@./scripts/install_python_tools.sh
go-generate-swagger:
@echo Generating swagger code
@echo Generating swagger specs from go code
@./scripts/go_generate_swagger.sh
generate-docs: generate-helm-readme generate-doc-assets generate-aperturectl-docs generate-otel-docs generate-code-snippets
@echo Generating docs
generate-config-markdown: go-generate-swagger generate-api
@cd ./docs && $(MAKE) generate-config-markdown
generate-helm-readme:
@echo Generating helm readme
@cd ./manifests/charts && $(MAKE) generate-helm-readme
helm-lint:
@echo helm lint
@cd ./manifests/charts && $(MAKE) helm-lint
generate-blueprints: generate-config-markdown
@echo Generating blueprints
@./scripts/generate_blueprints.sh
generate-doc-assets: generate-blueprints
@cd ./docs && $(MAKE) generate-jsonnet
@cd ./docs && $(MAKE) generate-mermaid
generate-aperturectl-docs:
@cd ./docs && $(MAKE) generate-aperturectl-docs
generate-code-snippets:
@echo Generating code snippets
cd ./docs && $(MAKE) generate-code-snippets
generate-otel-docs:
@cd ./docs && $(MAKE) generate-otel-docs
coverage_profile:
gotestsum --format=testname -- -coverpkg=./... -coverprofile=profile.coverprofile ./...
show_coverage_in_browser: profile.coverprofile
go tool cover -html profile.coverprofile
pre-commit-checks:
@echo Running pre-commit checks
@pre-commit run --all-files
extensions_md5sum:
@echo Resetting extensions.go checksum
@scripts/precommit/check-extensions-go.sh generate
all: install-tools generate-api go-generate go-mod-tidy go-lint go-build go-build-plugins go-test generate-docs generate-helm-readme generate-blueprints helm-lint pre-commit-checks
@echo "Done"
.PHONY: install-tools install-asdf-tools install-go-tools install-python-tools generate-api go-generate go-generate-swagger go-mod-tidy generate-config-markdown generate-doc-assets generate-docs go-test go-lint go-build go-build-plugins coverage_profile show_coverage_in_browser generate-helm-readme helm-lint generate-blueprints pre-commit-checks generate-aperturectl-docs extensions_md5sum
#####################################
###### OPERATOR section starts ######
#####################################
# IMAGE_TAG_BASE defines the docker.io namespace and part of the image name for remote images.
IMAGE_TAG_BASE ?= fluxninja/aperture-operator
# USE_IMAGE_DIGESTS defines if images are resolved via tags or digests
# You can enable this value if you would like to use SHA Based Digests
# To enable set flag to true
USE_IMAGE_DIGESTS ?= false
ifeq ($(USE_IMAGE_DIGESTS), true)
BUNDLE_GEN_FLAGS += --use-image-digests
endif
# Image URL to use all building/pushing image targets
IMG ?= aperture-operator:latest
# ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary.
ENVTEST_K8S_VERSION = 1.26
# 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
# Setting SHELL to bash allows bash commands to be executed by recipes.
# This is a requirement for 'setup-envtest.sh' in the test target.
# 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: operator-all
operator-all: operator-build
##@ 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 commands 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: operator-help
operator-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: operator-manifests
operator-manifests: ## Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects.
$(CONTROLLER_GEN) rbac:roleName=manager-role crd:ignoreUnexportedFields=true,allowDangerousTypes=true webhook paths="./operator/..." output:crd:artifacts:config=operator/config/crd/bases output:rbac:artifacts:config=operator/config/rbac output:webhook:artifacts:config=operator/config/webhook
./operator/hack/create_policy_sample.sh
cp ./operator/config/crd/bases/fluxninja.com_agents.yaml ./manifests/charts/aperture-agent/crds/fluxninja.com_agents.yaml
cp ./operator/config/crd/bases/fluxninja.com_controllers.yaml ./manifests/charts/aperture-controller/crds/fluxninja.com_controllers.yaml
cp ./operator/config/crd/bases/fluxninja.com_policies.yaml ./manifests/charts/aperture-controller/crds/fluxninja.com_policies.yaml
.PHONY: operator-generate
operator-generate: ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
$(CONTROLLER_GEN) object:headerFile="operator/hack/boilerplate.go.txt" paths="./cmd/..."
$(CONTROLLER_GEN) object:headerFile="operator/hack/boilerplate.go.txt" paths="./pkg/..."
$(CONTROLLER_GEN) object:headerFile="operator/hack/boilerplate.go.txt" paths="./operator/..."
$(CONTROLLER_GEN) object:headerFile="operator/hack/boilerplate.go.txt" paths="./extensions/..."
.PHONY: operator-fmt
operator-fmt: ## Run go fmt against code.
go fmt ./operator/...
.PHONY: operator-vet
operator-vet: ## Run go vet against code.
go vet ./operator/...
.PHONY: operator-test
operator-test: operator-manifests operator-generate operator-fmt operator-vet ## Run tests.
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) -p path)" \
go test ./operator/... \
-coverprofile operator/cover.out
.PHONY: operator-setup_envtest
operator-setup_envtest: ## Run tests.
echo "$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) -p path)"
##@ Build
.PHONY: operator-build
operator-build: operator-generate operator-fmt operator-vet ## Build manager binary.
go build \
-o bin/manager \
operator/main.go
.PHONY: operator-run
operator-run: operator-manifests operator-generate operator-fmt operator-vet ## Run a controller from your host.
go run ./operator/main.go
.PHONY: operator-docker-build
operator-docker-build: operator-test ## Build docker image with the manager.
docker build -t ${IMG} ./ -f operator/Dockerfile
##@ Deployment
ifndef ignore-not-found
ignore-not-found = false
endif
.PHONY: operator-install
operator-install: operator-manifests ## Install CRDs into the K8s cluster specified in ~/.kube/config.
$(KUSTOMIZE) build operator/config/crd | kubectl apply -f -
.PHONY: operator-uninstall
operator-uninstall: operator-manifests ## Uninstall CRDs from the K8s cluster specified in ~/.kube/config. Call with ignore-not-found=true to ignore resource not found errors during deletion.
$(KUSTOMIZE) build operator/config/crd | kubectl delete --ignore-not-found=$(ignore-not-found) -f -
.PHONY: operator-deploy
operator-deploy: operator-manifests ## Deploy controller to the K8s cluster specified in ~/.kube/config.
cd operator/config/manager && $(KUSTOMIZE) edit set image controller=${IMG}
$(KUSTOMIZE) build operator/config/default | kubectl create -f -
.PHONY: operator-undeploy
operator-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.
$(KUSTOMIZE) build operator/config/default | kubectl delete --ignore-not-found=$(ignore-not-found) -f -
##@ Build Dependencies
## Tool Binaries
KUSTOMIZE ?= kustomize
CONTROLLER_GEN ?= controller-gen
ENVTEST ?= setup-envtest
#####################################
###### OPERATOR section ends ########
#####################################