Skip to content

Commit b667a12

Browse files
authored
Merge pull request #294 from xueweiz/compile
Allow compilation time disabling for each type of Problem Daemon.
2 parents e10e6cc + be2647a commit b667a12

File tree

7 files changed

+87
-12
lines changed

7 files changed

+87
-12
lines changed

.travis.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,9 @@ install:
2121
script:
2222
- make
2323
- make test
24+
- make clean && BUILD_TAGS="disable_custom_plugin_monitor" make
25+
- BUILD_TAGS="disable_custom_plugin_monitor" make test
26+
- make clean && BUILD_TAGS="disable_system_log_monitor" make
27+
- BUILD_TAGS="disable_system_log_monitor" make test
28+
- make clean && BUILD_TAGS="disable_system_stats_monitor" make
29+
- BUILD_TAGS="disable_system_stats_monitor" make test

Makefile

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,16 +59,22 @@ BASEIMAGE:=k8s.gcr.io/debian-base-amd64:0.4.0
5959
# Disable cgo by default to make the binary statically linked.
6060
CGO_ENABLED:=0
6161

62+
# Construct the "-tags" parameter used by "go build".
63+
BUILD_TAGS?=""
6264
ifeq ($(ENABLE_JOURNALD), 1)
6365
# Enable journald build tag.
64-
BUILD_TAGS:=-tags journald
66+
BUILD_TAGS:=$(BUILD_TAGS) journald
6567
# Enable cgo because sdjournal needs cgo to compile. The binary will be
6668
# dynamically linked if CGO_ENABLED is enabled. This is fine because fedora
6769
# already has necessary dynamic library. We can not use `-extldflags "-static"`
6870
# here, because go-systemd uses dlopen, and dlopen will not work properly in a
6971
# statically linked application.
7072
CGO_ENABLED:=1
7173
endif
74+
ifneq ($(BUILD_TAGS), "")
75+
BUILD_TAGS:=-tags "$(BUILD_TAGS)"
76+
endif
77+
7278

7379
vet:
7480
GO111MODULE=on go list -mod vendor $(BUILD_TAGS) ./... | \
@@ -95,7 +101,7 @@ version:
95101
-o bin/node-problem-detector \
96102
-ldflags '-X $(PKG)/pkg/version.version=$(VERSION)' \
97103
$(BUILD_TAGS) \
98-
./cmd/node-problem-detector
104+
./cmd/nodeproblemdetector
99105

100106
Dockerfile: Dockerfile.in
101107
sed -e 's|@BASEIMAGE@|$(BASEIMAGE)|g' $< >$@

README.md

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,19 @@ Currently, a problem daemon is running as a goroutine in the node-problem-detect
5252
binary. In the future, we'll separate node-problem-detector and problem daemons into
5353
different containers, and compose them with pod specification.
5454

55+
Each catagory of problem daemon can be disabled at compilation time by setting
56+
corresponding build tags. If they are disabled at compilation time, then all their
57+
build dependencies, global variables and background goroutines will be trimmed out
58+
of the compiled executable.
59+
5560
List of supported problem daemons:
5661

