Skip to content

Commit 8f2a94f

Browse files
authored
Merge pull request #502 from jeremyje/windows
Introduce Windows build of Node Problem Detector
2 parents bf51d66 + 4adec4b commit 8f2a94f

10 files changed

+225
-35
lines changed

Makefile

+55
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,60 @@ fmt:
8686
version:
8787
@echo $(VERSION)
8888

89+
WINDOWS_AMD64_BINARIES = bin/windows_amd64/node-problem-detector.exe bin/windows_amd64/health-checker.exe
90+
WINDOWS_AMD64_TEST_BINARIES = test/bin/windows_amd64/problem-maker.exe
91+
LINUX_AMD64_BINARIES = bin/linux_amd64/node-problem-detector bin/linux_amd64/health-checker
92+
LINUX_AMD64_TEST_BINARIES = test/bin/linux_amd64/problem-maker
93+
ifeq ($(ENABLE_JOURNALD), 1)
94+
LINUX_AMD64_BINARIES += bin/linux_amd64/log-counter
95+
endif
96+
97+
windows-binaries: $(WINDOWS_AMD64_BINARIES) $(WINDOWS_AMD64_TEST_BINARIES)
98+
99+
bin/windows_amd64/%.exe: $(PKG_SOURCES)
100+
ifeq ($(ENABLE_JOURNALD), 1)
101+
echo "Journald on Windows is not supported, use make ENABLE_JOURNALD=0 [TARGET]"
102+
endif
103+
GOOS=windows GOARCH=amd64 CGO_ENABLED=$(CGO_ENABLED) GO111MODULE=on go build \
104+
-mod vendor \
105+
-o $@ \
106+
-ldflags '-X $(PKG)/pkg/version.version=$(VERSION)' \
107+
-tags "$(BUILD_TAGS)" \
108+
./cmd/$(subst -,,$*)/$(subst -,_,$*).go
109+
touch $@
110+
111+
./test/bin/windows_amd64/%.exe: $(PKG_SOURCES)
112+
ifeq ($(ENABLE_JOURNALD), 1)
113+
echo "Journald on Windows is not supported, use make ENABLE_JOURNALD=0 [TARGET]"
114+
endif
115+
GOOS=windows GOARCH=amd64 CGO_ENABLED=$(CGO_ENABLED) GO111MODULE=on go build \
116+
-mod vendor \
117+
-o $@ \
118+
-tags "$(BUILD_TAGS)" \
119+
./test/e2e/$(subst -,,$*)/$(subst -,_,$*).go
120+
121+
bin/linux_amd64/%: $(PKG_SOURCES)
122+
GOOS=linux GOARCH=amd64 CGO_ENABLED=$(CGO_ENABLED) GO111MODULE=on go build \
123+
-mod vendor \
124+
-o $@ \
125+
-ldflags '-X $(PKG)/pkg/version.version=$(VERSION)' \
126+
-tags "$(BUILD_TAGS)" \
127+
./cmd/$(subst -,,$*)/$(subst -,_,$*).go
128+
touch $@
129+
130+
./test/bin/linux_amd64/%: $(PKG_SOURCES)
131+
GOOS=linux GOARCH=amd64 CGO_ENABLED=$(CGO_ENABLED) GO111MODULE=on go build \
132+
-mod vendor \
133+
-o $@ \
134+
-tags "$(BUILD_TAGS)" \
135+
./test/e2e/$(subst -,,$*)/$(subst -,_,$*).go
136+
137+
ifneq ($(ENABLE_JOURNALD), 1)
138+
bin/linux_amd64/log-counter:
139+
echo "Warning: log-counter requires journald, skipping."
140+
endif
141+
142+
# In the future these targets should be deprecated.
89143
./bin/log-counter: $(PKG_SOURCES)
90144
ifeq ($(ENABLE_JOURNALD), 1)
91145
CGO_ENABLED=$(CGO_ENABLED) GOOS=linux GO111MODULE=on go build \
@@ -175,5 +229,6 @@ clean:
175229
rm -f bin/health-checker
176230
rm -f bin/log-counter
177231
rm -f bin/node-problem-detector
232+
rm -f $(WINDOWS_AMD64_BINARIES) $(LINUX_AMD64_BINARIES)
178233
rm -f test/bin/problem-maker
179234
rm -f node-problem-detector-*.tar.gz

pkg/systemlogmonitor/logwatchers/filelog/log_watcher.go

