Remove dependency on code.cloudfoundry.org/clock

This commit is contained in:
Ciprian Hacman
2023-09-19 12:43:15 +03:00
parent fb498567b4
commit 65e4aa3c5e
18 changed files with 4 additions and 607 deletions

View File

@@ -23,7 +23,6 @@ import (
"strings"
"time"
utilclock "code.cloudfoundry.org/clock"
"k8s.io/klog/v2"
"k8s.io/node-problem-detector/pkg/systemlogmonitor/logwatchers/types"
@@ -40,7 +39,6 @@ type filelogWatcher struct {
logCh chan *logtypes.Log
startTime time.Time
tomb *tomb.Tomb
clock utilclock.Clock
}
// NewSyslogWatcherOrDie creates a new log watcher. The function panics
@@ -62,7 +60,6 @@ func NewSyslogWatcherOrDie(cfg types.WatcherConfig) types.LogWatcher {
tomb: tomb.NewTomb(),
// A capacity 1000 buffer should be enough
logCh: make(chan *logtypes.Log, 1000),
clock: utilclock.NewClock(),
}
}

View File

@@ -25,8 +25,8 @@ import (
logtypes "k8s.io/node-problem-detector/pkg/systemlogmonitor/types"
"k8s.io/node-problem-detector/pkg/util"
"code.cloudfoundry.org/clock/fakeclock"
"github.com/stretchr/testify/assert"
testclock "k8s.io/utils/clock/testing"
)
// getTestPluginConfig returns a plugin config for test. Use configuration for
@@ -42,7 +42,7 @@ func getTestPluginConfig() map[string]string {
func TestWatch(t *testing.T) {
// now is a fake time
now := time.Date(time.Now().Year(), time.January, 2, 3, 4, 5, 0, time.Local)
fakeClock := fakeclock.NewFakeClock(now)
fakeClock := testclock.NewFakeClock(now)
testCases := []struct {
uptime time.Duration
lookback string
@@ -155,8 +155,6 @@ Jan 2 03:04:05 kernel: [2.000000] 3
})
// Set the startTime.
w.(*filelogWatcher).startTime, _ = util.GetStartTime(fakeClock.Now(), test.uptime, test.lookback, test.delay)
// Set the fake clock.
w.(*filelogWatcher).clock = fakeClock
logCh, err := w.Watch()
assert.NoError(t, err)
defer w.Stop()

View File

@@ -21,7 +21,6 @@ import (
"strings"
"time"
utilclock "code.cloudfoundry.org/clock"
"github.com/euank/go-kmsg-parser/kmsgparser"
"k8s.io/klog/v2"
@@ -38,7 +37,6 @@ type kernelLogWatcher struct {
tomb *tomb.Tomb
kmsgParser kmsgparser.Parser
clock utilclock.Clock
}
// NewKmsgWatcher creates a watcher which will read messages from /dev/kmsg
@@ -58,7 +56,6 @@ func NewKmsgWatcher(cfg types.WatcherConfig) types.LogWatcher {
tomb: tomb.NewTomb(),
// Arbitrary capacity
logCh: make(chan *logtypes.Log, 100),
clock: utilclock.NewClock(),
}
}

View File

@@ -17,12 +17,11 @@ limitations under the License.
package kmsg
import (
testclock "k8s.io/utils/clock/testing"
"testing"
"code.cloudfoundry.org/clock/fakeclock"
"github.com/euank/go-kmsg-parser/kmsgparser"
"github.com/stretchr/testify/assert"
"time"
"k8s.io/node-problem-detector/pkg/systemlogmonitor/logwatchers/types"
@@ -49,7 +48,7 @@ func (m *mockKmsgParser) SeekEnd() error { return nil }
func TestWatch(t *testing.T) {
now := time.Date(time.Now().Year(), time.January, 2, 3, 4, 5, 0, time.Local)
fakeClock := fakeclock.NewFakeClock(now)
fakeClock := testclock.NewFakeClock(now)
testCases := []struct {
uptime time.Duration
lookback string
@@ -150,7 +149,6 @@ func TestWatch(t *testing.T) {
for _, test := range testCases {
w := NewKmsgWatcher(types.WatcherConfig{Lookback: test.lookback})
w.(*kernelLogWatcher).startTime, _ = util.GetStartTime(fakeClock.Now(), test.uptime, test.lookback, test.delay)
w.(*kernelLogWatcher).clock = fakeClock
w.(*kernelLogWatcher).kmsgParser = test.log
logCh, err := w.Watch()
if err != nil {