Skip to content

Commit adbe770

Browse files
committed
replace k8s.io/apimachinery/pkg/util/clock with k8s.io/utils/clock
1 parent 608e129 commit adbe770

File tree

20 files changed

+402
-29
lines changed

20 files changed

+402
-29
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ require (
3333
k8s.io/client-go v11.0.1-0.20190805182717-6502b5e7b1b5+incompatible
3434
k8s.io/component-base v0.17.2
3535
k8s.io/klog v1.0.0
36+
k8s.io/utils v0.0.0-20200122174043-1e243dd1a584
3637
sigs.k8s.io/boskos v0.0.0-20200515170311-7d36bde8cdf6
3738
)
3839

@@ -95,7 +96,6 @@ require (
9596
gopkg.in/yaml.v3 v3.0.1 // indirect
9697
k8s.io/kube-openapi v0.0.0-20200410145947-bcb3869e6f29 // indirect
9798
k8s.io/test-infra v0.0.0-20200514184223-ba32c8aae783 // indirect
98-
k8s.io/utils v0.0.0-20200122174043-1e243dd1a584 // indirect
9999
sigs.k8s.io/yaml v1.2.0 // indirect
100100
)
101101

pkg/exporters/k8sexporter/condition/manager.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ import (
2626
"k8s.io/node-problem-detector/pkg/types"
2727
problemutil "k8s.io/node-problem-detector/pkg/util"
2828

29-
"k8s.io/api/core/v1"
30-
"k8s.io/apimachinery/pkg/util/clock"
29+
v1 "k8s.io/api/core/v1"
30+
"k8s.io/utils/clock"
3131

3232
"github.com/golang/glog"
3333
)
@@ -68,7 +68,7 @@ type conditionManager struct {
6868
// No lock is needed in `sync`, because it is in the same goroutine with the
6969
// write operation.
7070
sync.RWMutex
71-
clock clock.Clock
71+
clock clock.WithTicker
7272
latestTry time.Time
7373
resyncNeeded bool
7474
client problemclient.Client
@@ -79,10 +79,10 @@ type conditionManager struct {
7979
}
8080

8181
// NewConditionManager creates a condition manager.
82-
func NewConditionManager(client problemclient.Client, clock clock.Clock, heartbeatPeriod time.Duration) ConditionManager {
82+
func NewConditionManager(client problemclient.Client, clockInUse clock.WithTicker, heartbeatPeriod time.Duration) ConditionManager {
8383
return &conditionManager{
8484
client: client,
85-
clock: clock,
85+
clock: clockInUse,
8686
updates: make(map[string]types.Condition),
8787
conditions: make(map[string]types.Condition),
8888
heartbeatPeriod: heartbeatPeriod,

pkg/exporters/k8sexporter/condition/manager_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,14 @@ import (
2929
problemutil "k8s.io/node-problem-detector/pkg/util"
3030

3131
v1 "k8s.io/api/core/v1"
32-
"k8s.io/apimachinery/pkg/util/clock"
32+
testclock "k8s.io/utils/clock/testing"
3333
)
3434

3535
const heartbeatPeriod = 1 * time.Minute
3636

37-
func newTestManager() (*conditionManager, *problemclient.FakeProblemClient, *clock.FakeClock) {
37+
func newTestManager() (*conditionManager, *problemclient.FakeProblemClient, *testclock.FakeClock) {
3838
fakeClient := problemclient.NewFakeProblemClient()
39-
fakeClock := clock.NewFakeClock(time.Now())
39+
fakeClock := testclock.NewFakeClock(time.Now())
4040
manager := NewConditionManager(fakeClient, fakeClock, heartbeatPeriod)
4141
return manager.(*conditionManager), fakeClient, fakeClock
4242
}

pkg/exporters/k8sexporter/k8s_exporter.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ import (
2525

2626
"github.com/golang/glog"
2727

28-
"k8s.io/apimachinery/pkg/util/clock"
2928
"k8s.io/apimachinery/pkg/util/wait"
29+
"k8s.io/utils/clock"
3030

3131
"k8s.io/node-problem-detector/cmd/options"
3232
"k8s.io/node-problem-detector/pkg/exporters/k8sexporter/condition"

pkg/exporters/k8sexporter/problemclient/problem_client.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@ import (
2929
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
3030
"k8s.io/apimachinery/pkg/runtime"
3131
"k8s.io/apimachinery/pkg/types"
32-
"k8s.io/apimachinery/pkg/util/clock"
3332
clientset "k8s.io/client-go/kubernetes"
3433
typedcorev1 "k8s.io/client-go/kubernetes/typed/core/v1"
3534
"k8s.io/client-go/tools/record"
35+
"k8s.io/utils/clock"
3636

3737
"k8s.io/node-problem-detector/cmd/options"
3838
"k8s.io/node-problem-detector/pkg/version"
@@ -107,7 +107,7 @@ func (c *nodeProblemClient) SetConditions(ctx context.Context, newConditions []v
107107
if err != nil {
108108
return err
109109
}
110-
return c.client.RESTClient().Patch(types.StrategicMergePatchType).Resource("nodes").Name(c.nodeName).SubResource("status").Body(patch).Do().Error()
110+
return c.client.RESTClient().Patch(types.StrategicMergePatchType).Resource("nodes").Name(c.nodeName).SubResource("status").Body(patch).Do(ctx).Error()
111111
}
112112

113113
func (c *nodeProblemClient) Eventf(eventType, source, reason, messageFmt string, args ...interface{}) {
@@ -121,7 +121,7 @@ func (c *nodeProblemClient) Eventf(eventType, source, reason, messageFmt string,
121121
}
122122

123123
func (c *nodeProblemClient) GetNode(ctx context.Context) (*v1.Node, error) {
124-
return c.client.Nodes().Get(c.nodeName, metav1.GetOptions{})
124+
return c.client.Nodes().Get(ctx, c.nodeName, metav1.GetOptions{})
125125
}
126126

127127
// generatePatch generates condition patch

pkg/exporters/k8sexporter/problemclient/problem_client_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ import (
2222
"testing"
2323
"time"
2424

25-
"k8s.io/api/core/v1"
25+
v1 "k8s.io/api/core/v1"
2626
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
27-
"k8s.io/apimachinery/pkg/util/clock"
2827
"k8s.io/client-go/tools/record"
28+
testclock "k8s.io/utils/clock/testing"
2929

3030
"github.com/stretchr/testify/assert"
3131
)
@@ -40,7 +40,7 @@ func newFakeProblemClient() *nodeProblemClient {
4040
nodeName: testNode,
4141
// There is no proper fake for *client.Client for now
4242
// TODO(random-liu): Add test for SetConditions when we have good fake for *client.Client
43-
clock: &clock.FakeClock{},
43+
clock: testclock.NewFakeClock(time.Now()),
4444
recorders: make(map[string]record.EventRecorder),
4545
nodeRef: getNodeRef("", testNode),
4646
}

pkg/logcounter/log_counter.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import (
2323
"fmt"
2424
"time"
2525

26-
"k8s.io/apimachinery/pkg/util/clock"
26+
"k8s.io/utils/clock"
2727

2828
"k8s.io/node-problem-detector/cmd/logcounter/options"
2929
"k8s.io/node-problem-detector/pkg/logcounter/types"

pkg/logcounter/log_counter_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,16 @@ import (
2323
"testing"
2424
"time"
2525

26-
"k8s.io/apimachinery/pkg/util/clock"
26+
testclock "k8s.io/utils/clock/testing"
2727

2828
"k8s.io/node-problem-detector/pkg/logcounter/types"
2929
"k8s.io/node-problem-detector/pkg/systemlogmonitor"
3030
systemtypes "k8s.io/node-problem-detector/pkg/systemlogmonitor/types"
3131
)
3232

33-
func NewTestLogCounter(pattern string, startTime time.Time) (types.LogCounter, *clock.FakeClock, chan *systemtypes.Log) {
33+
func NewTestLogCounter(pattern string, startTime time.Time) (types.LogCounter, *testclock.FakeClock, chan *systemtypes.Log) {
3434
logCh := make(chan *systemtypes.Log)
35-
clock := clock.NewFakeClock(startTime)
35+
clock := testclock.NewFakeClock(startTime)
3636
return &logCounter{
3737
logCh: logCh,
3838
buffer: systemlogmonitor.NewLogBuffer(bufferSize),

pkg/systemlogmonitor/logwatchers/filelog/translator.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Licensed under the Apache License, Version 2.0 (the "License");
55
you may not use this file except in compliance with the License.
66
You may obtain a copy of the License at
77
8-
http://www.apache.org/licenses/LICENSE-2.0
8+
http://www.apache.org/licenses/LICENSE-2.0
99
1010
Unless required by applicable law or agreed to in writing, software
1111
distributed under the License is distributed on an "AS IS" BASIS,

pkg/util/helpers_linux.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Licensed under the Apache License, Version 2.0 (the "License");
55
you may not use this file except in compliance with the License.
66
You may obtain a copy of the License at
77
8-
http://www.apache.org/licenses/LICENSE-2.0
8+
http://www.apache.org/licenses/LICENSE-2.0
99
1010
Unless required by applicable law or agreed to in writing, software
1111
distributed under the License is distributed on an "AS IS" BASIS,

0 commit comments

Comments
 (0)