-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathMakefile
More file actions
204 lines (170 loc) · 7.18 KB
/
Makefile
File metadata and controls
204 lines (170 loc) · 7.18 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
############
# DEFAULTS #
############
PROJECT_DIR := $(shell dirname $(abspath $(lastword $(MAKEFILE_LIST))))
#########
# TOOLS #
#########
LOCALBIN := $(PWD)/bin
CODEGEN_VERSION := v0.34.0
CODEGEN = $(shell pwd)/bin/code-generator
CODEGEN_ROOT = $(shell go env GOMODCACHE)/k8s.io/code-generator@$(CODEGEN_VERSION)
CONTROLLER_TOOLS_VERSION ?= v0.19.0
CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen
GEN_CRD_API_REFERENCE_DOCS ?= $(LOCALBIN)/crd-ref-docs
GEN_CRD_API_REFERENCE_DOCS_VERSION ?= latest
HELM ?= $(LOCALBIN)/helm
HELM_VERSION ?= v3.17.3
HELM_DOCS ?= $(TOOLS_DIR)/helm-docs
HELM_DOCS_VERSION ?= v1.14.2
CLIENT_GEN ?= $(LOCALBIN)/client-gen
LISTER_GEN ?= $(LOCALBIN)/lister-gen
INFORMER_GEN ?= $(LOCALBIN)/informer-gen
REGISTER_GEN ?= $(LOCALBIN)/register-gen
REGISTER_GEN ?= $(LOCALBIN)/register-gen
CODE_GEN_VERSION := v0.33.1
SED := $(shell if [ "$(GOOS)" = "darwin" ]; then echo "gsed"; else echo "sed"; fi)
$(HELM):
@echo Install helm... >&2
@GOBIN=$(LOCALBIN) go install helm.sh/helm/v3/cmd/helm@$(HELM_VERSION)
$(HELM_DOCS):
@echo Install helm-docs... >&2
@GOBIN=$(LOCALBIN) go install github.com/norwoodj/helm-docs/cmd/helm-docs@$(HELM_DOCS_VERSION)
$(GEN_CRD_API_REFERENCE_DOCS):
test -s $(LOCALBIN)/crd-ref-docs && $(LOCALBIN)/crd-ref-docs --version | grep -q $(GEN_CRD_API_REFERENCE_DOCS_VERSION) || \
GOBIN=$(LOCALBIN) go install github.com/elastic/crd-ref-docs@$(GEN_CRD_API_REFERENCE_DOCS_VERSION)
$(CONTROLLER_GEN):
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)
$(CLIENT_GEN):
@echo Install client-gen... >&2
@GOBIN=$(LOCALBIN) go install k8s.io/code-generator/cmd/client-gen@$(CODE_GEN_VERSION)
$(LISTER_GEN):
@echo Install lister-gen... >&2
@GOBIN=$(LOCALBIN) go install k8s.io/code-generator/cmd/lister-gen@$(CODE_GEN_VERSION)
$(INFORMER_GEN):
@echo Install informer-gen... >&2
@GOBIN=$(LOCALBIN) go install k8s.io/code-generator/cmd/informer-gen@$(CODE_GEN_VERSION)
$(REGISTER_GEN):
@echo Install register-gen... >&2
@GOBIN=$(LOCALBIN) go install k8s.io/code-generator/cmd/register-gen@$(CODE_GEN_VERSION)
.PHONY: install-tools
install-tools: ## Install tools
install-tools: $(HELM)
install-tools: $(GEN_CRD_API_REFERENCE_DOCS)
install-tools: $(CONTROLLER_GEN)
install-tools: $(REGISTER_GEN)
.PHONY: clean-tools
clean-tools: ## Remove installed tools
@echo Clean tools... >&2
@rm -rf $(LOCALBIN)
###########
# CODEGEN #
###########
codegen-crds: ## Generate CRDs
codegen-crds: $(CONTROLLER_GEN)
@echo Generate CRDs... >&2
@$(CONTROLLER_GEN) paths=./apis/... crd:crdVersions=v1,ignoreUnexportedFields=true,generateEmbeddedObjectMeta=false
codegen-deepcopy: ## Generate deep copy functions
codegen-deepcopy: $(CONTROLLER_GEN)
@echo Generate deep copy functions... >&2
@$(CONTROLLER_GEN) paths=./apis/... object
codegen-rbac: ## Generate rbac
codegen-rbac: $(CONTROLLER_GEN)
@echo Generate rbac... >&2
@$(CONTROLLER_GEN) paths=./apis/... rbac:roleName=manager-role
codegen-client-applyconfigurations: ## Generate apply configs
codegen-client-applyconfigurations: $(CONTROLLER_GEN)
@echo Generate apply configs... >&2
@$(CONTROLLER_GEN) paths=./apis/... applyconfiguration
codegen-client-clientset: ## Generate clientset
codegen-client-clientset: $(CLIENT_GEN)
@echo Generate clientset... >&2
@rm -rf ./pkg/client/clientset && mkdir -p ./pkg/client/clientset
@$(CLIENT_GEN) \
--clientset-name versioned \
--apply-configuration-package github.com/openreports/reports-api/pkg/client/applyconfiguration \
--output-dir ./pkg/client/clientset \
--output-pkg github.com/openreports/reports-api/pkg/client/clientset \
--input-base github.com/openreports/reports-api \
--input ./apis/openreports.io/v1alpha1
codegen-client-listers: ## Generate listers
codegen-client-listers: $(LISTER_GEN)
@echo Generate listers... >&2
@rm -rf ./pkg/client/listers && mkdir -p ./pkg/client/listers
@$(LISTER_GEN) \
--output-dir ./pkg/client/listers \
--output-pkg github.com/openreports/reports-api/pkg/client/listers \
./apis/...
codegen-client-informers: ## Generate informers
codegen-client-informers: $(INFORMER_GEN)
@echo Generate informers... >&2
@rm -rf ./pkg/client/informers && mkdir -p ./pkg/client/informers
@$(INFORMER_GEN) \
--output-dir ./pkg/client/informers \
--output-pkg github.com/openreports/reports-api/pkg/client/informers \
--versioned-clientset-package github.com/openreports/reports-api/pkg/client/clientset/versioned \
--listers-package github.com/openreports/reports-api/pkg/client/listers \
./apis/...
codegen-client: ## Generate client
codegen-client: codegen-client-applyconfigurations
codegen-client: codegen-client-informers
codegen-client: codegen-client-listers
codegen-client: codegen-client-clientset
codegen-api-docs: ## Generate API docs
codegen-api-docs: $(GEN_CRD_API_REFERENCE_DOCS)
@echo Generate api docs... >&2
@$(GEN_CRD_API_REFERENCE_DOCS) --source-path=./apis --config=./docs/config.yaml --renderer=markdown --output-path=./docs/api-docs.md
codegen-helm-crds: ## Copy CRDs in helm chart
codegen-helm-crds: codegen-crds
@echo Copy CRDs... >&2
@cp config/crd/*.yaml charts/openreports/templates/
.PHONY: codegen-helm-docs
codegen-helm-docs: ## Generate helm docs
@echo Generate helm docs... >&2
@docker run -v ${PWD}/chart:/work -w /work jnorwood/helm-docs:$(HELM_DOCS_VERSION) -s file
codegen-release-manifest: ## Generate release manifest
codegen-release-manifest: $(HELM)
codegen-release-manifest: codegen-helm-crds
@echo Generate release manifests... >&2
@$(HELM) template openreports charts/openreports \
| $(SED) -e '/^#.*/d' > ./config/install.yaml
codegen: ## Build all generated code
codegen: codegen-crds
codegen: codegen-deepcopy
codegen: codegen-rbac
codegen: codegen-api-docs
codegen: codegen-client
codegen: codegen-helm-crds
codegen: codegen-release-manifest
codegen: codegen-helm-docs
verify-codegen: ## Verify all generated code and docs are up to date
verify-codegen: codegen
@echo Run go mod tidy... >&2
@go mod tidy
@echo Checking codegen is up to date... >&2
@git --no-pager diff -- .
@echo 'If this test fails, it is because the git diff is non-empty after running "make codegen".' >&2
@echo 'To correct this, locally run "make codegen", commit the changes, and re-run tests.' >&2
@git diff --quiet --exit-code -- .
#########
# BUILD #
#########
fmt: ## Run go fmt against code
fmt: codegen
@echo Format code... >&2
@go fmt ./...
vet: ## Run go vet against code
vet: fmt
@echo Vet code... >&2
@go vet ./...
build: ## Run go build against code
build: vet
@echo Build code... >&2
@go build ./...
########
# HELP #
########
.PHONY: help
help: ## Shows the available commands
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-40s\033[0m %s\n", $$1, $$2}'