Merge pull request #502 from jeremyje/windows

Introduce Windows build of Node Problem Detector
This commit is contained in:
Kubernetes Prow Robot
2020-12-07 22:21:11 -08:00
committed by GitHub
10 changed files with 225 additions and 35 deletions

View File

@@ -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 \
@@ -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

View File

@@ -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"
@@ -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
}

View File

@@ -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
}

View File

@@ -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.")
}

View File

@@ -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
}

View File

@@ -17,7 +17,6 @@ package util
import (
"fmt"
"syscall"
"time"
"github.com/cobaugh/osrelease"
@@ -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)

31
pkg/util/helpers_linux.go Normal file
View File

@@ -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
}

View File

@@ -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
}