Skip to content

Introduce Windows build of Node Problem Detector #502

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,60 @@ fmt:
version:
@echo $(VERSION)

WINDOWS_AMD64_BINARIES = bin/windows_amd64/node-problem-detector.exe bin/windows_amd64/health-checker.exe
WINDOWS_AMD64_TEST_BINARIES = test/bin/windows_amd64/problem-maker.exe
LINUX_AMD64_BINARIES = bin/linux_amd64/node-problem-detector bin/linux_amd64/health-checker
LINUX_AMD64_TEST_BINARIES = test/bin/linux_amd64/problem-maker
ifeq ($(ENABLE_JOURNALD), 1)
LINUX_AMD64_BINARIES += bin/linux_amd64/log-counter
endif

windows-binaries: $(WINDOWS_AMD64_BINARIES) $(WINDOWS_AMD64_TEST_BINARIES)

bin/windows_amd64/%.exe: $(PKG_SOURCES)
ifeq ($(ENABLE_JOURNALD), 1)
echo "Journald on Windows is not supported, use make ENABLE_JOURNALD=0 [TARGET]"
endif
GOOS=windows GOARCH=amd64 CGO_ENABLED=$(CGO_ENABLED) GO111MODULE=on go build \
-mod vendor \
-o $@ \
-ldflags '-X $(PKG)/pkg/version.version=$(VERSION)' \
-tags "$(BUILD_TAGS)" \
./cmd/$(subst -,,$*)/$(subst -,_,$*).go
touch $@

./test/bin/windows_amd64/%.exe: $(PKG_SOURCES)
ifeq ($(ENABLE_JOURNALD), 1)
echo "Journald on Windows is not supported, use make ENABLE_JOURNALD=0 [TARGET]"
endif
GOOS=windows GOARCH=amd64 CGO_ENABLED=$(CGO_ENABLED) GO111MODULE=on go build \
-mod vendor \
-o $@ \
-tags "$(BUILD_TAGS)" \
./test/e2e/$(subst -,,$*)/$(subst -,_,$*).go

bin/linux_amd64/%: $(PKG_SOURCES)
GOOS=linux GOARCH=amd64 CGO_ENABLED=$(CGO_ENABLED) GO111MODULE=on go build \
-mod vendor \
-o $@ \
-ldflags '-X $(PKG)/pkg/version.version=$(VERSION)' \
-tags "$(BUILD_TAGS)" \
./cmd/$(subst -,,$*)/$(subst -,_,$*).go
touch $@

./test/bin/linux_amd64/%: $(PKG_SOURCES)
GOOS=linux GOARCH=amd64 CGO_ENABLED=$(CGO_ENABLED) GO111MODULE=on go build \
-mod vendor \
-o $@ \
-tags "$(BUILD_TAGS)" \
./test/e2e/$(subst -,,$*)/$(subst -,_,$*).go

ifneq ($(ENABLE_JOURNALD), 1)
bin/linux_amd64/log-counter:
echo "Warning: log-counter requires journald, skipping."
endif

# In the future these targets should be deprecated.
./bin/log-counter: $(PKG_SOURCES)
ifeq ($(ENABLE_JOURNALD), 1)
CGO_ENABLED=$(CGO_ENABLED) GOOS=linux GO111MODULE=on go build \
Expand Down Expand Up @@ -175,5 +229,6 @@ clean:
rm -f bin/health-checker
rm -f bin/log-counter
rm -f bin/node-problem-detector
rm -f $(WINDOWS_AMD64_BINARIES) $(LINUX_AMD64_BINARIES)
rm -f test/bin/problem-maker
rm -f node-problem-detector-*.tar.gz
26 changes: 0 additions & 26 deletions pkg/systemlogmonitor/logwatchers/filelog/log_watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,12 @@ package filelog
import (
"bufio"
"bytes"
"fmt"
"io"
"os"
"strings"
"time"

utilclock "code.cloudfoundry.org/clock"
"github.com/golang/glog"
"github.com/google/cadvisor/utils/tail"

"k8s.io/node-problem-detector/pkg/systemlogmonitor/logwatchers/types"
logtypes "k8s.io/node-problem-detector/pkg/systemlogmonitor/types"
Expand Down Expand Up @@ -135,26 +132,3 @@ func (s *filelogWatcher) watchLoop() {
s.logCh <- log
}
}