-26
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,12 @@ package filelog
1919
import (
2020
"bufio"
2121
"bytes"
22-
"fmt"
2322
"io"
24-
"os"
2523
"strings"
2624
"time"
2725

2826
utilclock "code.cloudfoundry.org/clock"
2927
"github.com/golang/glog"
30-
"github.com/google/cadvisor/utils/tail"
3128

3229
"k8s.io/node-problem-detector/pkg/systemlogmonitor/logwatchers/types"
3330
logtypes "k8s.io/node-problem-detector/pkg/systemlogmonitor/types"
@@ -135,26 +132,3 @@ func (s *filelogWatcher) watchLoop() {
135132
s.logCh <- log
136133
}
137134
}
138-
139-
// getLogReader returns log reader for filelog log. Note that getLogReader doesn't look back
140-
// to the rolled out logs.
141-
func getLogReader(path string) (io.ReadCloser, error) {
142-
if path == "" {
143-
return nil, fmt.Errorf("unexpected empty log path")
144-
}
145-
// To handle log rotation, tail will not report error immediately if
146-
// the file doesn't exist. So we check file existence first.
147-
// This could go wrong during mid-rotation. It should recover after
148-
// several restart when the log file is created again. The chance
149-
// is slim but we should still fix this in the future.
150-
// TODO(random-liu): Handle log missing during rotation.
151-
_, err := os.Stat(path)
152-
if err != nil {
153-
return nil, fmt.Errorf("failed to stat the file %q: %v", path, err)
154-
}
155-
tail, err := tail.NewTail(path)
156-
if err != nil {
157-
return nil, fmt.Errorf("failed to tail the file %q: %v", path, err)
158-
}
159-
return tail, nil
160-
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
Copyright 2016 The Kubernetes Authors All rights reserved.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package filelog
18+
19+
import (
20+
"fmt"
21+
"io"
22+
"os"
23+
24+
"github.com/google/cadvisor/utils/tail"
25+
)
26+
27+
// getLogReader returns log reader for filelog log. Note that getLogReader doesn't look back
28+
// to the rolled out logs.
29+
func getLogReader(path string) (io.ReadCloser, error) {
30+
if path == "" {
31+
return nil, fmt.Errorf("unexpected empty log path")
32+
}
33+
// To handle log rotation, tail will not report error immediately if
34+
// the file doesn't exist. So we check file existence first.
35+
// This could go wrong during mid-rotation. It should recover after
36+
// several restart when the log file is created again. The chance
37+
// is slim but we should still fix this in the future.
38+
// TODO(random-liu): Handle log missing during rotation.
39+
_, err := os.Stat(path)
40+
if err != nil {
41+
return nil, fmt.Errorf("failed to stat the file %q: %v", path, err)
42+
}
43+
tail, err := tail.NewTail(path)
44+
if err != nil {
45+
return nil, fmt.Errorf("failed to tail the file %q: %v", path, err)
46+
}
47+
return tail, nil
48+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
Copyright 2016 The Kubernetes Authors All rights reserved.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package filelog
18+
19+
import (
20+
"fmt"
21+
"io"
22+
)
23+
24+
// getLogReader returns log reader for filelog log. Note that getLogReader doesn't look back
25+
// to the rolled out logs.
26+
func getLogReader(path string) (io.ReadCloser, error) {
27+
// TODO: Support this on windows.
28+
return nil, fmt.Errorf("not supported on windows.")
29+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
Copyright 2017 The Kubernetes Authors All rights reserved.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package kmsg
18+
19+
import (
20+
"runtime"
21+
22+
"github.com/golang/glog"
23+
24+
"k8s.io/node-problem-detector/pkg/systemlogmonitor/logwatchers/types"
25+
)
26+
27+
// NewKmsgWatcher creates a watcher which will read messages from /dev/kmsg
28+
func NewKmsgWatcher(cfg types.WatcherConfig) types.LogWatcher {
29+
glog.Fatalf("kmsg parser is not supported in %s", runtime.GOOS)
30+
return nil
31+
}

pkg/util/helpers.go

-9
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ package util
1717

1818
import (
1919
"fmt"
20-
"syscall"
2120
"time"
2221

2322
"github.com/cobaugh/osrelease"
@@ -37,14 +36,6 @@ func GenerateConditionChangeEvent(t string, status types.ConditionStatus, reason
3736
}
3837
}
3938

40-
func GetUptimeDuration() (time.Duration, error) {
41-
var info syscall.Sysinfo_t
42-
if err := syscall.Sysinfo(&info); err != nil {
43-
return 0, fmt.Errorf("failed to get system info: %v", err)
44-
}
45-
return time.Duration(info.Uptime) * time.Second, nil
46-
}
47-
4839
func GetStartTime(now time.Time, uptimeDuration time.Duration, lookbackStr string, delayStr string) (time.Time, error) {
4940
startTime := now.Add(-uptimeDuration)
5041

pkg/util/helpers_linux.go

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
Copyright 2017 The Kubernetes Authors All rights reserved.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
package util
17+
18+
import (
19+
"fmt"
20+
"syscall"
21+
"time"
22+
)
23+
24+
// GetUptimeDuration returns the time elapsed since last boot.
25+
func GetUptimeDuration() (time.Duration, error) {
26+
var info syscall.Sysinfo_t
27+
if err := syscall.Sysinfo(&info); err != nil {
28+
return 0, fmt.Errorf("failed to get system info: %v", err)
29+
}
30+
return time.Duration(info.Uptime) * time.Second, nil
31+
}

pkg/util/helpers_windows.go

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
Copyright 2017 The Kubernetes Authors All rights reserved.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
package util
17+
18+
import (
19+
"time"
20+
21+
"github.com/shirou/gopsutil/host"
22+
)
23+
24+
// GetUptimeDuration returns the time elapsed since last boot.
25+
func GetUptimeDuration() (time.Duration, error) {
26+
ut, err := host.Uptime()
27+
if err != nil {
28+
return 0, err
29+
}
30+
return time.Duration(ut), nil
31+
}

0 commit comments

Comments
 (0)