Skip to content

Commit e394763

Browse files
committed
Update Makefile to support compile journald support
1 parent c15d463 commit e394763

File tree

4 files changed

+74
-16
lines changed

4 files changed

+74
-16
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
/bin/node-problem-detector
2+
/Dockerfile

Dockerfile renamed to Dockerfile.in

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,12 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
FROM alpine:3.4
15+
FROM @BASEIMAGE@
1616
MAINTAINER Random Liu <[email protected]>
17+
18+
# Avoid symlink of /etc/localtime.
19+
RUN test -h /etc/localtime && rm -f /etc/localtime && cp /usr/share/zoneinfo/UTC /etc/localtime || true
20+
1721
ADD ./bin/node-problem-detector /node-problem-detector
1822
ADD config /config
1923
ENTRYPOINT ["/node-problem-detector", "--kernel-monitor=/config/kernel-monitor.json"]

Makefile

Lines changed: 67 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,73 @@
1-
.PHONY: all build-container build-tar build push-container push-tar push clean vet fmt version
1+
# Copyright 2017 The Kubernetes Authors.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
# Build the node-problem-detector image.
16+
17+
.PHONY: all build-container build-tar build push-container push-tar push clean vet fmt version Dockerfile
218

319
all: build
420

5-
VERSION := $(shell git describe --tags --dirty)
21+
# VERSION is the version of the binary.
22+
VERSION:=$(shell git describe --tags --dirty)
623

7-
TAG ?= $(VERSION)
24+
# TAG is the tag of the container image, default to binary version.
25+
TAG?=$(VERSION)
826

9-
UPLOAD_PATH ?= gs://kubernetes-release
27+
# PROJ is the image project.
28+
PROJ?=gcr.io/google_containers
29+
30+
# UPLOAD_PATH is the cloud storage path to upload release tar.
31+
UPLOAD_PATH?=gs://kubernetes-release
1032
# Trim the trailing '/' in the path
11-
UPLOAD_PATH := $(shell echo $(UPLOAD_PATH) | sed '$$s/\/*$$//')
33+
UPLOAD_PATH:=$(shell echo $(UPLOAD_PATH) | sed '$$s/\/*$$//')
34+
35+
# PKG is the package name of node problem detector repo.
36+
PKG:=k8s.io/node-problem-detector
37+
38+
# PKG_SOURCES are all the go source code.
39+
PKG_SOURCES:=$(shell find pkg cmd -name '*.go')
1240

13-
PROJ ?= google_containers
41+
# TARBALL is the name of release tar. Include binary version by default.
42+
TARBALL:=node-problem-detector-$(VERSION).tar.gz
1443

15-
PKG := k8s.io/node-problem-detector
44+
# IMAGE is the image name of the node problem detector container image.
45+
IMAGE:=$(PROJ)/node-problem-detector:$(TAG)
1646

17-
PKG_SOURCES := $(shell find pkg cmd -name '*.go')
47+
# ENABLE_JOURNALD enables build journald support or not. Building journald support needs libsystemd-dev
48+
# or libsystemd-journal-dev.
49+
# TODO(random-liu): Build NPD inside container.
50+
ENABLE_JOURNALD?=1
1851

19-
TARBALL := node-problem-detector-$(VERSION).tar.gz
52+
# TODO(random-liu): Support different architectures.
53+
BASEIMAGE:=alpine:3.4
2054

21-
IMAGE := gcr.io/$(PROJ)/node-problem-detector:$(TAG)
55+
# Disable cgo by default to make the binary statically linked.
56+
CGO_ENABLED:=0
57+
58+
# NOTE that enable journald will increase the image size.
59+
ifeq ($(ENABLE_JOURNALD), 1)
60+
# Enable journald build tag.
61+
BUILD_TAGS:=-tags journald
62+
# Use fedora because it has newer systemd version (229) and support +LZ4. +LZ4 is needed
63+
# on some os distros such as GCI.
64+
BASEIMAGE:=fedora
65+
# Enable cgo because sdjournal needs cgo to compile. The binary will be dynamically
66+
# linked if CGO_ENABLED is enabled. This is fine because fedora already has necessary
67+
# dynamic library. We can not use `-extldflags "-static"` here, because go-systemd uses
68+
# dlopen, and dlopen will not work properly in a statically linked application.
69+
CGO_ENABLED:=1
70+
endif
2271

2372
vet:
2473
go list ./... | grep -v "./vendor/*" | xargs go vet
@@ -30,14 +79,17 @@ version:
3079
@echo $(VERSION)
3180

3281
./bin/node-problem-detector: $(PKG_SOURCES)
33-
GOOS=linux go build -o bin/node-problem-detector \
34-
-ldflags '-w -extldflags "-static" -X $(PKG)/pkg/version.version=$(VERSION)' \
35-
cmd/node_problem_detector.go
82+
CGO_ENABLED=$(CGO_ENABLED) GOOS=linux go build -o bin/node-problem-detector \
83+
-ldflags '-w -X $(PKG)/pkg/version.version=$(VERSION)' \
84+
$(BUILD_TAGS) cmd/node_problem_detector.go
85+
86+
Dockerfile: Dockerfile.in
87+
sed -e 's|@BASEIMAGE@|$(BASEIMAGE)|g' $< >$@
3688

3789
test: vet fmt
38-
go test -timeout=1m -v -race ./pkg/...
90+
go test -timeout=1m -v -race ./pkg/... $(BUILD_TAGS)
3991

40-
build-container: ./bin/node-problem-detector
92+
build-container: ./bin/node-problem-detector Dockerfile
4193
docker build -t $(IMAGE) .
4294

4395
build-tar: ./bin/node-problem-detector

node-problem-detector.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ spec:
1212
- name: node-problem-detector
1313
command:
1414
- /node-problem-detector
15+
- --logtostderr
1516
- --kernel-monitor=/config/kernel-monitor.json
1617
image: gcr.io/google_containers/node-problem-detector:v0.2
1718
imagePullPolicy: Always

0 commit comments

Comments
 (0)