// getLogReader returns log reader for filelog log. Note that getLogReader doesn't look back
// to the rolled out logs.
func getLogReader(path string) (io.ReadCloser, error) {
if path == "" {
return nil, fmt.Errorf("unexpected empty log path")
}
// To handle log rotation, tail will not report error immediately if
// the file doesn't exist. So we check file existence first.
// This could go wrong during mid-rotation. It should recover after
// several restart when the log file is created again. The chance
// is slim but we should still fix this in the future.
// TODO(random-liu): Handle log missing during rotation.
_, err := os.Stat(path)
if err != nil {
return nil, fmt.Errorf("failed to stat the file %q: %v", path, err)
}
tail, err := tail.NewTail(path)
if err != nil {
return nil, fmt.Errorf("failed to tail the file %q: %v", path, err)
}
return tail, nil
}
48 changes: 48 additions & 0 deletions pkg/systemlogmonitor/logwatchers/filelog/log_watcher_linux.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
Copyright 2016 The Kubernetes Authors All rights reserved.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package filelog

import (
"fmt"
"io"
"os"

"github.com/google/cadvisor/utils/tail"
)

// getLogReader returns log reader for filelog log. Note that getLogReader doesn't look back
// to the rolled out logs.
func getLogReader(path string) (io.ReadCloser, error) {
if path == "" {
return nil, fmt.Errorf("unexpected empty log path")
}
// To handle log rotation, tail will not report error immediately if
// the file doesn't exist. So we check file existence first.
// This could go wrong during mid-rotation. It should recover after
// several restart when the log file is created again. The chance
// is slim but we should still fix this in the future.
// TODO(random-liu): Handle log missing during rotation.
_, err := os.Stat(path)
if err != nil {
return nil, fmt.Errorf("failed to stat the file %q: %v", path, err)
}
tail, err := tail.NewTail(path)
if err != nil {
return nil, fmt.Errorf("failed to tail the file %q: %v", path, err)
}
return tail, nil
}
29 changes: 29 additions & 0 deletions pkg/systemlogmonitor/logwatchers/filelog/log_watcher_windows.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
Copyright 2016 The Kubernetes Authors All rights reserved.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package filelog

import (
"fmt"
"io"
)

// getLogReader returns log reader for filelog log. Note that getLogReader doesn't look back
// to the rolled out logs.
func getLogReader(path string) (io.ReadCloser, error) {
// TODO: Support this on windows.
return nil, fmt.Errorf("not supported on windows.")
}
31 changes: 31 additions & 0 deletions pkg/systemlogmonitor/logwatchers/kmsg/log_watcher_windows.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
Copyright 2017 The Kubernetes Authors All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package kmsg

import (
"runtime"

"github.com/golang/glog"

"k8s.io/node-problem-detector/pkg/systemlogmonitor/logwatchers/types"
)

// NewKmsgWatcher creates a watcher which will read messages from /dev/kmsg
func NewKmsgWatcher(cfg types.WatcherConfig) types.LogWatcher {
glog.Fatalf("kmsg parser is not supported in %s", runtime.GOOS)
return nil
}
9 changes: 0 additions & 9 deletions pkg/util/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ package util

import (
"fmt"
"syscall"
"time"

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

func GetUptimeDuration() (time.Duration, error) {
var info syscall.Sysinfo_t
if err := syscall.Sysinfo(&info); err != nil {
return 0, fmt.Errorf("failed to get system info: %v", err)
}
return time.Duration(info.Uptime) * time.Second, nil
}

func GetStartTime(now time.Time, uptimeDuration time.Duration, lookbackStr string, delayStr string) (time.Time, error) {
startTime := now.Add(-uptimeDuration)

Expand Down
31 changes: 31 additions & 0 deletions pkg/util/helpers_linux.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
Copyright 2017 The Kubernetes Authors All rights reserved.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package util

import (
"fmt"
"syscall"
"time"
)

// GetUptimeDuration returns the time elapsed since last boot.
func GetUptimeDuration() (time.Duration, error) {
var info syscall.Sysinfo_t
if err := syscall.Sysinfo(&info); err != nil {
return 0, fmt.Errorf("failed to get system info: %v", err)
}
return time.Duration(info.Uptime) * time.Second, nil
}
31 changes: 31 additions & 0 deletions pkg/util/helpers_windows.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
Copyright 2017 The Kubernetes Authors All rights reserved.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package util

import (
"time"

"github.com/shirou/gopsutil/host"
)

// GetUptimeDuration returns the time elapsed since last boot.
func GetUptimeDuration() (time.Duration, error) {
ut, err := host.Uptime()
if err != nil {
return 0, err
}
return time.Duration(ut), nil
}