Skip to content

Commit cf8c138

Browse files
committed
Update tests to run also on macOS
1 parent 9ff6b0b commit cf8c138

File tree

9 files changed

+188
-0
lines changed

9 files changed

+188
-0
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
Copyright 2023 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 healthchecker
18+
19+
import (
20+
"runtime"
21+
"time"
22+
23+
"k8s.io/klog/v2"
24+
25+
"k8s.io/node-problem-detector/cmd/healthchecker/options"
26+
)
27+
28+
// getUptimeFunc returns the time for which the given service has been running.
29+
func getUptimeFunc(service string) func() (time.Duration, error) {
30+
klog.Fatalf("getUptimeFunc is not supported in %s", runtime.GOOS)
31+
return func() (time.Duration, error) { return time.Second, nil }
32+
}
33+
34+
// getRepairFunc returns the repair function based on the component.
35+
func getRepairFunc(hco *options.HealthCheckerOptions) func() {
36+
klog.Fatalf("getRepairFunc is not supported in %s", runtime.GOOS)
37+
return func() {}
38+
}
39+
40+
// checkForPattern returns (true, nil) if logPattern occurs less than logCountThreshold number of times since last
41+
// service restart. (false, nil) otherwise.
42+
func checkForPattern(service, logStartTime, logPattern string, logCountThreshold int) (bool, error) {
43+
klog.Fatalf("checkForPattern is not supported in %s", runtime.GOOS)
44+
return false, nil
45+
}
46+
47+
func getDockerPath() string {
48+
klog.Fatalf("getDockerPath is not supported in %s", runtime.GOOS)
49+
return ""
50+
}

pkg/healthchecker/types/types_linux.go renamed to pkg/healthchecker/types/types_unix.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//go:build unix
2+
13
/*
24
Copyright 2021 The Kubernetes Authors All rights reserved.
35
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
Copyright 2023 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+
"io"
21+
22+
"github.com/hpcloud/tail"
23+
)
24+
25+
// getLogReader returns log reader for filelog log. Note that getLogReader doesn't look back
26+
// to the rolled out logs.
27+
func getLogReader(path string) (io.ReadCloser, error) {
28+
return tail.OpenFile(path)
29+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
Copyright 2023 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/systemstatsmonitor/cpu_collector_linux.go renamed to pkg/systemstatsmonitor/cpu_collector_unix.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//go:build unix
2+
13
/*
24
Copyright 2020 The Kubernetes Authors All rights reserved.
35

pkg/systemstatsmonitor/memory_collector_linux.go renamed to pkg/systemstatsmonitor/memory_collector_unix.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//go:build unix
2+
13
/*
24
Copyright 2020 The Kubernetes Authors All rights reserved.
35
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
Copyright 2023 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 types
18+
19+
const defaultProcPath = ""
20+
21+
func (ssc *SystemStatsConfig) validateProcPath() error {
22+
// not supported
23+
return nil
24+
}

pkg/util/exec_linux.go renamed to pkg/util/exec_unix.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//go:build unix
2+
13
/*
24
Copyright 2021 The Kubernetes Authors All rights reserved.
35

pkg/util/helpers_darwin.go

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
Copyright 2023 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+
"golang.org/x/sys/unix"
20+
"time"
21+
22+
"github.com/shirou/gopsutil/host"
23+
)
24+
25+
// GetUptimeDuration returns the time elapsed since last boot.
26+
// For example: "cos 77-12293.0.0", "ubuntu 16.04.6 LTS (Xenial Xerus)".
27+
func GetUptimeDuration() (time.Duration, error) {
28+
ut, err := host.Uptime()
29+
if err != nil {
30+
return 0, err
31+
}
32+
return time.Duration(ut), nil
33+
}
34+
35+
// GetOSVersion retrieves the version of the current operating system.
36+
func GetOSVersion() (string, error) {
37+
var uts unix.Utsname
38+
if err := unix.Uname(&uts); err != nil {
39+
return "", err
40+
}
41+
42+
sysname := unix.ByteSliceToString(uts.Sysname[:])
43+
release := unix.ByteSliceToString(uts.Release[:])
44+
45+
return sysname + " " + release, nil
46+
}

0 commit comments

Comments
 (0)