mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-24 20:24:09 +00:00
Migrate to k8s.io/utils/clock in client-go
This commit is contained in:
parent
cb2ea4bf7c
commit
bb7dac443a
@ -24,8 +24,8 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"k8s.io/apimachinery/pkg/util/clock"
|
|
||||||
"k8s.io/apimachinery/pkg/util/runtime"
|
"k8s.io/apimachinery/pkg/util/runtime"
|
||||||
|
"k8s.io/utils/clock"
|
||||||
)
|
)
|
||||||
|
|
||||||
// For any test of the style:
|
// For any test of the style:
|
||||||
|
@ -26,8 +26,9 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"k8s.io/apimachinery/pkg/util/clock"
|
|
||||||
"k8s.io/apimachinery/pkg/util/runtime"
|
"k8s.io/apimachinery/pkg/util/runtime"
|
||||||
|
"k8s.io/utils/clock"
|
||||||
|
testingclock "k8s.io/utils/clock/testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestUntil(t *testing.T) {
|
func TestUntil(t *testing.T) {
|
||||||
@ -713,7 +714,7 @@ func TestContextForChannel(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestExponentialBackoffManagerGetNextBackoff(t *testing.T) {
|
func TestExponentialBackoffManagerGetNextBackoff(t *testing.T) {
|
||||||
fc := clock.NewFakeClock(time.Now())
|
fc := testingclock.NewFakeClock(time.Now())
|
||||||
backoff := NewExponentialBackoffManager(1, 10, 10, 2.0, 0.0, fc)
|
backoff := NewExponentialBackoffManager(1, 10, 10, 2.0, 0.0, fc)
|
||||||
durations := []time.Duration{1, 2, 4, 8, 10, 10, 10}
|
durations := []time.Duration{1, 2, 4, 8, 10, 10, 10}
|
||||||
for i := 0; i < len(durations); i++ {
|
for i := 0; i < len(durations); i++ {
|
||||||
@ -732,7 +733,7 @@ func TestExponentialBackoffManagerGetNextBackoff(t *testing.T) {
|
|||||||
|
|
||||||
func TestJitteredBackoffManagerGetNextBackoff(t *testing.T) {
|
func TestJitteredBackoffManagerGetNextBackoff(t *testing.T) {
|
||||||
// positive jitter
|
// positive jitter
|
||||||
backoffMgr := NewJitteredBackoffManager(1, 1, clock.NewFakeClock(time.Now()))
|
backoffMgr := NewJitteredBackoffManager(1, 1, testingclock.NewFakeClock(time.Now()))
|
||||||
for i := 0; i < 5; i++ {
|
for i := 0; i < 5; i++ {
|
||||||
backoff := backoffMgr.(*jitteredBackoffManagerImpl).getNextBackoff()
|
backoff := backoffMgr.(*jitteredBackoffManagerImpl).getNextBackoff()
|
||||||
if backoff < 1 || backoff > 2 {
|
if backoff < 1 || backoff > 2 {
|
||||||
@ -741,7 +742,7 @@ func TestJitteredBackoffManagerGetNextBackoff(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// negative jitter, shall be a fixed backoff
|
// negative jitter, shall be a fixed backoff
|
||||||
backoffMgr = NewJitteredBackoffManager(1, -1, clock.NewFakeClock(time.Now()))
|
backoffMgr = NewJitteredBackoffManager(1, -1, testingclock.NewFakeClock(time.Now()))
|
||||||
backoff := backoffMgr.(*jitteredBackoffManagerImpl).getNextBackoff()
|
backoff := backoffMgr.(*jitteredBackoffManagerImpl).getNextBackoff()
|
||||||
if backoff != 1 {
|
if backoff != 1 {
|
||||||
t.Errorf("backoff should be 1, but got %d", backoff)
|
t.Errorf("backoff should be 1, but got %d", backoff)
|
||||||
|
@ -21,9 +21,9 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"k8s.io/apimachinery/pkg/runtime"
|
"k8s.io/apimachinery/pkg/runtime"
|
||||||
"k8s.io/apimachinery/pkg/util/clock"
|
|
||||||
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
|
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
|
||||||
"k8s.io/apimachinery/pkg/util/wait"
|
"k8s.io/apimachinery/pkg/util/wait"
|
||||||
|
"k8s.io/utils/clock"
|
||||||
)
|
)
|
||||||
|
|
||||||
// This file implements a low-level controller that is used in
|
// This file implements a low-level controller that is used in
|
||||||
|
@ -20,8 +20,8 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"k8s.io/apimachinery/pkg/util/clock"
|
|
||||||
"k8s.io/klog/v2"
|
"k8s.io/klog/v2"
|
||||||
|
"k8s.io/utils/clock"
|
||||||
)
|
)
|
||||||
|
|
||||||
// ExpirationCache implements the store interface
|
// ExpirationCache implements the store interface
|
||||||
|
@ -17,8 +17,8 @@ limitations under the License.
|
|||||||
package cache
|
package cache
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"k8s.io/apimachinery/pkg/util/clock"
|
|
||||||
"k8s.io/apimachinery/pkg/util/sets"
|
"k8s.io/apimachinery/pkg/util/sets"
|
||||||
|
"k8s.io/utils/clock"
|
||||||
)
|
)
|
||||||
|
|
||||||
type fakeThreadSafeMap struct {
|
type fakeThreadSafeMap struct {
|
||||||
|
@ -21,9 +21,10 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"k8s.io/apimachinery/pkg/util/clock"
|
|
||||||
"k8s.io/apimachinery/pkg/util/sets"
|
"k8s.io/apimachinery/pkg/util/sets"
|
||||||
"k8s.io/apimachinery/pkg/util/wait"
|
"k8s.io/apimachinery/pkg/util/wait"
|
||||||
|
"k8s.io/utils/clock"
|
||||||
|
testingclock "k8s.io/utils/clock/testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestTTLExpirationBasic(t *testing.T) {
|
func TestTTLExpirationBasic(t *testing.T) {
|
||||||
@ -167,7 +168,7 @@ func TestTTLPolicy(t *testing.T) {
|
|||||||
exactlyOnTTL := fakeTime.Add(-ttl)
|
exactlyOnTTL := fakeTime.Add(-ttl)
|
||||||
expiredTime := fakeTime.Add(-(ttl + 1))
|
expiredTime := fakeTime.Add(-(ttl + 1))
|
||||||
|
|
||||||
policy := TTLPolicy{ttl, clock.NewFakeClock(fakeTime)}
|
policy := TTLPolicy{ttl, testingclock.NewFakeClock(fakeTime)}
|
||||||
item := testStoreObject{id: "foo", val: "bar"}
|
item := testStoreObject{id: "foo", val: "bar"}
|
||||||
itemkey, _ := testStoreKeyFunc(item)
|
itemkey, _ := testStoreKeyFunc(item)
|
||||||
fakeTimestampedEntry := &TimestampedEntry{Obj: item, Timestamp: exactlyOnTTL, key: itemkey}
|
fakeTimestampedEntry := &TimestampedEntry{Obj: item, Timestamp: exactlyOnTTL, key: itemkey}
|
||||||
|
@ -32,7 +32,6 @@ import (
|
|||||||
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
|
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
|
||||||
"k8s.io/apimachinery/pkg/runtime"
|
"k8s.io/apimachinery/pkg/runtime"
|
||||||
"k8s.io/apimachinery/pkg/runtime/schema"
|
"k8s.io/apimachinery/pkg/runtime/schema"
|
||||||
"k8s.io/apimachinery/pkg/util/clock"
|
|
||||||
"k8s.io/apimachinery/pkg/util/naming"
|
"k8s.io/apimachinery/pkg/util/naming"
|
||||||
utilnet "k8s.io/apimachinery/pkg/util/net"
|
utilnet "k8s.io/apimachinery/pkg/util/net"
|
||||||
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
|
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
|
||||||
@ -40,6 +39,7 @@ import (
|
|||||||
"k8s.io/apimachinery/pkg/watch"
|
"k8s.io/apimachinery/pkg/watch"
|
||||||
"k8s.io/client-go/tools/pager"
|
"k8s.io/client-go/tools/pager"
|
||||||
"k8s.io/klog/v2"
|
"k8s.io/klog/v2"
|
||||||
|
"k8s.io/utils/clock"
|
||||||
"k8s.io/utils/trace"
|
"k8s.io/utils/trace"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -32,9 +32,10 @@ import (
|
|||||||
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
|
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
|
||||||
"k8s.io/apimachinery/pkg/runtime"
|
"k8s.io/apimachinery/pkg/runtime"
|
||||||
"k8s.io/apimachinery/pkg/runtime/schema"
|
"k8s.io/apimachinery/pkg/runtime/schema"
|
||||||
"k8s.io/apimachinery/pkg/util/clock"
|
|
||||||
"k8s.io/apimachinery/pkg/util/wait"
|
"k8s.io/apimachinery/pkg/util/wait"
|
||||||
"k8s.io/apimachinery/pkg/watch"
|
"k8s.io/apimachinery/pkg/watch"
|
||||||
|
"k8s.io/utils/clock"
|
||||||
|
testingclock "k8s.io/utils/clock/testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
var nevererrc chan error
|
var nevererrc chan error
|
||||||
@ -376,7 +377,7 @@ func TestReflectorListAndWatchInitConnBackoff(t *testing.T) {
|
|||||||
func(t *testing.T) {
|
func(t *testing.T) {
|
||||||
stopCh := make(chan struct{})
|
stopCh := make(chan struct{})
|
||||||
connFails := test.numConnFails
|
connFails := test.numConnFails
|
||||||
fakeClock := clock.NewFakeClock(time.Unix(0, 0))
|
fakeClock := testingclock.NewFakeClock(time.Unix(0, 0))
|
||||||
bm := wait.NewExponentialBackoffManager(time.Millisecond, maxBackoff, 100*time.Millisecond, 2.0, 1.0, fakeClock)
|
bm := wait.NewExponentialBackoffManager(time.Millisecond, maxBackoff, 100*time.Millisecond, 2.0, 1.0, fakeClock)
|
||||||
done := make(chan struct{})
|
done := make(chan struct{})
|
||||||
defer close(done)
|
defer close(done)
|
||||||
|
@ -23,10 +23,10 @@ import (
|
|||||||
|
|
||||||
"k8s.io/apimachinery/pkg/api/meta"
|
"k8s.io/apimachinery/pkg/api/meta"
|
||||||
"k8s.io/apimachinery/pkg/runtime"
|
"k8s.io/apimachinery/pkg/runtime"
|
||||||
"k8s.io/apimachinery/pkg/util/clock"
|
|
||||||
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
|
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
|
||||||
"k8s.io/apimachinery/pkg/util/wait"
|
"k8s.io/apimachinery/pkg/util/wait"
|
||||||
"k8s.io/utils/buffer"
|
"k8s.io/utils/buffer"
|
||||||
|
"k8s.io/utils/clock"
|
||||||
|
|
||||||
"k8s.io/klog/v2"
|
"k8s.io/klog/v2"
|
||||||
)
|
)
|
||||||
|
@ -26,10 +26,10 @@ import (
|
|||||||
"k8s.io/api/core/v1"
|
"k8s.io/api/core/v1"
|
||||||
"k8s.io/apimachinery/pkg/api/meta"
|
"k8s.io/apimachinery/pkg/api/meta"
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
"k8s.io/apimachinery/pkg/util/clock"
|
|
||||||
"k8s.io/apimachinery/pkg/util/sets"
|
"k8s.io/apimachinery/pkg/util/sets"
|
||||||
"k8s.io/apimachinery/pkg/util/wait"
|
"k8s.io/apimachinery/pkg/util/wait"
|
||||||
fcache "k8s.io/client-go/tools/cache/testing"
|
fcache "k8s.io/client-go/tools/cache/testing"
|
||||||
|
testingclock "k8s.io/utils/clock/testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
type testListener struct {
|
type testListener struct {
|
||||||
@ -105,7 +105,7 @@ func TestListenerResyncPeriods(t *testing.T) {
|
|||||||
// create the shared informer and resync every 1s
|
// create the shared informer and resync every 1s
|
||||||
informer := NewSharedInformer(source, &v1.Pod{}, 1*time.Second).(*sharedIndexInformer)
|
informer := NewSharedInformer(source, &v1.Pod{}, 1*time.Second).(*sharedIndexInformer)
|
||||||
|
|
||||||
clock := clock.NewFakeClock(time.Now())
|
clock := testingclock.NewFakeClock(time.Now())
|
||||||
informer.clock = clock
|
informer.clock = clock
|
||||||
informer.processor.clock = clock
|
informer.processor.clock = clock
|
||||||
|
|
||||||
@ -190,7 +190,7 @@ func TestResyncCheckPeriod(t *testing.T) {
|
|||||||
// create the shared informer and resync every 12 hours
|
// create the shared informer and resync every 12 hours
|
||||||
informer := NewSharedInformer(source, &v1.Pod{}, 12*time.Hour).(*sharedIndexInformer)
|
informer := NewSharedInformer(source, &v1.Pod{}, 12*time.Hour).(*sharedIndexInformer)
|
||||||
|
|
||||||
clock := clock.NewFakeClock(time.Now())
|
clock := testingclock.NewFakeClock(time.Now())
|
||||||
informer.clock = clock
|
informer.clock = clock
|
||||||
informer.processor.clock = clock
|
informer.processor.clock = clock
|
||||||
|
|
||||||
@ -278,7 +278,7 @@ func TestSharedInformerWatchDisruption(t *testing.T) {
|
|||||||
// create the shared informer and resync every 1s
|
// create the shared informer and resync every 1s
|
||||||
informer := NewSharedInformer(source, &v1.Pod{}, 1*time.Second).(*sharedIndexInformer)
|
informer := NewSharedInformer(source, &v1.Pod{}, 1*time.Second).(*sharedIndexInformer)
|
||||||
|
|
||||||
clock := clock.NewFakeClock(time.Now())
|
clock := testingclock.NewFakeClock(time.Now())
|
||||||
informer.clock = clock
|
informer.clock = clock
|
||||||
informer.processor.clock = clock
|
informer.processor.clock = clock
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user