57-
| Problem Daemon | NodeCondition | Description |
58-
|----------------|:---------------:|:------------|
59-
| [KernelMonitor](https://github.com/kubernetes/node-problem-detector/blob/master/config/kernel-monitor.json) | KernelDeadlock | A system log monitor monitors kernel log and reports problem according to predefined rules. |
60-
| [AbrtAdaptor](https://github.com/kubernetes/node-problem-detector/blob/master/config/abrt-adaptor.json) | None | Monitor ABRT log messages and report them further. ABRT (Automatic Bug Report Tool) is health monitoring daemon able to catch kernel problems as well as application crashes of various kinds occurred on the host. For more information visit the [link](https://github.com/abrt). |
61-
| [CustomPluginMonitor](https://github.com/kubernetes/node-problem-detector/blob/master/config/custom-plugin-monitor.json) | On-demand(According to users configuration) | A custom plugin monitor for node-problem-detector to invoke and check various node problems with user defined check scripts. See proposal [here](https://docs.google.com/document/d/1jK_5YloSYtboj-DtfjmYKxfNnUxCAvohLnsH5aGCAYQ/edit#). |
62-
| [SystemStatsMonitor](https://github.com/kubernetes/node-problem-detector/blob/master/config/system-stats-monitor.json) | None(Could be added in the future) | A system stats monitor for node-problem-detector to collect various health-related system stats as metrics. See proposal [here](https://docs.google.com/document/d/1SeaUz6kBavI283Dq8GBpoEUDrHA2a795xtw0OvjM568/edit). |
62+
| Problem Daemon | NodeCondition | Description | Disabling Build Tag |
63+
|----------------|:---------------:|:------------|:--------------------|
64+
| [KernelMonitor](https://github.com/kubernetes/node-problem-detector/blob/master/config/kernel-monitor.json) | KernelDeadlock | A system log monitor monitors kernel log and reports problem according to predefined rules. | disable_system_log_monitor
65+
| [AbrtAdaptor](https://github.com/kubernetes/node-problem-detector/blob/master/config/abrt-adaptor.json) | None | Monitor ABRT log messages and report them further. ABRT (Automatic Bug Report Tool) is health monitoring daemon able to catch kernel problems as well as application crashes of various kinds occurred on the host. For more information visit the [link](https://github.com/abrt). | disable_system_log_monitor
66+
| [CustomPluginMonitor](https://github.com/kubernetes/node-problem-detector/blob/master/config/custom-plugin-monitor.json) | On-demand(According to users configuration) | A custom plugin monitor for node-problem-detector to invoke and check various node problems with user defined check scripts. See proposal [here](https://docs.google.com/document/d/1jK_5YloSYtboj-DtfjmYKxfNnUxCAvohLnsH5aGCAYQ/edit#). | disable_custom_plugin_monitor
67+
| [SystemStatsMonitor](https://github.com/kubernetes/node-problem-detector/blob/master/config/system-stats-monitor.json) | None(Could be added in the future) | A system stats monitor for node-problem-detector to collect various health-related system stats as metrics. See proposal [here](https://docs.google.com/document/d/1SeaUz6kBavI283Dq8GBpoEUDrHA2a795xtw0OvjM568/edit). | disable_system_stats_monitor
6368

6469
# Exporter
6570

@@ -117,6 +122,18 @@ with one of the below directions:
117122
* Build the binary.
118123
* Build the docker image. The binary and `config/` are copied into the docker image.
119124

125+
If you do not need certain categories of problem daemons, you could choose to disable them at compilation time. This is the
126+
best way of keeping your node-problem-detector runtime compact without unnecessary code (e.g. global
127+
variables, goroutines, etc). You can do so via setting the `BUILD_TAGS` environment variable
128+
before running `make`. For example:
129+
130+
`BUILD_TAGS="disable_custom_plugin_monitor disable_system_stats_monitor" make`
131+
132+
Above command will compile the node-problem-detector without [Custom Plugin Monitor](https://github.com/kubernetes/node-problem-detector/tree/master/pkg/custompluginmonitor)
133+
and [System Stats Monitor](https://github.com/kubernetes/node-problem-detector/tree/master/pkg/systemstatsmonitor).
134+
Check out the [Problem Daemon](https://github.com/kubernetes/node-problem-detector#problem-daemon) section
135+
to see how to disable each problem daemon during compilation time.
136+
120137
**Note**:
121138
By default node-problem-detector will be built with systemd support with `make` command. This requires systemd develop files.
122139
You should download the systemd develop files first. For Ubuntu, `libsystemd-journal-dev` package should

cmd/node-problem-detector/node_problem_detector.go renamed to cmd/nodeproblemdetector/node_problem_detector.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"github.com/spf13/pflag"
2424

2525
"k8s.io/node-problem-detector/cmd/options"
26+
_ "k8s.io/node-problem-detector/cmd/nodeproblemdetector/problemdaemonplugins"
2627
"k8s.io/node-problem-detector/pkg/exporters/k8sexporter"
2728
"k8s.io/node-problem-detector/pkg/exporters/prometheusexporter"
2829
"k8s.io/node-problem-detector/pkg/problemdaemon"

cmd/node-problem-detector/plugins.go renamed to cmd/nodeproblemdetector/problemdaemonplugins/custom_plugin_monitor_plugin.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// +build !disable_custom_plugin_monitor
2+
13
/*
24
Copyright 2019 The Kubernetes Authors All rights reserved.
35
@@ -14,11 +16,8 @@ See the License for the specific language governing permissions and
1416
limitations under the License.
1517
*/
1618

17-
package main
19+
package problemdaemonplugins
1820

19-
// register problem daemons here
2021
import (
2122
_ "k8s.io/node-problem-detector/pkg/custompluginmonitor"
22-
_ "k8s.io/node-problem-detector/pkg/systemlogmonitor"
23-
_ "k8s.io/node-problem-detector/pkg/systemstatsmonitor"
2423
)
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// +build !disable_system_log_monitor
2+
3+
/*
4+
Copyright 2019 The Kubernetes Authors All rights reserved.
5+
6+
Licensed under the Apache License, Version 2.0 (the "License");
7+
you may not use this file except in compliance with the License.
8+
You may obtain a copy of the License at
9+
10+
http://www.apache.org/licenses/LICENSE-2.0
11+
12+
Unless required by applicable law or agreed to in writing, software
13+
distributed under the License is distributed on an "AS IS" BASIS,
14+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
See the License for the specific language governing permissions and
16+
limitations under the License.
17+
*/
18+
19+
package problemdaemonplugins
20+
21+
import (
22+
_ "k8s.io/node-problem-detector/pkg/systemlogmonitor"
23+
)
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// +build !disable_system_stats_monitor
2+
3+
/*
4+
Copyright 2019 The Kubernetes Authors All rights reserved.
5+
6+
Licensed under the Apache License, Version 2.0 (the "License");
7+
you may not use this file except in compliance with the License.
8+
You may obtain a copy of the License at
9+
10+
http://www.apache.org/licenses/LICENSE-2.0
11+
12+
Unless required by applicable law or agreed to in writing, software
13+
distributed under the License is distributed on an "AS IS" BASIS,
14+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
See the License for the specific language governing permissions and
16+
limitations under the License.
17+
*/
18+
19+
package problemdaemonplugins
20+
21+
import (
22+
_ "k8s.io/node-problem-detector/pkg/systemstatsmonitor"
23+
)

0 commit comments

Comments
 (0)