forked from kubernetes-sigs/application
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
270 lines (212 loc) · 7.63 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
# Copyright 2019 The Kubernetes Authors.
# SPDX-License-Identifier: Apache-2.0
#
# Makefile for application
# 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.
ARCH ?= amd64
ALL_ARCH = amd64 arm arm64 ppc64le s390x
IMAGE_NAME ?= kubernetes-application-$(ARCH)
TAG ?= dev
REGISTRY ?= gcr.io/$(shell gcloud config get-value project)
CONTROLLER_IMG ?= $(REGISTRY)/$(IMAGE_NAME):$(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
.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 ./**
## --------------------------------------
## Deploying
## --------------------------------------
# Install CRDs into a cluster
.PHONY: install
install: $(TOOLBIN)/kustomize $(TOOLBIN)/kubectl
$(TOOLBIN)/kustomize build config/crd| $(TOOLBIN)/kubectl apply -f -
# Uninstall CRDs from a cluster
.PHONY: uninstall
uninstall: $(TOOLBIN)/kustomize $(TOOLBIN)/kubectl
$(TOOLBIN)/kustomize build config/crd| $(TOOLBIN)/kubectl delete -f -
# Deploy controller in the configured Kubernetes cluster in ~/.kube/config
.PHONY: deploy
deploy: $(TOOLBIN)/kustomize
cd config/kube-app-manager && $(TOOLBIN)/kustomize edit set image controller=$(CONTROLLER_IMG)
$(TOOLBIN)/kustomize build config/default | $(TOOLBIN)/kubectl apply -f -
# unDeploy controller in the configured Kubernetes cluster in ~/.kube/config
.PHONY: undeploy
undeploy: $(TOOLBIN)/kustomize $(TOOLBIN)/kubectl
$(TOOLBIN)/kustomize build config/default | $(TOOLBIN)/kubectl delete -f -
# 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
# 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-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: docker-build
docker-build: test $(TOOLBIN)/kustomize ## Build the docker image for kube-app-manager
docker build --network=host --pull --build-arg ARCH=$(ARCH) . -t $(CONTROLLER_IMG)
@echo "updating kustomize image patch file for kube-app-manager resource"
cd config/kube-app-manager && $(TOOLBIN)/kustomize edit set image controller=$(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