-
-
Notifications
You must be signed in to change notification settings - Fork 35
/
Makefile
276 lines (222 loc) · 13.1 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
274
275
276
# ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary.
ENVTEST_K8S_VERSION = 1.28.0
# 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
UNAME=$(shell uname -s)
VERSION ?= "$(shell cat VERSION)"
# 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: all
all: 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: 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
YAML_PREFIX=spec.versions[0].schema.openAPIV3Schema.properties.spec.properties
CRD_PRESERVE=x-kubernetes-preserve-unknown-fields = true
.PHONY: manifests
manifests: controller-gen yq ## Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects.
$(CONTROLLER_GEN) rbac:roleName=manager-role crd webhook paths="./..." output:crd:artifacts:config=config/crd/bases
$(YQ) -i 'del(.$(YAML_PREFIX).services.properties.frontend.properties.initContainers.items.properties)' ./config/crd/bases/temporal.io_temporalclusters.yaml
$(YQ) -i 'del(.$(YAML_PREFIX).services.properties.frontend.properties.initContainers.items.required)' ./config/crd/bases/temporal.io_temporalclusters.yaml
$(YQ) -i '.$(YAML_PREFIX).services.properties.frontend.properties.initContainers.items.$(CRD_PRESERVE)' ./config/crd/bases/temporal.io_temporalclusters.yaml
$(YQ) -i 'del(.$(YAML_PREFIX).services.properties.history.properties.initContainers.items.properties)' ./config/crd/bases/temporal.io_temporalclusters.yaml
$(YQ) -i 'del(.$(YAML_PREFIX).services.properties.history.properties.initContainers.items.required)' ./config/crd/bases/temporal.io_temporalclusters.yaml
$(YQ) -i '.$(YAML_PREFIX).services.properties.history.properties.initContainers.items.$(CRD_PRESERVE)' ./config/crd/bases/temporal.io_temporalclusters.yaml
$(YQ) -i 'del(.$(YAML_PREFIX).services.properties.matching.properties.initContainers.items.properties)' ./config/crd/bases/temporal.io_temporalclusters.yaml
$(YQ) -i 'del(.$(YAML_PREFIX).services.properties.matching.properties.initContainers.items.required)' ./config/crd/bases/temporal.io_temporalclusters.yaml
$(YQ) -i '.$(YAML_PREFIX).services.properties.matching.properties.initContainers.items.$(CRD_PRESERVE)' ./config/crd/bases/temporal.io_temporalclusters.yaml
$(YQ) -i 'del(.$(YAML_PREFIX).services.properties.internalFrontend.properties.initContainers.items.properties)' ./config/crd/bases/temporal.io_temporalclusters.yaml
$(YQ) -i 'del(.$(YAML_PREFIX).services.properties.internalFrontend.properties.initContainers.items.required)' ./config/crd/bases/temporal.io_temporalclusters.yaml
$(YQ) -i '.$(YAML_PREFIX).services.properties.internalFrontend.properties.initContainers.items.$(CRD_PRESERVE)' ./config/crd/bases/temporal.io_temporalclusters.yaml
$(YQ) -i 'del(.$(YAML_PREFIX).services.properties.worker.properties.initContainers.items.properties)' ./config/crd/bases/temporal.io_temporalclusters.yaml
$(YQ) -i 'del(.$(YAML_PREFIX).services.properties.worker.properties.initContainers.items.required)' ./config/crd/bases/temporal.io_temporalclusters.yaml
$(YQ) -i '.$(YAML_PREFIX).services.properties.worker.properties.initContainers.items.$(CRD_PRESERVE)' ./config/crd/bases/temporal.io_temporalclusters.yaml
$(YQ) -i 'del(.$(YAML_PREFIX).jobInitContainers.items.properties)' ./config/crd/bases/temporal.io_temporalclusters.yaml
$(YQ) -i 'del(.$(YAML_PREFIX).jobInitContainers.items.required)' ./config/crd/bases/temporal.io_temporalclusters.yaml
$(YQ) -i '.$(YAML_PREFIX).jobInitContainers.items.$(CRD_PRESERVE)' ./config/crd/bases/temporal.io_temporalclusters.yaml
.PHONY: generate
generate: controller-gen api-docs ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..."
.PHONY: api-docs
api-docs: gen-crd-api-reference-docs ## Generate API reference documentation
$(GEN_CRD_API_REFERENCE_DOCS) -api-dir=./api/v1beta1 -config=./hack/api/config.json -template-dir=./hack/api/template -out-file=./docs/api/v1beta1.md
.PHONY: fmt
fmt: ## Run go fmt against code.
go fmt ./...
.PHONY: vet
vet: ## Run go vet against code.
go vet ./...
.PHONY: lint
lint: golangci-lint ## Run golang-ci-lint against code.
$(GOLANGCI_LINT) run ./...
.PHONY: test
test: manifests generate fmt vet envtest ## Run tests.
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" go test $$(go list ./... | grep -v /tests/e2e) -coverprofile cover.out
.PHONY: test-e2e
test-e2e: artifacts ## Run end2end tests.
go test ./tests/e2e -v -timeout 60m -args "--v=4"
.PHONY: test-e2e-dev
test-e2e-dev: artifacts ## Run end2end tests on dev computer using kind.
docker build -t temporal-operator .
docker save temporal-operator > /tmp/temporal-operator.tar
OPERATOR_IMAGE_PATH=/tmp/temporal-operator.tar go test ./tests/e2e -v -timeout 60m -args "--v=4"
.PHONY: ensure-license
ensure-license: go-licenser
$(GO_LICENSER) -licensor "Alexandre VILAIN" -exclude api -exclude pkg/version -license ASL2 .
.PHONY: check-license
check-license: go-licenser
$(GO_LICENSER) -licensor "Alexandre VILAIN" -exclude api -exclude pkg/version -license ASL2 -d .
.PHONY: dev-cluster
dev-cluster: kind-with-registry
$(KIND_WITH_REGISTRY)
.PHONY: clean-dev-cluster
clean-dev-cluster:
kind delete clusters kind
.PHONY: deploy-dev
deploy-dev: dev-cluster
tilt up
##@ Build
.PHONY: build
build: generate fmt vet ## Build manager binary.
go build -o bin/manager main.go
.PHONY: run
run: manifests generate fmt vet ## Run a controller from your host.
go run ./main.go
.PHONY: docker-build-dev
docker-build-dev: ## Build docker image with the manager.
docker build -t temporal-operator .
##@ Deployment
ifndef ignore-not-found
ignore-not-found = false
endif
.PHONY: install
install: manifests kustomize ## Install CRDs into the K8s cluster specified in ~/.kube/config.
$(KUSTOMIZE) build config/crd |kubectl apply --server-side -f -
.PHONY: uninstall
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.
$(KUSTOMIZE) build config/crd | kubectl delete --ignore-not-found=$(ignore-not-found) -f -
.PHONY: deploy
deploy: manifests kustomize ## Deploy controller to the K8s cluster specified in ~/.kube/config.
$(KUSTOMIZE) build config/default | kubectl apply -f -
.PHONY: undeploy
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 config/default | kubectl delete --ignore-not-found=$(ignore-not-found) -f -
.PHONY: artifacts
artifacts: kustomize
mkdir -p $(RELEASE_PATH)
$(KUSTOMIZE) build config/crd > ${RELEASE_PATH}/temporal-operator.crds.yaml
$(KUSTOMIZE) build config/default > ${RELEASE_PATH}/temporal-operator.yaml
.PHONY: helm
helm: helm-docs manifests artifacts
cp ${RELEASE_PATH}/temporal-operator.crds.yaml charts/temporal-operator/crds
$(HELM_DOCS) --chart-search-root=charts/temporal-operator --template-files=hack/helm/template/README.md.gotmpl
.PHONY: bundle
bundle: manifests kustomize operator-sdk ## Generate bundle manifests and metadata, then validate generated files.
$(OPERATOR_SDK) generate kustomize manifests -q
$(KUSTOMIZE) build config/manifests | $(OPERATOR_SDK) generate bundle -q --overwrite --manifests --version $(VERSION) $(BUNDLE_METADATA_OPTS)
$(OPERATOR_SDK) bundle validate ./bundle
.PHONY: prepare-release
prepare-release: kustomize
$(eval OLD_VERSION := $(shell curl -s https://api.github.com/repos/alexandrevilain/temporal-operator/releases | jq -r '.[0].tag_name'))
cd config/manager && $(KUSTOMIZE) edit set image ghcr.io/alexandrevilain/temporal-operator:v$(VERSION)
sed -i'' -e 's/replaces: temporal-operator.v.*/replaces: temporal-operator.$(OLD_VERSION)/' config/manifests/bases/temporal-operator.clusterserviceversion.yaml
$(MAKE) bundle
OPERATOR_HUB_FORK_REPOSITORY ?= [email protected]:alexandrevilain/community-operators.git
.PHONY: operatorhub
operatorhub:
VERSION=$(VERSION) FORK_REPOSITORY=$(OPERATOR_HUB_FORK_REPOSITORY) ./hack/operatorhub.sh
##@ Build Dependencies
RELEASE_PATH ?= $(shell pwd)/out/release/artifacts
## Location to install dependencies to
LOCALBIN ?= $(shell pwd)/bin
$(LOCALBIN):
mkdir -p $(LOCALBIN)
## Tool Binaries
KUSTOMIZE ?= $(LOCALBIN)/kustomize
OPERATOR_SDK ?= $(LOCALBIN)/operator-sdk
CONTROLLER_GEN ?= GOFLAGS=-mod=mod $(LOCALBIN)/controller-gen
ENVTEST ?= $(LOCALBIN)/setup-envtest
GO_LICENSER ?= $(LOCALBIN)/go-licenser
GEN_CRD_API_REFERENCE_DOCS ?= $(LOCALBIN)/gen-crd-api-reference-docs
GOLANGCI_LINT ?= $(LOCALBIN)/golangci-lint
YQ ?= $(LOCALBIN)/yq
KIND_WITH_REGISTRY ?= $(LOCALBIN)/kind-with-registry
HELM_DOCS ?= $(LOCALBIN)/helm-docs
## Tool Versions
KUSTOMIZE_VERSION ?= v4.5.7
OPERATOR_SDK_VERSION ?= 1.37.0
CONTROLLER_TOOLS_VERSION ?= v0.16.3
GO_LICENSER_VERSION ?= v0.4.0
GEN_CRD_API_REFERENCE_DOCS_VERSION ?= 3f29e6853552dcf08a8e846b1225f275ed0f3e3b
GOLANGCI_LINT_VERSION ?= v1.61.0
YQ_VERSION ?= v4.30.6
KIND_WITH_REGISTRY_VERSION ?= 0.17.0
HELM_DOCS_VERSION ?= v1.12.0
.PHONY: kustomize
kustomize: $(KUSTOMIZE) ## Download kustomize locally if necessary. If wrong version is installed, it will be removed before downloading.
$(KUSTOMIZE): $(LOCALBIN)
@if test -x $(LOCALBIN)/kustomize && ! $(LOCALBIN)/kustomize version | grep -q $(KUSTOMIZE_VERSION); then \
echo "$(LOCALBIN)/kustomize version is not expected $(KUSTOMIZE_VERSION). Removing it before installing."; \
rm -rf $(LOCALBIN)/kustomize; \
fi
test -s $(LOCALBIN)/kustomize || GOBIN=$(LOCALBIN) go install sigs.k8s.io/kustomize/kustomize/v4@${KUSTOMIZE_VERSION}
.PHONY: operator-sdk
operator-sdk: $(OPERATOR_SDK)
$(OPERATOR_SDK): $(LOCALBIN)
test -s $(LOCALBIN)/operator-sdk && $(LOCALBIN)/operator-sdk version | grep -q $(OPERATOR_SDK_VERSION) || \
curl -sLo $(OPERATOR_SDK) https://github.com/operator-framework/operator-sdk/releases/download/v${OPERATOR_SDK_VERSION}/operator-sdk_`go env GOOS`_`go env GOARCH`
@chmod +x $(OPERATOR_SDK)
.PHONY: golangci-lint
golangci-lint: $(GOLANGCI_LINT)
$(GOLANGCI_LINT): $(LOCALBIN)
test -s $(LOCALBIN)/golangci-lint && $(LOCALBIN)/golangci-lint version | grep -q $(GOLANGCI_LINT_VERSION) || \
GOBIN=$(LOCALBIN) go install github.com/golangci/golangci-lint/cmd/golangci-lint@$(GOLANGCI_LINT_VERSION)
.PHONY: go-licenser
go-licenser: $(GO_LICENSER)
$(GO_LICENSER): $(LOCALBIN)
GOBIN=$(LOCALBIN) go install github.com/elastic/go-licenser@$(GO_LICENSER_VERSION)
.PHONY: controller-gen
controller-gen: $(CONTROLLER_GEN) ## Download controller-gen locally if necessary. If wrong version is installed, it will be overwritten.
$(CONTROLLER_GEN): $(LOCALBIN)
test -s $(LOCALBIN)/controller-gen && $(LOCALBIN)/controller-gen --version | grep -q $(CONTROLLER_TOOLS_VERSION) || \
GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-tools/cmd/controller-gen@$(CONTROLLER_TOOLS_VERSION)
.PHONY: gen-crd-api-reference-docs
gen-crd-api-reference-docs: $(GEN_CRD_API_REFERENCE_DOCS) ## Download gen-crd-api-reference-docs locally if necessary.
$(GEN_CRD_API_REFERENCE_DOCS): $(LOCALBIN)
GOBIN=$(LOCALBIN) go install github.com/ahmetb/gen-crd-api-reference-docs@$(GEN_CRD_API_REFERENCE_DOCS_VERSION)
.PHONY: envtest
envtest: $(ENVTEST) ## Download envtest-setup locally if necessary.
$(ENVTEST): $(LOCALBIN)
test -s $(LOCALBIN)/setup-envtest || GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-runtime/tools/setup-envtest@latest
.PHONY: yq
yq: $(YQ)
$(YQ): $(LOCALBIN)
GOBIN=$(LOCALBIN) go install github.com/mikefarah/yq/v4@$(YQ_VERSION)
.PHONY: kind-with-registry
kind-with-registry: $(KIND_WITH_REGISTRY)
$(KIND_WITH_REGISTRY): $(LOCALBIN)
curl -sLo $(KIND_WITH_REGISTRY) https://raw.githubusercontent.com/kubernetes-sigs/kind/v$(KIND_WITH_REGISTRY_VERSION)/site/static/examples/kind-with-registry.sh
chmod +x $(KIND_WITH_REGISTRY)
.PHONY: helm-docs
helm-docs: $(HELM_DOCS) ## Generate helm documentation
$(HELM_DOCS): $(LOCALBIN)
GOBIN=$(LOCALBIN) go install github.com/norwoodj/helm-docs/cmd/helm-docs@$(HELM_DOCS_VERSION)