-
Notifications
You must be signed in to change notification settings - Fork 12
/
Makefile
271 lines (234 loc) · 7.45 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
# Image URL to use all building/pushing image targets
VERSION?=v0.8.1
IMG?=fintechstudios/ververica-platform-k8s-operator
PKG=github.com/fintechstudios.com/ververica-platform-k8s-operator
VERSION_PKG=main
BUILD=$(shell date -u +'%Y-%m-%dT%H:%M:%SZ')
# Produce CRDs that work back to Kubernetes 1.11 (no version conversion)
CRD_OPTIONS?="crd"
DOCKER_REPO=fintechstudios/ververica-platform-k8s-operator
LD_FLAGS="-X $(VERSION_PKG).operatorVersion='$(VERSION)' -X $(VERSION_PKG).gitCommit='$(GIT_COMMIT)' -X $(VERSION_PKG).buildDate='$(BUILD)'"
TEST_CLUSTER_NAME=ververica-platform-k8s-operator-cluster
# 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
all: manager
# find or download controller-gen
.PHONY: controller-gen
controller-gen:
ifeq (, $(shell which controller-gen))
@{ \
set -e ;\
CONTROLLER_GEN_TMP_DIR=$$(mktemp -d) ;\
cd $$CONTROLLER_GEN_TMP_DIR ;\
go mod init tmp ;\
go get sigs.k8s.io/controller-tools/cmd/[email protected] ;\
rm -rf $$CONTROLLER_GEN_TMP_DIR ;\
}
CONTROLLER_GEN=$(GOBIN)/controller-gen
else
CONTROLLER_GEN=$(shell which controller-gen)
endif
# find or download kustomize
.PHONY: kustomize
kustomize:
ifeq (, $(shell which kustomize))
@{ \
set -e ;\
KUSTOMIZE_TMP_DIR=$$(mktemp -d) ;\
cd $$KUSTOMIZE_TMP_DIR ;\
go mod init tmp ;\
go get sigs.k8s.io/kustomize/kustomize/[email protected] ;\
rm -rf $$KUSTOMIZE_TMP_DIR ;\
}
KUSTOMIZE=$(GOBIN)/kustomize
else
KUSTOMIZE=$(shell which kustomize)
endif
# find or download kind
.PHONY: kind
kind:
ifeq (, $(shell which kind))
@{ \
set -e ;\
KIND_TMP_DIR=$$(mktemp -d) ;\
cd $$KIND_TMP_DIR ;\
go mod init tmp ;\
go get sigs.k8s.io/[email protected] ;\
rm -rf $$KIND_TMP_DIR ;\
}
KIND=$(GOBIN)/kind
else
KIND=$(shell which kind)
endif
# find or download mocker
.PHONY: mockery
mockery:
ifeq (, $(shell which mockery))
@{ \
set -e ;\
MOCKERY_TMP_DIR=$$(mktemp -d) ;\
cd $$MOCKERY_TMP_DIR ;\
go mod init tmp ;\
go get github.com/vektra/mockery/.../ ;\
rm -rf $$MOCKERY_TMP_DIR ;\
}
MOCKERY=$(GOBIN)/mockery
else
MOCKERY=$(shell which mockery)
endif
# Run tests
.PHONY: test
test: generate manifests
go test -ldflags $(LD_FLAGS) ./pkg/... ./api/... ./controllers/... ./ -coverprofile cover.out
# Build manager binary
.PHONY: manager
manager: generate
go build $(ARGS) -ldflags $(LD_FLAGS) -o bin/manager main.go
mocks: mockery
rm -rf mocks \
&& $(MOCKERY) -dir pkg/vvp/appmanager -all -output ./mocks/vvp/appmanager -case=underscore \
&& $(MOCKERY) -dir pkg/vvp/platform -all -output ./mocks/vvp/platform -case=underscore
# Run against the configured Kubernetes cluster in ~/.kube/config
.PHONY: run
run: generate
go run -ldflags $(LD_FLAGS) ./main.go
# Install CRDs into a cluster
.PHONY: install
install: manifests
$(KUSTOMIZE) build config/crd | kubectl apply -f -
# Uninstall CRDs from a cluster
uninstall: manifests
$(KUSTOMIZE) build config/crd | kubectl delete -f -
# Deploy controller in the configured Kubernetes cluster in ~/.kube/config
.PHONY: deploy
deploy: manifests
cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG}
$(KUSTOMIZE) build config/default | kubectl apply -f -
# Generate manifests e.g. CRD, RBAC etc.
.PHONY: manifests
manifests: controller-gen
$(CONTROLLER_GEN) $(CRD_OPTIONS) rbac:roleName=manager-role webhook paths="./..." output:crd:artifacts:config=config/crd/bases
# Run gofmt against non-generated code
.PHONY: fmt
fmt:
gofmt -s -w ./api ./controllers ./pkg *.go
.PHONY: lint
lint:
golangci-lint run --timeout=120s --verbose
# Generate code
.PHONY: generate
generate: controller-gen
$(CONTROLLER_GEN) object:headerFile=./hack/boilerplate.go.txt paths=./api/...
# Patch the latest image version into the default kustomize image patch
.PHONY: patch-image
patch-image:
sed -i'' -e 's@image: .*@image: '"$(IMG):$(VERSION)"'@' ./config/default/manager_image_patch.yaml
# Build the k8s resources for deployment
.PHONY: kustomize-build
kustomize-build: patch-image
rm -f resources.yaml && $(KUSTOMIZE) build config/default > resources.yaml
# Update the Swagger Client API
.PHONY: swagger-gen
swagger-gen:
./hack/update-app-manager-swagger-codegen.sh \
&& ./hack/update-platform-swagger-codegen.sh
.PHONY: docker-build-image
docker-build-image:
docker build -f build.Dockerfile \
--cache-from $(DOCKER_REPO)-builder:$(VERSION) \
--tag $(DOCKER_REPO)-builder:$(VERSION) \
.
.PHONY: docker-build
docker-build: docker-build-image
docker build \
--build-arg BUILD_IMG=$(DOCKER_REPO)-builder:$(VERSION) \
--build-arg GIT_COMMIT=$(GIT_COMMIT) \
--build-arg VERSION=$(VERSION) \
--cache-from $(DOCKER_REPO):$(VERSION) \
-f Dockerfile \
--tag $(DOCKER_REPO):$(VERSION) \
.
.PHONY: test-cluster-load-image
test-cluster-load-image: kind
$(KIND) load docker-image --name $(TEST_CLUSTER_NAME) $(DOCKER_REPO):$(VERSION)
# Create the test cluster using kind
# install local path storage as defult storage class (see: https://github.com/kubernetes-sigs/kind/issues/118#issuecomment-475134086)
.PHONY: test-cluster-create kind
test-cluster-create:
$(KIND) create cluster --name $(TEST_CLUSTER_NAME)
# Delete the test cluster using kind
.PHONY: test-cluster-delete kind
test-cluster-delete:
$(KIND) delete cluster --name $(TEST_CLUSTER_NAME)
.PHONY: test-cluster-install-vvp-enterprise
test-cluster-install-vvp-enterprise:
. ./hack/helm-init.sh \
&& helm upgrade --install \
--version 4.0.0 \
--namespace vvp \
--set vvp.persistence.type=local \
vvp \
ververica/ververica-platform \
$(HELM_EXTRA_ARGS)
.PHONY: test-cluster-install-vvp-community
test-cluster-install-vvp-community:
. ./hack/helm-init.sh \
&& helm upgrade --install \
--version 4.0.0 \
--namespace vvp \
--set vvp.persistence.type=local \
--set acceptCommunityEditionLicense=true \
vvp \
ververica/ververica-platform \
$(HELM_EXTRA_ARGS)
.PHONY: test-cluster-install-cert-manager
test-cluster-install-cert-manager:
kubectl apply \
--validate=false \
-f https://github.com/jetstack/cert-manager/releases/download/v0.14.1/cert-manager.crds.yaml \
&& . ./hack/helm-init.sh \
&& helm upgrade --install \
--version v0.14.1 \
--namespace cert-manager \
cert-manager \
jetstack/cert-manager
.PHONY: test-cluster-install-chart
test-cluster-install-chart: docker-build test-cluster-load-image
. ./hack/helm-init.sh \
&& helm upgrade --install \
--namespace vvp \
vp-k8s-operator \
./charts/vp-k8s-operator \
--set imageRepository=$(DOCKER_REPO) \
--set imageTag=$(VERSION) \
--set vvpEdition=community \
--set vvpUrl=http://vvp-ververica-platform \
$(HELM_EXTRA_ARGS)
.PHONY: test-cluster-install-crds
test-cluster-install-crds:
. ./hack/helm-init.sh \
&& helm upgrade --install \
--namespace vvp \
vp-k8s-operator-crds \
./charts/vp-k8s-operator-crds \
--set webhookCert.name=vp-k8s-operator-serving-cert \
--set webhookService.name=vp-k8s-operator-webhook-service \
$(HELM_EXTRA_ARGS)
.PHONY: test-cluster-wait-for-cert-manager
test-cluster-wait-for-cert-manager:
kubectl -n cert-manager wait --for=condition=available deployments --all
.PHONY: test-cluster-wait-for-vvp
test-cluster-wait-for-vvp:
kubectl -n vvp wait --for=condition=available deployments --all
# Requires tiller to be running
.PHONY: test-cluster-setup
test-cluster-setup: test-cluster-install-cert-manager \
test-cluster-install-vvp-community \
test-cluster-wait-for-cert-manager \
test-cluster-wait-for-vvp \
test-cluster-install-chart \
test-cluster-install-crds