forked from kubernetes-sigs/application
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
338 lines (269 loc) · 9.59 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
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
# Copyright 2019 The Kubernetes Authors.
# SPDX-License-Identifier: Apache-2.0
#
# Makefile for application
VERSION_FILE ?= VERSION-DEV
include $(VERSION_FILE)
# Produce CRDs that work back to Kubernetes 1.11 (no version conversion)
CRD_OPTIONS ?= "crd:trivialVersions=true"
# Releases should modify and double check these vars.
VER ?= v${app_major}.${app_minor}.${app_patch}
ARCH ?= amd64
ALL_ARCH = amd64 arm arm64 ppc64le s390x
IMAGE_NAME = kube-app-manager
ifeq ($(ARCH), amd64)
IMAGE_TAG ?= $(VER)
else
IMAGE_TAG ?= $(ARCH)-$(VER)
endif
RELEASE_REMOTE ?= origin
RELEASE_BRANCH ?= release-v${app_major}.${app_minor}
RELEASE_TAG ?= v${app_major}.${app_minor}.${app_patch}
CONTROLLER_IMG ?= $(REGISTRY)/$(IMAGE_NAME):$(IMAGE_TAG)
# Directories.
TOOLS_DIR := $(shell pwd)/hack/tools
TOOLBIN := $(TOOLS_DIR)/bin
# Allow overriding manifest generation destination directory
MANIFEST_ROOT ?= config
CRD_ROOT ?= $(MANIFEST_ROOT)/crd/bases
WEBHOOK_ROOT ?= $(MANIFEST_ROOT)/webhook
RBAC_ROOT ?= $(MANIFEST_ROOT)/rbac
COVER_FILE ?= cover.out
VERS := dev v0.8.1
.DEFAULT_GOAL := all
.PHONY: all
all: generate fix vet fmt manifests test lint license misspell tidy bin/kube-app-manager
## --------------------------------------
## Tooling Binaries
## --------------------------------------
$(TOOLBIN)/controller-gen:
GOBIN=$(TOOLBIN) GO111MODULE=on go get sigs.k8s.io/controller-tools/cmd/[email protected]
$(TOOLBIN)/golangci-lint:
GOBIN=$(TOOLBIN) GO111MODULE=on go get github.com/golangci/golangci-lint/cmd/[email protected]
$(TOOLBIN)/mockgen:
GOBIN=$(TOOLBIN) GO111MODULE=on go get github.com/golang/mock/[email protected]
$(TOOLBIN)/conversion-gen:
GOBIN=$(TOOLBIN) GO111MODULE=on go get k8s.io/code-generator/cmd/[email protected]
$(TOOLBIN)/kubebuilder $(TOOLBIN)/etcd $(TOOLBIN)/kube-apiserver $(TOOLBIN)/kubectl:
cd $(TOOLS_DIR); ./install_kubebuilder.sh
$(TOOLBIN)/kustomize:
cd $(TOOLS_DIR); ./install_kustomize.sh
$(TOOLBIN)/kind:
GOBIN=$(TOOLBIN) GO111MODULE=on go get sigs.k8s.io/[email protected]
$(TOOLBIN)/addlicense:
GOBIN=$(TOOLBIN) GO111MODULE=on go get github.com/google/addlicense
$(TOOLBIN)/misspell:
GOBIN=$(TOOLBIN) GO111MODULE=on go get github.com/client9/misspell/cmd/[email protected]
.PHONY: install-tools
install-tools: \
$(TOOLBIN)/controller-gen \
$(TOOLBIN)/golangci-lint \
$(TOOLBIN)/mockgen \
$(TOOLBIN)/conversion-gen \
$(TOOLBIN)/kubebuilder \
$(TOOLBIN)/kustomize \
$(TOOLBIN)/addlicense \
$(TOOLBIN)/misspell \
$(TOOLBIN)/kind
## --------------------------------------
## Tests
## --------------------------------------
# Run tests
.PHONY: test
test: $(TOOLBIN)/etcd $(TOOLBIN)/kube-apiserver $(TOOLBIN)/kubectl
TEST_ASSET_KUBECTL=$(TOOLBIN)/kubectl \
TEST_ASSET_KUBE_APISERVER=$(TOOLBIN)/kube-apiserver \
TEST_ASSET_ETCD=$(TOOLBIN)/etcd \
go test -v ./api/... ./controllers/... -coverprofile $(COVER_FILE)
# Run e2e-tests
K8S_VERSION := "v1.16.4"
.PHONY: e2e-setup
e2e-setup: $(TOOLBIN)/kind
KUBECONFIG=$(shell $(TOOLBIN)/kind get kubeconfig-path --name="kind") \
$(TOOLBIN)/kind create cluster \
-v 4 --retain --wait=1m \
--config e2e/kind-config.yaml \
--image=kindest/node:$(K8S_VERSION)
.PHONY: e2e-cleanup
e2e-cleanup: $(TOOLBIN)/kind
$(TOOLBIN)/kind delete cluster
.PHONY: e2e-test
e2e-test: generate fmt vet manifests $(TOOLBIN)/kind $(TOOLBIN)/kustomize $(TOOLBIN)/kubectl
go test -v ./e2e/main_test.go
.PHONY: local-e2e-test
local-e2e-test: e2e-setup e2e-test e2e-cleanup
## --------------------------------------
## Build and run
## --------------------------------------
# Build kube-app-kube-app-manager binary
bin/kube-app-manager: main.go generate fmt vet manifests
go build -o bin/kube-app-manager main.go
# Run against the configured Kubernetes cluster in ~/.kube/config
.PHONY: runbg
runbg: bin/kube-app-manager
bin/kube-app-manager --metrics-addr ":8083" >& kube-app-manager.log & echo $$! > kube-app-manager.pid
# Run against the configured Kubernetes cluster in ~/.kube/config
.PHONY: run
run: bin/kube-app-manager
bin/kube-app-manager
# Debug using the configured Kubernetes cluster in ~/.kube/config
.PHONY: debug
debug: generate fmt vet manifests
dlv debug ./main.go
## --------------------------------------
## Code maintenance
## --------------------------------------
.PHONY: fmt
fmt:
go fmt ./api/... ./controllers/...
.PHONY: vet
vet:
go vet ./api/... ./controllers/...
.PHONY: fix
fix:
go fix ./api/... ./controllers/...
.PHONY: license
license: $(TOOLBIN)/addlicense
$(TOOLBIN)/addlicense -y $(shell date +"%Y") -c "The Kubernetes Authors." -f LICENSE_TEMPLATE .
.PHONY: tidy
tidy:
go mod tidy
.PHONY: lint
lint: $(TOOLBIN)/golangci-lint
$(TOOLBIN)/golangci-lint run ./...
.PHONY: misspell
misspell: $(TOOLBIN)/misspell
$(TOOLBIN)/misspell ./**
.PHONY: misspell-fix
misspell-fix: $(TOOLBIN)/misspell
$(TOOLBIN)/misspell -w ./**
## --------------------------------------
## Deploy all (CRDs + Controller)
## --------------------------------------
# Deploy controller in the configured Kubernetes cluster in ~/.kube/config
# This is expected to be used by user during dev
.PHONY: deploy
deploy:
kubectl apply -f deploy/kube-app-manager-aio.yaml
# unDeploy controller in the configured Kubernetes cluster in ~/.kube/config
.PHONY: undeploy
undeploy:
kubectl delete -f deploy/kube-app-manager-aio.yaml
.PHONY: deploy-dev
deploy-dev: $(TOOLBIN)/kubectl generate-resources
$(TOOLBIN)/kubectl apply -f $(AIO_YAML)
# unDeploy controller in the configured Kubernetes cluster in ~/.kube/config
.PHONY: undeploy-dev
undeploy-dev: $(TOOLBIN)/kubectl generate-resources
$(TOOLBIN)/kubectl delete -f $(AIO_YAML)
## --------------------------------------
## Deploy CRDs only
## --------------------------------------
# Install CRDs into a cluster,
.PHONY: deploy-crd
deploy-crd: $(TOOLBIN)/kustomize $(TOOLBIN)/kubectl
$(TOOLBIN)/kustomize build config/crd| $(TOOLBIN)/kubectl apply -f -
# Uninstall CRDs from a cluster
.PHONY: undeploy-crd
undeploy-crd: $(TOOLBIN)/kustomize $(TOOLBIN)/kubectl
$(TOOLBIN)/kustomize build config/crd| $(TOOLBIN)/kubectl delete -f -
## --------------------------------------
## Deploy demo
## --------------------------------------
# Deploy wordpress
.PHONY: deploy-wordpress
deploy-wordpress: $(TOOLBIN)/kustomize $(TOOLBIN)/kubectl
mkdir -p /tmp/data1 /tmp/data2
$(TOOLBIN)/kustomize build docs/examples/wordpress | $(TOOLBIN)/kubectl apply -f -
# Uneploy wordpress
.PHONY: undeploy-wordpress
undeploy-wordpress: $(TOOLBIN)/kustomize $(TOOLBIN)/kubectl
$(TOOLBIN)/kustomize build docs/examples/wordpress | $(TOOLBIN)/kubectl delete -f -
# $(TOOLBIN)/kubectl delete pvc --all
# sudo rm -fr /tmp/data1 /tmp/data2
## --------------------------------------
## Generating
## --------------------------------------
.PHONY: generate
generate: ## Generate code
$(MAKE) generate-go
$(MAKE) manifests
$(MAKE) generate-resources
VERSION_FILE=VERSION $(MAKE) generate-resources
# Generate manifests e.g. CRD, RBAC etc.
.PHONY: manifests
manifests: $(TOOLBIN)/controller-gen
$(TOOLBIN)/controller-gen \
$(CRD_OPTIONS) \
rbac:roleName=kube-app-manager-role \
paths=./... \
output:crd:artifacts:config=$(CRD_ROOT) \
output:crd:dir=$(CRD_ROOT) \
output:webhook:dir=$(WEBHOOK_ROOT) \
webhook
.PHONY: generate-resources
generate-resources: $(TOOLBIN)/kustomize
cd config/default/scratch && $(TOOLBIN)/kustomize edit set image kube-app-manager=$(CONTROLLER_IMG)
$(TOOLBIN)/kustomize build config/default/scratch/ -o $(AIO_YAML)
.PHONY: generate-go
generate-go: $(TOOLBIN)/controller-gen $(TOOLBIN)/conversion-gen $(TOOLBIN)/mockgen
go generate ./api/... ./controllers/...
$(TOOLBIN)/controller-gen \
paths=./api/v1beta1/... \
object:headerFile=./hack/boilerplate.go.txt
## --------------------------------------
## Docker
## --------------------------------------
.PHONY: set-image
set-image: $(TOOLBIN)/kustomize
@echo "updating kustomize image patch file for kube-app-manager resource"
cd config/kube-app-manager && $(TOOLBIN)/kustomize edit set image kube-app-manager=$(CONTROLLER_IMG)
.PHONY: docker-build
docker-build: set-image test $(TOOLBIN)/kustomize ## Build the docker image for kube-app-manager
docker build --network=host --pull --build-arg ARCH=$(ARCH) . -t $(CONTROLLER_IMG)
.PHONY: docker-push
docker-push: ## Push the docker image
docker push $(CONTROLLER_IMG)
.PHONY: clean
clean:
go clean --cache
rm -f $(COVER_FILE)
rm -f $(TOOLBIN)/kustomize
rm -f $(TOOLBIN)/goimports
rm -f $(TOOLBIN)/golangci-lint
rm -f $(TOOLBIN)/controller-gen
rm -f $(TOOLBIN)/conversion-gen
rm -f $(TOOLBIN)/etcd
rm -f $(TOOLBIN)/kube-apiserver
rm -f $(TOOLBIN)/kubebuilder
rm -f $(TOOLBIN)/addlicense
rm -f $(TOOLBIN)/kubectl
rm -f $(TOOLBIN)/kustomize
rm -f $(TOOLBIN)/misspell
rm -f $(TOOLBIN)/mockgen
## --------------------------------------
## Releasing
## --------------------------------------
.PHONY: release-branch
release-branch:
echo "checking branch=$(RELEASE_BRANCH)"
git ls-remote --exit-code `git remote get-url $(RELEASE_REMOTE)` $(RELEASE_BRANCH) || make create-release-branch
.PHONY: create-release-branch
create-release-branch:
git fetch upstream
git checkout master
git rebase upstream/master
git branch -D $(RELEASE_BRANCH) || true
git checkout -b $(RELEASE_BRANCH)
git push -f $(RELEASE_REMOTE) $(RELEASE_BRANCH)
.PHONY: release-tag
release-tag: release-branch
git branch -D $(RELEASE_BRANCH) || true
git branch ${RELEASE_BRANCH} ${RELEASE_REMOTE}/${RELEASE_BRANCH}
git checkout $(RELEASE_BRANCH)
git tag -a ${RELEASE_TAG} -m "Release ${RELEASE_TAG} on branch ${RELEASE_BRANCH}"
git push $(RELEASE_REMOTE) ${RELEASE_TAG}
.PHONY: delete-release-tag
delete-release-tag:
git tag --delete $(RELEASE_TAG)
git push $(RELEASE_REMOTE) :refs/tags/$(RELEASE_TAG)