From 01243dd50efd2d61eaeb251d26b2dd3248527b28 Mon Sep 17 00:00:00 2001 From: wojtekt Date: Fri, 17 Sep 2021 11:36:09 +0200 Subject: [PATCH] Migrate to k8s.io/utils/clock in client-go Kubernetes-commit: bb7dac443a2039f97c822f610e78d4b65482c56d --- tools/cache/controller.go | 2 +- tools/cache/expiration_cache.go | 2 +- tools/cache/expiration_cache_fakes.go | 2 +- tools/cache/expiration_cache_test.go | 5 +++-- tools/cache/reflector.go | 2 +- tools/cache/reflector_test.go | 5 +++-- tools/cache/shared_informer.go | 2 +- tools/cache/shared_informer_test.go | 8 ++++---- 8 files changed, 15 insertions(+), 13 deletions(-) diff --git a/tools/cache/controller.go b/tools/cache/controller.go index fe394d16..3491c011 100644 --- a/tools/cache/controller.go +++ b/tools/cache/controller.go @@ -21,9 +21,9 @@ import ( "time" "k8s.io/apimachinery/pkg/runtime" - "k8s.io/apimachinery/pkg/util/clock" utilruntime "k8s.io/apimachinery/pkg/util/runtime" "k8s.io/apimachinery/pkg/util/wait" + "k8s.io/utils/clock" ) // This file implements a low-level controller that is used in diff --git a/tools/cache/expiration_cache.go b/tools/cache/expiration_cache.go index dfa95619..7abdae73 100644 --- a/tools/cache/expiration_cache.go +++ b/tools/cache/expiration_cache.go @@ -20,8 +20,8 @@ import ( "sync" "time" - "k8s.io/apimachinery/pkg/util/clock" "k8s.io/klog/v2" + "k8s.io/utils/clock" ) // ExpirationCache implements the store interface diff --git a/tools/cache/expiration_cache_fakes.go b/tools/cache/expiration_cache_fakes.go index 33afd32c..a16f4735 100644 --- a/tools/cache/expiration_cache_fakes.go +++ b/tools/cache/expiration_cache_fakes.go @@ -17,8 +17,8 @@ limitations under the License. package cache import ( - "k8s.io/apimachinery/pkg/util/clock" "k8s.io/apimachinery/pkg/util/sets" + "k8s.io/utils/clock" ) type fakeThreadSafeMap struct { diff --git a/tools/cache/expiration_cache_test.go b/tools/cache/expiration_cache_test.go index 160fe6eb..00a9e61c 100644 --- a/tools/cache/expiration_cache_test.go +++ b/tools/cache/expiration_cache_test.go @@ -21,9 +21,10 @@ import ( "testing" "time" - "k8s.io/apimachinery/pkg/util/clock" "k8s.io/apimachinery/pkg/util/sets" "k8s.io/apimachinery/pkg/util/wait" + "k8s.io/utils/clock" + testingclock "k8s.io/utils/clock/testing" ) func TestTTLExpirationBasic(t *testing.T) { @@ -167,7 +168,7 @@ func TestTTLPolicy(t *testing.T) { exactlyOnTTL := fakeTime.Add(-ttl) expiredTime := fakeTime.Add(-(ttl + 1)) - policy := TTLPolicy{ttl, clock.NewFakeClock(fakeTime)} + policy := TTLPolicy{ttl, testingclock.NewFakeClock(fakeTime)} item := testStoreObject{id: "foo", val: "bar"} itemkey, _ := testStoreKeyFunc(item) fakeTimestampedEntry := &TimestampedEntry{Obj: item, Timestamp: exactlyOnTTL, key: itemkey} diff --git a/tools/cache/reflector.go b/tools/cache/reflector.go index 90fa45dd..f7adeeed 100644 --- a/tools/cache/reflector.go +++ b/tools/cache/reflector.go @@ -32,7 +32,6 @@ import ( "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime/schema" - "k8s.io/apimachinery/pkg/util/clock" "k8s.io/apimachinery/pkg/util/naming" utilnet "k8s.io/apimachinery/pkg/util/net" utilruntime "k8s.io/apimachinery/pkg/util/runtime" @@ -40,6 +39,7 @@ import ( "k8s.io/apimachinery/pkg/watch" "k8s.io/client-go/tools/pager" "k8s.io/klog/v2" + "k8s.io/utils/clock" "k8s.io/utils/trace" ) diff --git a/tools/cache/reflector_test.go b/tools/cache/reflector_test.go index fa3b638c..49f76bf0 100644 --- a/tools/cache/reflector_test.go +++ b/tools/cache/reflector_test.go @@ -32,9 +32,10 @@ import ( "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime/schema" - "k8s.io/apimachinery/pkg/util/clock" "k8s.io/apimachinery/pkg/util/wait" "k8s.io/apimachinery/pkg/watch" + "k8s.io/utils/clock" + testingclock "k8s.io/utils/clock/testing" ) var nevererrc chan error @@ -376,7 +377,7 @@ func TestReflectorListAndWatchInitConnBackoff(t *testing.T) { func(t *testing.T) { stopCh := make(chan struct{}) 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) done := make(chan struct{}) defer close(done) diff --git a/tools/cache/shared_informer.go b/tools/cache/shared_informer.go index 1a95dcfe..4b7fc04e 100644 --- a/tools/cache/shared_informer.go +++ b/tools/cache/shared_informer.go @@ -23,10 +23,10 @@ import ( "k8s.io/apimachinery/pkg/api/meta" "k8s.io/apimachinery/pkg/runtime" - "k8s.io/apimachinery/pkg/util/clock" utilruntime "k8s.io/apimachinery/pkg/util/runtime" "k8s.io/apimachinery/pkg/util/wait" "k8s.io/utils/buffer" + "k8s.io/utils/clock" "k8s.io/klog/v2" ) diff --git a/tools/cache/shared_informer_test.go b/tools/cache/shared_informer_test.go index 5882e585..ce129bd3 100644 --- a/tools/cache/shared_informer_test.go +++ b/tools/cache/shared_informer_test.go @@ -26,10 +26,10 @@ import ( "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/meta" 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/wait" fcache "k8s.io/client-go/tools/cache/testing" + testingclock "k8s.io/utils/clock/testing" ) type testListener struct { @@ -105,7 +105,7 @@ func TestListenerResyncPeriods(t *testing.T) { // create the shared informer and resync every 1s informer := NewSharedInformer(source, &v1.Pod{}, 1*time.Second).(*sharedIndexInformer) - clock := clock.NewFakeClock(time.Now()) + clock := testingclock.NewFakeClock(time.Now()) informer.clock = clock informer.processor.clock = clock @@ -190,7 +190,7 @@ func TestResyncCheckPeriod(t *testing.T) { // create the shared informer and resync every 12 hours informer := NewSharedInformer(source, &v1.Pod{}, 12*time.Hour).(*sharedIndexInformer) - clock := clock.NewFakeClock(time.Now()) + clock := testingclock.NewFakeClock(time.Now()) informer.clock = clock informer.processor.clock = clock @@ -278,7 +278,7 @@ func TestSharedInformerWatchDisruption(t *testing.T) { // create the shared informer and resync every 1s informer := NewSharedInformer(source, &v1.Pod{}, 1*time.Second).(*sharedIndexInformer) - clock := clock.NewFakeClock(time.Now()) + clock := testingclock.NewFakeClock(time.Now()) informer.clock = clock informer.processor.clock = clock