This repository has been archived by the owner on May 6, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 382
/
Makefile
459 lines (384 loc) · 17.2 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
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
# Copyright 2016 The Kubernetes Authors.
#
# 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.
all: build test verify
# Some env vars that devs might find useful:
# GOFLAGS : extra "go build" flags to use - e.g. -v (for verbose)
# NO_DOCKER=1 : execute each step natively, not in a Docker container
# TEST_DIRS= : only run the unit tests from the specified dirs
# UNIT_TESTS= : only run the unit tests matching the specified regexp
# Define some constants
#######################
ROOT = $(dir $(abspath $(lastword $(MAKEFILE_LIST))))
BINDIR ?= bin
BUILD_DIR ?= build
COVERAGE ?= $(CURDIR)/coverage.html
SC_PKG = github.com/kubernetes-sigs/service-catalog
TOP_SRC_DIRS = cmd contrib pkg plugin
SRC_DIRS = $(shell sh -c "find $(TOP_SRC_DIRS) -name \\*.go \
-exec dirname {} \\; | sort | uniq")
TEST_DIRS ?= $(shell sh -c "find $(TOP_SRC_DIRS) -name \\*_test.go \
-exec dirname {} \\; | sort | uniq")
# Either the tag name, e.g. v1.2.3 or the commit hash for untagged commits, e.g. abc123
VERSION ?= $(shell git describe --tags --always --abbrev=7 --dirty)
# Either the tag name, e.g. v1.2.3 or a combination of the closest tag combined with the commit hash, e.g. v1.2.3-2-gabc123
TAG_VERSION ?= $(shell git describe --tags --abbrev=7 --dirty)
BUILD_LDFLAGS = $(shell build/version.sh $(ROOT) $(SC_PKG))
GIT_BRANCH ?= $(shell git rev-parse --abbrev-ref HEAD)
# Only skip the verification of external href's if we're not on 'master'
SKIP_HTTP=-x
SKIP_COMMENT=" (Skipping external hrefs)"
ifeq ($(GIT_BRANCH),master)
SKIP_HTTP=
SKIP_COMMENT=" (Checking external hrefs)"
endif
# Run stat against /dev/null and check if it has any stdout output.
# If stdout is blank, we are detecting bsd-stat because stat it has
# returned an error to stderr. If not bsd-stat, assume gnu-stat.
ifeq ($(shell stat -c"%U" /dev/null 2> /dev/null),)
STAT = stat -f '%c %N'
else
STAT = stat -c '%Y %n'
endif
TYPES_FILES = $(shell find pkg/apis -name types.go)
GO_VERSION ?= 1.12
ALL_ARCH=amd64 arm arm64 ppc64le s390x
ALL_CLIENT_PLATFORM=darwin linux windows
PLATFORM ?= linux
# This is the current platform, so that we can build a native client binary by default
CLIENT_PLATFORM?=$(shell uname -s | tr A-Z a-z)
ARCH ?= amd64
ifeq ($(PLATFORM),windows)
FILE_EXT=.exe
else
FILE_EXT=
endif
# TODO: Consider using busybox instead of debian
BASEIMAGE?=gcr.io/google-containers/debian-base-$(ARCH):v1.0.0
GO_BUILD = env CGO_ENABLED=0 GOOS=$(PLATFORM) GOARCH=$(ARCH) \
go build $(GOFLAGS) -a -tags netgo -installsuffix netgo \
-ldflags '-s -w -X $(SC_PKG)/pkg.VERSION=$(VERSION) $(BUILD_LDFLAGS)'
BASE_PATH = $(ROOT:/src/github.com/kubernetes-sigs/service-catalog/=)
ORIG_GOPATH ?= $(shell go env GOPATH)
export GOPATH = $(BASE_PATH):$(ROOT)/vendor
MUTABLE_TAG ?= canary
SERVICE_CATALOG_IMAGE = $(REGISTRY)service-catalog-$(ARCH):$(VERSION)
SERVICE_CATALOG_MUTABLE_IMAGE = $(REGISTRY)service-catalog-$(ARCH):$(MUTABLE_TAG)
USER_BROKER_IMAGE = $(REGISTRY)user-broker-$(ARCH):$(VERSION)
USER_BROKER_MUTABLE_IMAGE = $(REGISTRY)user-broker-$(ARCH):$(MUTABLE_TAG)
TEST_BROKER_IMAGE = $(REGISTRY)test-broker-$(ARCH):$(VERSION)
TEST_BROKER_MUTABLE_IMAGE = $(REGISTRY)test-broker-$(ARCH):$(MUTABLE_TAG)
HEALTHCHECK_IMAGE = $(REGISTRY)healthcheck-$(ARCH):$(VERSION)
HEALTHCHECK_MUTABLE_IMAGE = $(REGISTRY)healthcheck-$(ARCH):$(MUTABLE_TAG)
ifdef UNIT_TESTS
UNIT_TEST_FLAGS=-run $(UNIT_TESTS) -v --env GODEBUG tls13=1
endif
ifdef INT_TESTS
INT_TEST_FLAGS=--test.run=$(INT_TESTS)
endif
ifdef TEST_LOG_LEVEL
UNIT_TEST_FLAGS+=-v
UNIT_TEST_LOG_FLAGS=-args --alsologtostderr --v=$(TEST_LOG_LEVEL)
INT_TEST_FLAGS+=--alsologtostderr --v=$(TEST_LOG_LEVEL)
endif
ifdef NO_DOCKER
DOCKER_CMD =
scBuildImageTarget =
else
# Mount .pkg as pkg so that we save our cached "go build" output files
DOCKER_CMD = docker run --security-opt label:disable --rm \
-v $(CURDIR):/go/src/$(SC_PKG) \
-v $(CURDIR)/.cache:/root/.cache/ \
-v $(CURDIR)/.pkg:/go/pkg --env AZURE_STORAGE_CONNECTION_STRING scbuildimage
scBuildImageTarget = .scBuildImage
endif
# This section builds the output binaries.
# Some will have dedicated targets to make it easier to type, for example
# "service-catalog" instead of "bin/service-catalog".
#########################################################################
build: .init .generate_files \
$(BINDIR)/service-catalog \
$(BINDIR)/user-broker \
$(BINDIR)/test-broker \
$(BINDIR)/healthcheck
.PHONY: $(BINDIR)/user-broker
user-broker: $(BINDIR)/user-broker
$(BINDIR)/user-broker: .init contrib/cmd/user-broker \
$(shell find contrib/cmd/user-broker -type f) \
$(shell find contrib/pkg/broker -type f)
$(DOCKER_CMD) $(GO_BUILD) -o $@ $(SC_PKG)/contrib/cmd/user-broker
.PHONY: $(BINDIR)/test-broker
test-broker: $(BINDIR)/test-broker
$(BINDIR)/test-broker: .init contrib/cmd/test-broker \
$(shell find contrib/cmd/test-broker -type f) \
$(shell find contrib/pkg/broker -type f)
$(DOCKER_CMD) $(GO_BUILD) -o $@ $(SC_PKG)/contrib/cmd/test-broker
.PHONY: $(BINDIR)/healthcheck
healthcheck: $(BINDIR)/healthcheck
$(BINDIR)/healthcheck: .init cmd/healthcheck \
$(shell find cmd/healthcheck -type f)
$(DOCKER_CMD) $(GO_BUILD) -o $@ $(SC_PKG)/cmd/healthcheck
.PHONY: $(BINDIR)/service-catalog
service-catalog: $(BINDIR)/service-catalog
$(BINDIR)/service-catalog: .init .generate_files cmd/service-catalog
$(DOCKER_CMD) $(GO_BUILD) -o $@ $(SC_PKG)/cmd/service-catalog
# This section contains the code generation stuff
#################################################
GENERATORS = $(addprefix $(BINDIR)/, defaulter-gen deepcopy-gen conversion-gen \
client-gen lister-gen informer-gen openapi-gen)
.PHONY: generators
generators: $(GENERATORS)
.SECONDEXPANSION:
$(BINDIR)/openapi-gen: $$(shell find vendor/k8s.io/kube-openapi/cmd/openapi-gen vendor/k8s.io/gengo) .init
$(DOCKER_CMD) go build -o $@ $(SC_PKG)/vendor/k8s.io/kube-openapi/cmd/openapi-gen
# We specify broad dependencies for these generator binaries: each one depends
# on everything under its source tree as well as gengo's. This uses GNU Make's
# secondary expansion feature to pass $* to `find`.
$(BINDIR)/%-gen: $$(shell find vendor/k8s.io/code-generator/cmd/$$*-gen vendor/k8s.io/gengo) .init
$(DOCKER_CMD) go build -o $@ $(SC_PKG)/vendor/k8s.io/code-generator/cmd/$*-gen
# Regenerate all files if the gen exes changed or any "types.go" files changed
.generate_files: .init generators $(TYPES_FILES)
# generate api deps
$(DOCKER_CMD) $(BUILD_DIR)/update-apis-gen.sh
# generate all pkg/client contents
$(DOCKER_CMD) $(BUILD_DIR)/update-client-gen.sh
touch $@
# Some prereq stuff
###################
.init: $(scBuildImageTarget) | $(BINDIR)
touch $@
$(BINDIR):
mkdir -p $@
.scBuildImage: build/build-image/Dockerfile $$(shell sh -c "docker inspect scbuildimage" > /dev/null 2>&1 || echo .forceIt)
mkdir -p .cache
mkdir -p .pkg
sed "s/GO_VERSION/$(GO_VERSION)/g" < build/build-image/Dockerfile | \
docker build -t scbuildimage -f - .
touch $@
# Just a dummy target that will force anything dependent on it to rebuild
.forceIt:
# Util targets
##############
.PHONY: verify verify-generated verify-client-gen verify-docs
verify: .init verify-generated verify-client-gen verify-docs verify-vendor
@echo Running gofmt:
@$(DOCKER_CMD) gofmt -l -s $(TOP_TEST_DIRS) $(TOP_SRC_DIRS)>.out 2>&1||true
@[ ! -s .out ] || \
(echo && echo "*** Please 'gofmt' the following:" && \
cat .out && echo && rm .out && false)
@rm .out
@#
@echo Running golint and go vet:
@# Exclude the generated (zz) files for now, as well as defaults.go (it
@# observes conventions from upstream that will not pass lint checks).
@$(DOCKER_CMD) sh -c \
'for i in $$(find $(TOP_SRC_DIRS) -name *.go \
| grep -v ^pkg/kubernetes/ \
| grep -v generated \
| grep -v v1beta1/defaults.go); \
do \
golint --set_exit_status $$i || exit 1; \
done'
@#
$(DOCKER_CMD) go vet $(SC_PKG)/...
@echo Running repo-infra verify scripts
@$(DOCKER_CMD) vendor/github.com/kubernetes/repo-infra/verify/verify-boilerplate.sh --rootdir=. | grep -Fv -e generated -e .pkg -e docsite > .out 2>&1 || true
@[ ! -s .out ] || (cat .out && rm .out && false)
@rm .out
@#
@echo Running errexit checker:
@$(DOCKER_CMD) build/verify-errexit.sh
@echo Running tag verification:
@$(DOCKER_CMD) build/verify-tags.sh
@echo Validating golden file flag is defined:
@$(DOCKER_CMD) go test -run DRYRUN ./cmd/svcat/... -update || printf "\n\nmake test-update-goldenfiles is broken. For each failed package above, add the following empty import to one of the test files to define the -update flag:\n_ \"github.com/kubernetes-sigs/service-catalog/internal/test\""
verify-docs: .init
@echo Running href checker$(SKIP_COMMENT):
@$(DOCKER_CMD) verify-links.sh -s .pkg -s .bundler -s _plugins -s _includes -t $(SKIP_HTTP) .
verify-generated: .init generators
$(DOCKER_CMD) $(BUILD_DIR)/update-apis-gen.sh --verify-only
verify-client-gen: .init generators
$(DOCKER_CMD) $(BUILD_DIR)/verify-client-gen.sh
format: .init
$(DOCKER_CMD) gofmt -w -s $(TOP_SRC_DIRS)
coverage: .init
$(DOCKER_CMD) contrib/hack/coverage.sh --html "$(COVERAGE)" \
$(addprefix ./,$(TEST_DIRS))
.PHONY: test test-unit test-integration test-e2e
test: .init build test-unit test-integration
# this target checks to see if the go binary is installed on the host
.PHONY: check-go
check-go:
@if [ -z $$(which go) ]; then \
echo "Missing \`go\` binary which is required for development"; \
exit 1; \
fi
# this target uses the host-local go installation to test
.PHONY: test-unit-native
test-unit-native: check-go
go test $(addprefix ${SC_PKG}/,${TEST_DIRS})
test-unit: .init build
@echo Running tests:
$(DOCKER_CMD) go test -race $(UNIT_TEST_FLAGS) \
$(addprefix $(SC_PKG)/,$(TEST_DIRS)) $(UNIT_TEST_LOG_FLAGS)
test-update-goldenfiles: .init
@echo Updating golden files to match current test output
$(DOCKER_CMD) go test ./cmd/svcat/... -update
build-integration: .generate_files
$(DOCKER_CMD) go test --tags="integration" -race github.com/kubernetes-sigs/service-catalog/pkg/controller/... -c
test-integration: .init $(scBuildImageTarget) build build-integration
$(DOCKER_CMD) ./controller.test
test-e2e:
./contrib/hack/ci/run-e2e-tests.sh
clean: clean-bin clean-build-image clean-generated clean-coverage
clean-bin: .init $(scBuildImageTarget)
$(DOCKER_CMD) rm -rf $(BINDIR)
clean-build-image: .init $(scBuildImageTarget)
$(DOCKER_CMD) rm -rf .pkg
rm -f .scBuildImage
docker rmi -f scbuildimage > /dev/null 2>&1 || true
# clean-generated does a `git checkout --` on all generated files and
# directories. May not work correctly if you have staged some of these files
# or have multiple commits.
clean-generated:
rm -f .generate_files
# rollback changes to generated defaults/conversions/deepcopies
find $(TOP_SRC_DIRS) -name zz_generated* | xargs git checkout --
# rollback changes to types.generated.go
find $(TOP_SRC_DIRS) -name types.generated* | xargs git checkout --
# rollback changes to the generated clientset directories
find $(TOP_SRC_DIRS) -type d -name *_generated | xargs git checkout --
# rollback openapi changes
git checkout -- pkg/openapi/openapi_generated.go
rm api_violations.txt
# purge-generated removes generated files from the filesystem.
purge-generated: .init $(scBuildImageTarget)
find $(TOP_SRC_DIRS) -name zz_generated* -exec $(DOCKER_CMD) rm {} \;
find $(TOP_SRC_DIRS) -depth -type d -name *_generated \
-exec $(DOCKER_CMD) rm -rf {} \;
$(DOCKER_CMD) rm -f pkg/openapi/openapi_generated.go
echo 'package v1beta1' > pkg/apis/servicecatalog/v1beta1/types.generated.go
rm -f .generate_files
clean-coverage:
rm -f $(COVERAGE)
# Building Docker Images for our executables
############################################
images: user-broker-image test-broker-image service-catalog-image healthcheck-image
images-all: $(addprefix arch-image-,$(ALL_ARCH))
arch-image-%:
$(MAKE) ARCH=$* build
$(MAKE) ARCH=$* images
define build-and-tag # (service, image, mutable_image, prefix)
$(eval build_path := "$(4)build/$(1)")
$(eval tmp_build_path := "$(build_path)/tmp")
mkdir -p $(tmp_build_path)
# scratch image needs an empty directory to have as /tmp
mkdir -p $(tmp_build_path)/tmp
cp $(BINDIR)/$(1) $(tmp_build_path)
cp $(build_path)/Dockerfile $(tmp_build_path)
# -i.bak is required for cross-platform compat: https://stackoverflow.com/questions/5694228/sed-in-place-flag-that-works-both-on-mac-bsd-and-linux
sed -i.bak "s|BASEIMAGE|$(BASEIMAGE)|g" $(tmp_build_path)/Dockerfile
rm $(tmp_build_path)/Dockerfile.bak
docker run --rm --privileged multiarch/qemu-user-static:register --reset
docker build -t $(2) $(tmp_build_path)
docker tag $(2) $(3)
rm -rf $(tmp_build_path)
endef
user-broker-image: contrib/build/user-broker/Dockerfile $(BINDIR)/user-broker
$(call build-and-tag,"user-broker",$(USER_BROKER_IMAGE),$(USER_BROKER_MUTABLE_IMAGE),"contrib/")
ifeq ($(ARCH),amd64)
docker tag $(USER_BROKER_IMAGE) $(REGISTRY)user-broker:$(VERSION)
docker tag $(USER_BROKER_MUTABLE_IMAGE) $(REGISTRY)user-broker:$(MUTABLE_TAG)
endif
test-broker-image: contrib/build/test-broker/Dockerfile $(BINDIR)/test-broker
$(call build-and-tag,"test-broker",$(TEST_BROKER_IMAGE),$(TEST_BROKER_MUTABLE_IMAGE),"contrib/")
ifeq ($(ARCH),amd64)
docker tag $(TEST_BROKER_IMAGE) $(REGISTRY)test-broker:$(VERSION)
docker tag $(TEST_BROKER_MUTABLE_IMAGE) $(REGISTRY)test-broker:$(MUTABLE_TAG)
endif
service-catalog-image: build/service-catalog/Dockerfile $(BINDIR)/service-catalog
$(call build-and-tag,"service-catalog",$(SERVICE_CATALOG_IMAGE),$(SERVICE_CATALOG_MUTABLE_IMAGE))
ifeq ($(ARCH),amd64)
docker tag $(SERVICE_CATALOG_IMAGE) $(REGISTRY)service-catalog:$(VERSION)
docker tag $(SERVICE_CATALOG_MUTABLE_IMAGE) $(REGISTRY)service-catalog:$(MUTABLE_TAG)
endif
healthcheck-image: contrib/build/healthcheck/Dockerfile $(BINDIR)/healthcheck
$(call build-and-tag,"healthcheck",$(HEALTHCHECK_IMAGE),$(HEALTHCHECK_MUTABLE_IMAGE),"contrib/")
ifeq ($(ARCH),amd64)
docker tag $(HEALTHCHECK_IMAGE) $(REGISTRY)healthcheck:$(VERSION)
docker tag $(HEALTHCHECK_MUTABLE_IMAGE) $(REGISTRY)healthcheck:$(MUTABLE_TAG)
endif
# Push our Docker Images to a registry
######################################
push: user-broker-push test-broker-push service-catalog-push
user-broker-push: user-broker-image
docker push $(USER_BROKER_IMAGE)
docker push $(USER_BROKER_MUTABLE_IMAGE)
ifeq ($(ARCH),amd64)
docker push $(REGISTRY)user-broker:$(VERSION)
docker push $(REGISTRY)user-broker:$(MUTABLE_TAG)
endif
test-broker-push: test-broker-image
docker push $(TEST_BROKER_IMAGE)
docker push $(TEST_BROKER_MUTABLE_IMAGE)
ifeq ($(ARCH),amd64)
docker push $(REGISTRY)test-broker:$(VERSION)
docker push $(REGISTRY)test-broker:$(MUTABLE_TAG)
endif
service-catalog-push: service-catalog-image
docker push $(SERVICE_CATALOG_IMAGE)
docker push $(SERVICE_CATALOG_MUTABLE_IMAGE)
ifeq ($(ARCH),amd64)
docker push $(REGISTRY)service-catalog:$(VERSION)
docker push $(REGISTRY)service-catalog:$(MUTABLE_TAG)
endif
release-push: $(addprefix release-push-,$(ALL_ARCH))
release-push-%:
$(MAKE) ARCH=$* build
$(MAKE) ARCH=$* push
# svcat kubectl plugin
############################
.PHONY: $(BINDIR)/svcat/$(TAG_VERSION)/$(PLATFORM)/$(ARCH)/svcat$(FILE_EXT)
svcat:
# Compile a native binary for local dev/test
$(MAKE) svcat-for-$(CLIENT_PLATFORM)
cp $(BINDIR)/svcat/$(TAG_VERSION)/$(CLIENT_PLATFORM)/$(ARCH)/svcat$(FILE_EXT) $(BINDIR)/svcat/
svcat-install: svcat
cp $(BINDIR)/svcat/svcat$(FILE_EXT) $(ORIG_GOPATH)/bin/
$(BINDIR)/svcat/svcat$(FILE_EXT) install plugin
svcat-all: $(addprefix svcat-for-,$(ALL_CLIENT_PLATFORM))
svcat-for-%:
$(MAKE) PLATFORM=$* VERSION=$(TAG_VERSION) svcat-xbuild
svcat-xbuild: $(BINDIR)/svcat/$(TAG_VERSION)/$(PLATFORM)/$(ARCH)/svcat$(FILE_EXT)
$(BINDIR)/svcat/$(TAG_VERSION)/$(PLATFORM)/$(ARCH)/svcat$(FILE_EXT): .init .generate_files
mkdir -p $(dir $@)
$(DOCKER_CMD) $(GO_BUILD) -o $@ $(SC_PKG)/cmd/svcat
svcat-publish: clean-bin svcat-all
# Download the latest client with https://download.svcat.sh/cli/latest/darwin/amd64/svcat
# Download an older client with https://download.svcat.sh/cli/VERSION/darwin/amd64/svcat
$(DOCKER_CMD) cp -R $(BINDIR)/svcat/$(TAG_VERSION) $(BINDIR)/svcat/$(MUTABLE_TAG)
# AZURE_STORAGE_CONNECTION_STRING will be used for auth in the following command
$(DOCKER_CMD) az storage blob upload-batch -d cli -s $(BINDIR)/svcat
# Dependency management via dep (https://golang.github.io/dep)
.PHONY: verify-vendor test-dep
verify-vendor: .init
# Verify that vendor/ is in sync with Gopkg.lock
$(DOCKER_CMD) $(BUILD_DIR)/verify-vendor.sh
test-dep: .init
# Test that a downstream consumer of our client library can use dep
$(DOCKER_CMD) test/test-dep.sh
.PHONY: docs
docs:
./build/docs.sh generate
docs-preview:
./build/docs.sh preview