From 5e55ef89f1eb24d7c49c7ae0841c7f467afdfb12 Mon Sep 17 00:00:00 2001 From: Xuewei Zhang Date: Tue, 26 Nov 2019 13:29:11 -0800 Subject: [PATCH] Make log-counter respect ENABLE_JOURNALD --- Dockerfile.in | 3 +++ Makefile | 9 +++++++++ cmd/logcounter/log_counter.go | 2 ++ pkg/logcounter/log_counter.go | 2 ++ pkg/logcounter/log_counter_test.go | 2 ++ 5 files changed, 18 insertions(+) diff --git a/Dockerfile.in b/Dockerfile.in index 076f5be2..ee0609c5 100644 --- a/Dockerfile.in +++ b/Dockerfile.in @@ -21,6 +21,9 @@ RUN clean-install libsystemd0 bash RUN test -h /etc/localtime && rm -f /etc/localtime && cp /usr/share/zoneinfo/UTC /etc/localtime || true ADD ./bin/node-problem-detector /node-problem-detector + +# Below command depends on ENABLE_JOURNAL=1. ADD ./bin/log-counter /home/kubernetes/bin/log-counter + ADD config /config ENTRYPOINT ["/node-problem-detector", "--system-log-monitors=/config/kernel-monitor.json"] diff --git a/Makefile b/Makefile index c14b0760..f746c3d0 100644 --- a/Makefile +++ b/Makefile @@ -84,12 +84,16 @@ version: @echo $(VERSION) ./bin/log-counter: $(PKG_SOURCES) +ifeq ($(ENABLE_JOURNALD), 1) CGO_ENABLED=$(CGO_ENABLED) GOOS=linux GO111MODULE=on go build \ -mod vendor \ -o bin/log-counter \ -ldflags '-X $(PKG)/pkg/version.version=$(VERSION)' \ -tags "$(BUILD_TAGS)" \ cmd/logcounter/log_counter.go +else + echo "Warning: log-counter requires journald, skipping." +endif ./bin/node-problem-detector: $(PKG_SOURCES) CGO_ENABLED=$(CGO_ENABLED) GOOS=linux GO111MODULE=on go build \ @@ -101,6 +105,11 @@ version: Dockerfile: Dockerfile.in sed -e 's|@BASEIMAGE@|$(BASEIMAGE)|g' $< >$@ +ifneq ($(ENABLE_JOURNALD), 1) + sed -i '/Below command depends on ENABLE_JOURNAL=1/,+2d' $@ + echo "Warning: log-counter requires journald, skipping." +endif + test: vet fmt GO111MODULE=on go test -mod vendor -timeout=1m -v -race -short -tags "$(BUILD_TAGS)" ./... diff --git a/cmd/logcounter/log_counter.go b/cmd/logcounter/log_counter.go index d3c03de2..21ee1e9c 100644 --- a/cmd/logcounter/log_counter.go +++ b/cmd/logcounter/log_counter.go @@ -1,3 +1,5 @@ +// +build journald + /* Copyright 2018 The Kubernetes Authors All rights reserved. diff --git a/pkg/logcounter/log_counter.go b/pkg/logcounter/log_counter.go index 7fd22e57..c31f8c34 100644 --- a/pkg/logcounter/log_counter.go +++ b/pkg/logcounter/log_counter.go @@ -1,3 +1,5 @@ +// +build journald + /* Copyright 2018 The Kubernetes Authors All rights reserved. diff --git a/pkg/logcounter/log_counter_test.go b/pkg/logcounter/log_counter_test.go index 23ec27b0..adbf8f26 100644 --- a/pkg/logcounter/log_counter_test.go +++ b/pkg/logcounter/log_counter_test.go @@ -1,3 +1,5 @@ +// +build journald + /* Copyright 2018 The Kubernetes Authors All rights reserved.