-
Notifications
You must be signed in to change notification settings - Fork 31
/
Makefile
225 lines (198 loc) · 5.51 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
# Copyright 2021 Alibaba Group Holding Limited.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
PRINT_HELP ?=
CURRENT_YEAR=$(shell date +"%Y")
## Location to install dependencies to
LOCALBIN ?= $(shell pwd)/bin
$(LOCALBIN):
mkdir -p $(LOCALBIN)
## Tool Binaries
CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen
## Tool Versions
CONTROLLER_TOOLS_VERSION ?= v0.16.1
define ALL_HELP_INFO
# Build code.
#
# Example:
# make
# make all
# make all TARGET=cmd/hpfs
endef
export ALL_HELP_INFO
.PHONY: target
all: target
ifeq ($(PRINT_HELP), y)
target:
@echo "$$ALL_HELP_INFO"
else
target: plugin-gen
@hack/make-rules/build.py $(TARGET)
endif
.PHONY: fmt
fmt:
@go fmt ./...
.PHONY: lint
lint:
@go vet ./...
.PHONY: clean
clean:
@rm -rf target
BUILD_IMAGE_ARGS=
ifneq (, $(REPO))
BUILD_IMAGE_ARGS:=${BUILD_IMAGE_ARGS} --repo $(REPO)
endif
ifneq (, $(TAG))
BUILD_IMAGE_ARGS:=${BUILD_IMAGE_ARGS} --tag $(TAG)
endif
ifneq (, $(LATEST))
BUILD_IMAGE_ARGS:=${BUILD_IMAGE_ARGS} --also-latest
endif
ifneq (, $(IMAGE_SOURCE))
BUILD_IMAGE_ARGS:=${BUILD_IMAGE_ARGS} --image-source $(IMAGE_SOURCE)
endif
ifneq (, $(TARGET))
BUILD_IMAGE_ARGS:=${BUILD_IMAGE_ARGS} $(TARGET)
endif
E2E_PARALLELISM=3
define BUILD_IMAGES_HELP_INFO
# Build images.
#
# Example:
# make build
# make build TARGET=cmd/hpfs
# make build REPO=registry.aliyun.com/custom
# make build REPO=registry.aliyun.com/custom TARGET=cmd/hpfs
# make build REPO=registry.aliyun.com/custom IMAGE_SOURCE=docker.io/custom
# make build REPO=... IMAGE_SOURCE=... TARGET=... TAG=... TARGET=...
endef
export BUILD_IMAGES_HELP_INFO
.PHONY: build
ifeq ($(PRINT_HELP), y)
build:
@echo "$$BUILD_IMAGES_HELP_INFO"
else
build: plugin-gen
@hack/make-rules/build-images.py ${BUILD_IMAGE_ARGS}
endif
define PUSH_IMAGES_HELP_INFO
# Build & push images.
#
# Example:
# make push
# make push TARGET=cmd/hpfs
# make push REPO=registry.aliyun.com/custom
# make push REPO=registry.aliyun.com/custom TARGET=cmd/hpfs
# make push REPO=registry.aliyun.com/custom IMAGE_SOURCE=docker.io/custom
# make push REPO=... IMAGE_SOURCE=... TARGET=... TAG=... TARGET=...
endef
export PUSH_IMAGES_HELP_INFO
.PHONY: push
ifeq ($(PRINT_HELP), y)
push:
@echo "$$PUSH_IMAGES_HELP_INFO"
else
push: plugin-gen
@hack/make-rules/build-images.py --push ${BUILD_IMAGE_ARGS}
endif
define GENERATE_HELP_INFO
# Generate files.
#
# Example:
# make generate
endef
.PHONY: generate
ifeq ($(PRINT_HELP), y)
generate:
@echo "$$GENERATE_HELP_INFO"
else
generate:
@go generate ./... && go fmt ./...
endif
.PHONY: plugin-gen
plugin-gen:
@go generate ./pkg/operator/v1/xstore/plugin
.PHONY: controller-gen
controller-gen: download-controller-gen
$(CONTROLLER_GEN) object:headerFile="hack/boilerplates/boilerplate.go.txt",year=$(CURRENT_YEAR) paths="./api/..."
@go fmt ./api/...
define UPDATE_VENDOR_LICENSES_HELP_INFO
# Update vendor and vendor licenses.
#
# Examples:
# make update-vendor-licenses
endef
.PHONY: update-vendor-licenses
ifeq ($(PRINT_HELP), y)
update-vendor-licenses:
@echo "$$UPDATE_VENDOR_LICENSES_HELP_INFO"
else
update-vendor-licenses:
@hack/make-rules/update-vendor-licenses.py
endif
define UNIT_TEST_HELP_INFO
# Run unit tests.
#
# Examples:
# make unit-test
endef
.PHONY: unit-test
ifeq ($(PRINT_HELP), y)
unit-test:
@echo "$$UNIT_TEST_HELP_INFO"
else
unit-test:
@go test -v -short `go list ./... | grep -v "/third-party"`
endif
define E2E_TEST_HELP_INFO
# Run e2e tests.
#
# Examples:
# make e2e-test
endef
.PHONY: e2e-test
ifeq ($(PRINT_HELP), y)
e2e-test:
@echo "$$E2E_TEST_HELP_INFO"
else
# @go test ./test/e2e -v -args timeout 6000 -ginkgo.progress -ginkgo.v
e2e-test:
@ginkgo -nodes=${E2E_PARALLELISM} -v -progress -p ./test/e2e
endif
.PHONY: manifests
manifests: controller-gen
$(CONTROLLER_GEN) crd:crdVersions=v1 rbac:roleName=manager-role webhook paths="./api/..." output:crd:artifacts:config=charts/polardbx-operator/crds
.PHONY: generate-notice
generate-notice:
@hack/make-rules/generate-notice.py
.PHONY: verify-boilerplates
verify-boilerplates:
@hack/make-rules/verify-boilerplates.py --language go --include-dirs api,cmd,pkg,test --exclude-dirs vendor --start-year 2021
@hack/make-rules/verify-boilerplates.py --language bash --exclude-dirs vendor --start-year 2021
@hack/make-rules/verify-boilerplates.py --language python --exclude-dirs vendor,tools/xstore/venv --start-year 2021
.PHONY: helm-package
helm-package:
@mkdir -p target/charts
@helm package charts/polardbx-operator -d target/charts
@helm package charts/polardbx-monitor -d target/charts
@helm package charts/polardbx-logcollector -d target/charts
.PHONY: download-controller-gen
download-controller-gen: $(LOCALBIN) ## Download controller-gen locally if necessary.
@{ \
set -e ;\
if [ ! -f "$(CONTROLLER_GEN)" ] || [ "$$($(CONTROLLER_GEN) --version 2>&1 | awk '{print $$NF}')" != "$(CONTROLLER_TOOLS_VERSION)" ]; then \
echo 'Installing controller-gen@$(CONTROLLER_TOOLS_VERSION)...' ;\
GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-tools/cmd/controller-gen@$(CONTROLLER_TOOLS_VERSION) ;\
echo 'Successfully installed' ;\
fi \
}