forked from kubernetes/node-problem-detector
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
374 lines (305 loc) · 12.9 KB
/
Makefile
File metadata and controls
374 lines (305 loc) · 12.9 KB
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
# Copyright 2017 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.
# Build the node-problem-detector image.
.PHONY: all \
lint vet fmt version test e2e-test \
build-binaries build-container build-tar build \
docker-builder build-in-docker \
push-container push-tar push release clean depup \
print-tar-sha-md5
all: build
# PLATFORMS is the set of OS_ARCH that NPD can build against.
LINUX_PLATFORMS=linux_amd64 linux_arm64
DOCKER_PLATFORMS=linux/amd64,linux/arm64
PLATFORMS=$(LINUX_PLATFORMS) windows_amd64
# BRANCH is the git branch.
BRANCH=$(shell git symbolic-ref --short HEAD)
# VERSION is the git version of the binary.
VERSION?=$(shell git describe --tags --always --dirty)
# TAG is the tag of the container image, default to binary version.
TAG?=$(VERSION)
# REGISTRY is the container registry to push into.
REGISTRY?=gcr.io/k8s-staging-npd
# UPLOAD_PATH is the cloud storage path to upload release tar.
UPLOAD_PATH?=gs://kubernetes-release
# Trim the trailing '/' in the path
UPLOAD_PATH:=$(shell echo $(UPLOAD_PATH) | sed '$$s/\/*$$//')
# PKG is the package name of node problem detector repo.
PKG:=k8s.io/node-problem-detector
# PKG_SOURCES are all the go source code.
ifeq ($(OS),Windows_NT)
PKG_SOURCES:=
# TODO: File change detection does not work in Windows.
else
PKG_SOURCES:=$(shell find pkg cmd -name '*.go')
endif
# PARALLEL specifies the number of parallel test nodes to run for e2e tests.
PARALLEL?=3
NPD_NAME_VERSION?=node-problem-detector-$(VERSION)
# TARBALL is the name of release tar. Include binary version by default.
TARBALL=$(NPD_NAME_VERSION).tar.gz
# IMAGE_TAGS contains the image tags of the node problem detector container image.
IMAGE_TAGS=--tag $(REGISTRY)/node-problem-detector:$(TAG)
IMAGE_TAGS_WINDOWS=--tag $(REGISTRY)/node-problem-detector-windows:$(TAG)
ifeq ($(REGISTRY), gcr.io/k8s-staging-npd)
ifeq (,$(findstring heads,$(BRANCH)))
IMAGE_TAGS+= --tag $(REGISTRY)/node-problem-detector:$(BRANCH)
IMAGE_TAGS_WINDOWS+= --tag $(REGISTRY)/node-problem-detector-windows:$(BRANCH)
endif
endif
# ENABLE_JOURNALD enables build journald support or not. Building journald
# support needs libsystemd-dev or libsystemd-journal-dev.
ENABLE_JOURNALD?=1
ifeq ($(shell go env GOHOSTOS), darwin)
ENABLE_JOURNALD=0
else ifeq ($(shell go env GOHOSTOS), windows)
ENABLE_JOURNALD=0
endif
# Disable cgo by default to make the binary statically linked.
CGO_ENABLED:=0
ifeq ($(GOARCH), arm64)
CC:=aarch64-linux-gnu-gcc
else
CC:=x86_64-linux-gnu-gcc
endif
# Set default Go architecture to AMD64.
GOARCH ?= amd64
# Construct the "-tags" parameter used by "go build".
BUILD_TAGS?=
LINUX_BUILD_TAGS = $(BUILD_TAGS)
WINDOWS_BUILD_TAGS = $(BUILD_TAGS)
ifeq ($(OS),Windows_NT)
HOST_PLATFORM_BUILD_TAGS = $(WINDOWS_BUILD_TAGS)
else
HOST_PLATFORM_BUILD_TAGS = $(LINUX_BUILD_TAGS)
endif
ifeq ($(ENABLE_JOURNALD), 1)
# Enable journald build tag.
LINUX_BUILD_TAGS := journald $(BUILD_TAGS)
# Enable cgo because sdjournal needs cgo to compile. The binary will be
# dynamically linked if CGO_ENABLED is enabled. This is fine because fedora
# already has necessary dynamic library. We can not use `-extldflags "-static"`
# here, because go-systemd uses dlopen, and dlopen will not work properly in a
# statically linked application.
CGO_ENABLED:=1
LOGCOUNTER=./bin/log-counter
else
# Hack: Don't copy over log-counter, use a wildcard path that shouldn't match
# anything in COPY command.
LOGCOUNTER=*dont-include-log-counter
endif
GOLANGCI_LINT_VERSION := v2.6.2
GOLANGCI_LINT := ./.bin/golangci-lint
lint: $(GOLANGCI_LINT)
$(GOLANGCI_LINT) run --config .golangci.yml ./...
$(GOLANGCI_LINT):
@echo "golangci-lint not found, downloading..."
@mkdir -p ./.bin
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b ./.bin $(GOLANGCI_LINT_VERSION)
vet:
go list -tags "$(HOST_PLATFORM_BUILD_TAGS)" ./... | \
grep -v "./vendor/*" | \
xargs go vet -tags "$(HOST_PLATFORM_BUILD_TAGS)"
fmt: $(GOLANGCI_LINT)
find . -type f -name "*.go" | grep -v "./vendor/*" | xargs gofmt -s -w -l
$(GOLANGCI_LINT) run --config .golangci.yml --fix ./...
version:
@echo $(VERSION)
BINARIES = bin/node-problem-detector bin/health-checker test/bin/problem-maker
BINARIES_LINUX_ONLY =
ifeq ($(ENABLE_JOURNALD), 1)
BINARIES_LINUX_ONLY += bin/log-counter
endif
ALL_BINARIES = $(foreach binary, $(BINARIES) $(BINARIES_LINUX_ONLY), ./$(binary)) \
$(foreach platform, $(LINUX_PLATFORMS), $(foreach binary, $(BINARIES) $(BINARIES_LINUX_ONLY), output/$(platform)/$(binary))) \
$(foreach binary, $(BINARIES), output/windows_amd64/$(binary).exe)
ALL_TARBALLS = $(foreach platform, $(PLATFORMS), $(NPD_NAME_VERSION)-$(platform).tar.gz)
output/windows_amd64/bin/%.exe: $(PKG_SOURCES)
GOOS=windows GOARCH=amd64 CGO_ENABLED=$(CGO_ENABLED) go build \
-o $@ \
-ldflags '-X $(PKG)/pkg/version.version=$(VERSION)' \
-tags "$(WINDOWS_BUILD_TAGS)" \
./cmd/$(subst -,,$*)
touch $@
output/windows_amd64/test/bin/%.exe: $(PKG_SOURCES)
cd test && \
GOOS=windows GOARCH=amd64 CGO_ENABLED=$(CGO_ENABLED) go build \
-o ../$@ \
-tags "$(WINDOWS_BUILD_TAGS)" \
./e2e/$(subst -,,$*)
output/linux_amd64/bin/%: $(PKG_SOURCES)
GOOS=linux GOARCH=amd64 CGO_ENABLED=$(CGO_ENABLED) \
CC=x86_64-linux-gnu-gcc go build \
-o $@ \
-ldflags '-X $(PKG)/pkg/version.version=$(VERSION)' \
-tags "$(LINUX_BUILD_TAGS)" \
./cmd/$(subst -,,$*)
touch $@
output/linux_amd64/test/bin/%: $(PKG_SOURCES)
cd test && \
GOOS=linux GOARCH=amd64 CGO_ENABLED=$(CGO_ENABLED) \
CC=x86_64-linux-gnu-gcc go build \
-o ../$@ \
-tags "$(LINUX_BUILD_TAGS)" \
./e2e/$(subst -,,$*)
output/linux_arm64/bin/%: $(PKG_SOURCES)
GOOS=linux GOARCH=arm64 CGO_ENABLED=$(CGO_ENABLED) \
CC=aarch64-linux-gnu-gcc go build \
-o $@ \
-ldflags '-X $(PKG)/pkg/version.version=$(VERSION)' \
-tags "$(LINUX_BUILD_TAGS)" \
./cmd/$(subst -,,$*)
touch $@
output/linux_arm64/test/bin/%: $(PKG_SOURCES)
cd test && \
GOOS=linux GOARCH=arm64 CGO_ENABLED=$(CGO_ENABLED) \
CC=aarch64-linux-gnu-gcc go build \
-o ../$@ \
-tags "$(LINUX_BUILD_TAGS)" \
./e2e/$(subst -,,$*)
# In the future these targets should be deprecated.
./bin/log-counter: $(PKG_SOURCES)
ifeq ($(ENABLE_JOURNALD), 1)
CGO_ENABLED=$(CGO_ENABLED) GOOS=linux GOARCH=$(GOARCH) CC=$(CC) go build \
-o bin/log-counter \
-ldflags '-X $(PKG)/pkg/version.version=$(VERSION)' \
-tags "$(LINUX_BUILD_TAGS)" \
cmd/logcounter/log_counter.go
else
echo "Warning: log-counter requires journald, skipping."
endif
./bin/node-problem-detector.exe: $(PKG_SOURCES)
CGO_ENABLED=0 GOOS=windows GOARCH=$(GOARCH) go build \
-o bin/node-problem-detector.exe \
-ldflags '-X $(PKG)/pkg/version.version=$(VERSION)' \
./cmd/nodeproblemdetector
./bin/node-problem-detector: $(PKG_SOURCES)
CGO_ENABLED=$(CGO_ENABLED) GOOS=linux GOARCH=$(GOARCH) CC=$(CC) go build \
-o bin/node-problem-detector \
-ldflags '-X $(PKG)/pkg/version.version=$(VERSION)' \
-tags "$(LINUX_BUILD_TAGS)" \
./cmd/nodeproblemdetector
./test/bin/problem-maker: $(PKG_SOURCES)
cd test && \
CGO_ENABLED=$(CGO_ENABLED) GOOS=linux GOARCH=$(GOARCH) CC=$(CC) go build \
-o bin/problem-maker \
-tags "$(LINUX_BUILD_TAGS)" \
./e2e/problemmaker/problem_maker.go
./bin/health-checker: $(PKG_SOURCES)
CGO_ENABLED=$(CGO_ENABLED) GOOS=linux GOARCH=$(GOARCH) CC=$(CC) go build \
-o bin/health-checker \
-ldflags '-X $(PKG)/pkg/version.version=$(VERSION)' \
-tags "$(LINUX_BUILD_TAGS)" \
cmd/healthchecker/health_checker.go
./bin/health-checker.exe: $(PKG_SOURCES)
CGO_ENABLED=0 GOOS=windows GOARCH=$(GOARCH) go build \
-o bin/health-checker.exe \
-ldflags '-X $(PKG)/pkg/version.version=$(VERSION)' \
cmd/healthchecker/health_checker.go
test: vet fmt
go test -timeout=1m -v -race -short -tags "$(HOST_PLATFORM_BUILD_TAGS)" ./...
e2e-test: vet fmt build-tar
cd test && \
go run github.com/onsi/ginkgo/ginkgo -nodes=$(PARALLEL) -timeout=10m -v -tags "$(HOST_PLATFORM_BUILD_TAGS)" -stream \
./e2e/metriconly/... -- \
-project=$(PROJECT) -zone=$(ZONE) \
-image=$(VM_IMAGE) -image-family=$(IMAGE_FAMILY) -image-project=$(IMAGE_PROJECT) \
-ssh-user=$(SSH_USER) -ssh-key=$(SSH_KEY) \
-npd-build-tar=`pwd`/../$(TARBALL) \
-boskos-project-type=$(BOSKOS_PROJECT_TYPE) -job-name=$(JOB_NAME) \
-artifacts-dir=$(ARTIFACTS)
$(NPD_NAME_VERSION)-%.tar.gz: $(ALL_BINARIES) test/e2e-install.sh
mkdir -p output/$*/ output/$*/test/
cp -r config/ output/$*/
cp test/e2e-install.sh output/$*/test/e2e-install.sh
(cd output/$*/ && tar -zcvf ../../$@ *)
sha512sum $@ > $@.sha512
image-$(NPD_NAME_VERSION)-linux_%.tar.gz: output/linux_%/test/bin/problem-maker test/e2e-install.sh
mkdir -p output/linux_$*/bin output/linux_$*/test
docker create --name npd-$* --platform linux/$* registry.k8s.io/node-problem-detector/node-problem-detector:$(TAG)
docker cp npd-$*:/node-problem-detector output/linux_$*/bin/
docker cp npd-$*:/home/kubernetes/bin/health-checker output/linux_$*/bin/
docker cp npd-$*:/home/kubernetes/bin/log-counter output/linux_$*/bin/
docker cp npd-$*:/config output/linux_$*/
docker rm -v npd-$*
cp test/e2e-install.sh output/linux_$*/test/e2e-install.sh
(cd output/linux_$*/ && tar -zcvf ../../$@ *)
cp $@ $(NPD_NAME_VERSION)-linux_$*.tar.gz
sha512sum $(NPD_NAME_VERSION)-linux_$*.tar.gz > $(NPD_NAME_VERSION)-linux_$*.tar.gz.sha512
image-$(NPD_NAME_VERSION)-windows_%.tar.gz: output/windows_%/test/bin/problem-maker.exe test/e2e-install.sh
mkdir -p output/windows_$*/bin output/windows_$*/test/
docker create --name npd-$* --platform windows/$* registry.k8s.io/node-problem-detector/node-problem-detector-windows:$(TAG)
docker cp npd-$*:/Files/node-problem-detector.exe output/windows_$*/bin/
docker cp npd-$*:/Files/etc/kubernetes/node/bin/health-checker.exe output/windows_$*/bin/
docker cp npd-$*:/Files/config output/windows_$*/
docker rm -v npd-$*
cp test/e2e-install.sh output/windows_$*/test/e2e-install.sh
(cd output/windows_$*/ && tar -zcvf ../../$@ *)
cp $@ $(NPD_NAME_VERSION)-windows_$*.tar.gz
sha512sum $(NPD_NAME_VERSION)-windows_$*.tar.gz > $(NPD_NAME_VERSION)-windows_$*.tar.gz.sha512
build-binaries: $(ALL_BINARIES)
build-container: clean Dockerfile
docker buildx create --platform $(DOCKER_PLATFORMS) --use
docker buildx build --platform $(DOCKER_PLATFORMS) $(IMAGE_TAGS) --build-arg LOGCOUNTER=$(LOGCOUNTER) .
build-container-windows: clean Dockerfile.windows
docker buildx create --platform windows/amd64 --use
docker buildx build --platform windows/amd64 $(IMAGE_TAGS_WINDOWS) -f Dockerfile.windows .
$(TARBALL): ./bin/node-problem-detector ./bin/log-counter ./bin/health-checker ./test/bin/problem-maker
tar -zcvf $(TARBALL) bin/ config/ test/e2e-install.sh test/bin/problem-maker
sha1sum $(TARBALL)
md5sum $(TARBALL)
build-tar: $(TARBALL) $(ALL_TARBALLS)
build: build-container build-tar
docker-builder:
docker build -t npd-builder . --target=builder
build-in-docker: clean docker-builder
docker run \
-v `pwd`:/gopath/src/k8s.io/node-problem-detector/ npd-builder:latest bash \
-c 'cd /gopath/src/k8s.io/node-problem-detector/ && make build-binaries'
push-container: build-container
# Build should be cached from build-container
docker buildx build --push --platform $(DOCKER_PLATFORMS) $(IMAGE_TAGS) --build-arg LOGCOUNTER=$(LOGCOUNTER) .
push-container-windows: build-container-windows
# Build should be cached from build-container
docker buildx build --push --platform windows/amd64 $(IMAGE_TAGS_WINDOWS) -f Dockerfile.windows .
push-tar: build-tar
gsutil cp $(TARBALL) $(UPLOAD_PATH)/node-problem-detector/
gsutil cp node-problem-detector-$(VERSION)-*.tar.gz* $(UPLOAD_PATH)/node-problem-detector/
# `make push` is used by presubmit and CI jobs.
push: push-container push-tar
# `make release` is used when releasing a new NPD version.
release: push-container build-tar print-tar-sha-md5
# `make release-new` is experimentally used when releasing a new NPD version.
release-new: image-$(NPD_NAME_VERSION)-linux_amd64.tar.gz image-$(NPD_NAME_VERSION)-linux_arm64.tar.gz image-$(NPD_NAME_VERSION)-windows_amd64.tar.gz print-tar-sha-md5
print-tar-sha-md5:
./hack/print-tar-sha-md5.sh $(VERSION)
coverage.out:
rm -f coverage.out
go test -coverprofile=coverage.out -timeout=1m -v -short ./...
clean:
rm -rf bin/
rm -rf test/bin/
rm -f node-problem-detector-*.tar.gz*
rm -rf output/
rm -f coverage.out
.PHONY: gomod
gomod:
go mod tidy
go mod vendor
cd test; go mod tidy
.PHONY: goget
goget:
go get $(shell go list -f '{{if not (or .Main .Indirect)}}{{.Path}}{{end}}' -mod=mod -m all)
.PHONY: depup
depup: goget gomod