Skip to content

Commit d000c1b

Browse files
authored
Merge pull request #390 from xueweiz/make
Fix build tags manipulation in Makefile
2 parents ef30a1f + 5e55ef8 commit d000c1b

File tree

6 files changed

+27
-10
lines changed

6 files changed

+27
-10
lines changed

.travis.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,5 @@ script:
2929
- BUILD_TAGS="disable_system_stats_monitor" make test
3030
- make clean && BUILD_TAGS="disable_stackdriver_exporter" make
3131
- BUILD_TAGS="disable_stackdriver_exporter" make test
32+
- make clean && ENABLE_JOURNALD=0 make
33+
- ENABLE_JOURNALD=0 make test

Dockerfile.in

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ RUN clean-install libsystemd0 bash
2121
RUN test -h /etc/localtime && rm -f /etc/localtime && cp /usr/share/zoneinfo/UTC /etc/localtime || true
2222

2323
ADD ./bin/node-problem-detector /node-problem-detector
24+
25+
# Below command depends on ENABLE_JOURNAL=1.
2426
ADD ./bin/log-counter /home/kubernetes/bin/log-counter
27+
2528
ADD config /config
2629
ENTRYPOINT ["/node-problem-detector", "--system-log-monitors=/config/kernel-monitor.json"]

Makefile

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ BASEIMAGE:=k8s.gcr.io/debian-base-amd64:v1.0.0
6060
CGO_ENABLED:=0
6161

6262
# Construct the "-tags" parameter used by "go build".
63-
BUILD_TAGS?=""
63+
BUILD_TAGS?=
6464
ifeq ($(ENABLE_JOURNALD), 1)
6565
# Enable journald build tag.
6666
BUILD_TAGS:=$(BUILD_TAGS) journald
@@ -71,14 +71,11 @@ ifeq ($(ENABLE_JOURNALD), 1)
7171
# statically linked application.
7272
CGO_ENABLED:=1
7373
endif
74-
ifneq ($(BUILD_TAGS), "")
75-
BUILD_TAGS:=-tags "$(BUILD_TAGS)"
76-
endif
7774

7875
vet:
79-
GO111MODULE=on go list -mod vendor $(BUILD_TAGS) ./... | \
76+
GO111MODULE=on go list -mod vendor -tags "$(BUILD_TAGS)" ./... | \
8077
grep -v "./vendor/*" | \
81-
GO111MODULE=on xargs go vet -mod vendor $(BUILD_TAGS)
78+
GO111MODULE=on xargs go vet -mod vendor -tags "$(BUILD_TAGS)"
8279

8380
fmt:
8481
find . -type f -name "*.go" | grep -v "./vendor/*" | xargs gofmt -s -w -l
@@ -87,29 +84,38 @@ version:
8784
@echo $(VERSION)
8885

8986
./bin/log-counter: $(PKG_SOURCES)
87+
ifeq ($(ENABLE_JOURNALD), 1)
9088
CGO_ENABLED=$(CGO_ENABLED) GOOS=linux GO111MODULE=on go build \
9189
-mod vendor \
9290
-o bin/log-counter \
9391
-ldflags '-X $(PKG)/pkg/version.version=$(VERSION)' \
94-
$(BUILD_TAGS) \
92+
-tags "$(BUILD_TAGS)" \
9593
cmd/logcounter/log_counter.go
94+
else
95+
echo "Warning: log-counter requires journald, skipping."
96+
endif
9697

9798
./bin/node-problem-detector: $(PKG_SOURCES)
9899
CGO_ENABLED=$(CGO_ENABLED) GOOS=linux GO111MODULE=on go build \
99100
-mod vendor \
100101
-o bin/node-problem-detector \
101102
-ldflags '-X $(PKG)/pkg/version.version=$(VERSION)' \
102-
$(BUILD_TAGS) \
103+
-tags "$(BUILD_TAGS)" \
103104
./cmd/nodeproblemdetector
104105

105106
Dockerfile: Dockerfile.in
106107
sed -e 's|@BASEIMAGE@|$(BASEIMAGE)|g' $< >$@
108+
ifneq ($(ENABLE_JOURNALD), 1)
109+
sed -i '/Below command depends on ENABLE_JOURNAL=1/,+2d' $@
110+
echo "Warning: log-counter requires journald, skipping."
111+
endif
112+
107113

108114
test: vet fmt
109-
GO111MODULE=on go test -mod vendor -timeout=1m -v -race -short $(BUILD_TAGS) ./...
115+
GO111MODULE=on go test -mod vendor -timeout=1m -v -race -short -tags "$(BUILD_TAGS)" ./...
110116

111117
e2e-test: vet fmt build-tar
112-
GO111MODULE=on go test -mod vendor -timeout=10m -v $(BUILD_TAGS) \
118+
GO111MODULE=on go test -mod vendor -timeout=10m -v -tags "$(BUILD_TAGS)" \
113119
./test/e2e/metriconly/... \
114120
-project=$(PROJECT) -zone=$(ZONE) \
115121
-image=$(VM_IMAGE) -image-family=$(IMAGE_FAMILY) -image-project=$(IMAGE_PROJECT) \

cmd/logcounter/log_counter.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// +build journald
2+
13
/*
24
Copyright 2018 The Kubernetes Authors All rights reserved.
35

pkg/logcounter/log_counter.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// +build journald
2+
13
/*
24
Copyright 2018 The Kubernetes Authors All rights reserved.
35

pkg/logcounter/log_counter_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// +build journald
2+
13
/*
24
Copyright 2018 The Kubernetes Authors All rights reserved.
35

0 commit comments

Comments
 (0)