Skip to content

Commit be3b1ad

Browse files
authored
Merge pull request #807 from hakman/tests-mac
Update tests to run also on macOS
2 parents e2ef1de + f58f6cd commit be3b1ad

File tree

10 files changed

+185
-0
lines changed

10 files changed

+185
-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+
"github.com/golang/glog"
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+
glog.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+
glog.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+
glog.Fatalf("checkForPattern is not supported in %s", runtime.GOOS)
44+
return false, nil
45+
}
46+
47+
func getDockerPath() string {
48+
glog.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: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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+
"time"
20+
21+
"github.com/shirou/gopsutil/v3/host"
22+
)
23+
24+
// GetUptimeDuration returns the time elapsed since last boot.
25+
// For example: "cos 77-12293.0.0", "ubuntu 16.04.6 LTS (Xenial Xerus)".
26+
func GetUptimeDuration() (time.Duration, error) {
27+
ut, err := host.Uptime()
28+
if err != nil {
29+
return 0, err
30+
}
31+
return time.Duration(ut), nil
32+
}
33+
34+
// GetOSVersion retrieves the version of the current operating system.
35+
// For example: "darwin 13.5"".
36+
func GetOSVersion() (string, error) {
37+
platform, _, version, err := host.PlatformInformation()
38+
if err != nil {
39+
return "", err
40+
}
41+
42+
return platform + " " + version, nil
43+
}

0 commit comments

Comments
 (0)