diff --git a/staging/src/k8s.io/apiserver/pkg/admission/plugin/namespace/lifecycle/admission.go b/staging/src/k8s.io/apiserver/pkg/admission/plugin/namespace/lifecycle/admission.go index c417e3f98ae..936a95e45cc 100644 --- a/staging/src/k8s.io/apiserver/pkg/admission/plugin/namespace/lifecycle/admission.go +++ b/staging/src/k8s.io/apiserver/pkg/admission/plugin/namespace/lifecycle/admission.go @@ -29,13 +29,13 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime/schema" utilcache "k8s.io/apimachinery/pkg/util/cache" - "k8s.io/apimachinery/pkg/util/clock" "k8s.io/apimachinery/pkg/util/sets" "k8s.io/apiserver/pkg/admission" "k8s.io/apiserver/pkg/admission/initializer" "k8s.io/client-go/informers" "k8s.io/client-go/kubernetes" corelisters "k8s.io/client-go/listers/core/v1" + "k8s.io/utils/clock" ) const ( diff --git a/staging/src/k8s.io/apiserver/pkg/admission/plugin/namespace/lifecycle/admission_test.go b/staging/src/k8s.io/apiserver/pkg/admission/plugin/namespace/lifecycle/admission_test.go index 71b1edf6d8b..e0131538db1 100644 --- a/staging/src/k8s.io/apiserver/pkg/admission/plugin/namespace/lifecycle/admission_test.go +++ b/staging/src/k8s.io/apiserver/pkg/admission/plugin/namespace/lifecycle/admission_test.go @@ -28,7 +28,6 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime/schema" - "k8s.io/apimachinery/pkg/util/clock" "k8s.io/apimachinery/pkg/util/diff" "k8s.io/apimachinery/pkg/util/sets" "k8s.io/apimachinery/pkg/util/wait" @@ -38,6 +37,8 @@ import ( clientset "k8s.io/client-go/kubernetes" "k8s.io/client-go/kubernetes/fake" core "k8s.io/client-go/testing" + "k8s.io/utils/clock" + testingclock "k8s.io/utils/clock/testing" ) // newHandlerForTest returns a configured handler for testing. @@ -240,7 +241,7 @@ func TestAdmissionNamespaceForceLiveLookup(t *testing.T) { return true, &v1.Namespace{ObjectMeta: metav1.ObjectMeta{Name: namespace}, Status: v1.NamespaceStatus{Phase: phases[namespace]}}, nil }) - fakeClock := clock.NewFakeClock(time.Now()) + fakeClock := testingclock.NewFakeClock(time.Now()) handler, informerFactory, err := newHandlerForTestWithClock(mockClient, fakeClock) if err != nil { diff --git a/staging/src/k8s.io/apiserver/pkg/authentication/token/cache/cache_simple.go b/staging/src/k8s.io/apiserver/pkg/authentication/token/cache/cache_simple.go index 8e0520af169..a2c5ce680b1 100644 --- a/staging/src/k8s.io/apiserver/pkg/authentication/token/cache/cache_simple.go +++ b/staging/src/k8s.io/apiserver/pkg/authentication/token/cache/cache_simple.go @@ -20,7 +20,7 @@ import ( "time" utilcache "k8s.io/apimachinery/pkg/util/cache" - "k8s.io/apimachinery/pkg/util/clock" + "k8s.io/utils/clock" ) type simpleCache struct { diff --git a/staging/src/k8s.io/apiserver/pkg/authentication/token/cache/cache_test.go b/staging/src/k8s.io/apiserver/pkg/authentication/token/cache/cache_test.go index bd0457ac6ca..774d659749d 100644 --- a/staging/src/k8s.io/apiserver/pkg/authentication/token/cache/cache_test.go +++ b/staging/src/k8s.io/apiserver/pkg/authentication/token/cache/cache_test.go @@ -24,9 +24,9 @@ import ( "github.com/google/uuid" - "k8s.io/apimachinery/pkg/util/clock" "k8s.io/apiserver/pkg/authentication/authenticator" "k8s.io/apiserver/pkg/authentication/user" + "k8s.io/utils/clock" ) func TestSimpleCache(t *testing.T) { diff --git a/staging/src/k8s.io/apiserver/pkg/authentication/token/cache/cached_token_authenticator.go b/staging/src/k8s.io/apiserver/pkg/authentication/token/cache/cached_token_authenticator.go index b0d06a23183..afd990f7184 100644 --- a/staging/src/k8s.io/apiserver/pkg/authentication/token/cache/cached_token_authenticator.go +++ b/staging/src/k8s.io/apiserver/pkg/authentication/token/cache/cached_token_authenticator.go @@ -33,12 +33,12 @@ import ( "golang.org/x/sync/singleflight" apierrors "k8s.io/apimachinery/pkg/api/errors" - utilclock "k8s.io/apimachinery/pkg/util/clock" auditinternal "k8s.io/apiserver/pkg/apis/audit" "k8s.io/apiserver/pkg/audit" "k8s.io/apiserver/pkg/authentication/authenticator" "k8s.io/apiserver/pkg/endpoints/request" "k8s.io/klog/v2" + "k8s.io/utils/clock" ) var errAuthnCrash = apierrors.NewInternalError(errors.New("authentication failed unexpectedly")) @@ -89,10 +89,10 @@ type cache interface { // New returns a token authenticator that caches the results of the specified authenticator. A ttl of 0 bypasses the cache. func New(authenticator authenticator.Token, cacheErrs bool, successTTL, failureTTL time.Duration) authenticator.Token { - return newWithClock(authenticator, cacheErrs, successTTL, failureTTL, utilclock.RealClock{}) + return newWithClock(authenticator, cacheErrs, successTTL, failureTTL, clock.RealClock{}) } -func newWithClock(authenticator authenticator.Token, cacheErrs bool, successTTL, failureTTL time.Duration, clock utilclock.Clock) authenticator.Token { +func newWithClock(authenticator authenticator.Token, cacheErrs bool, successTTL, failureTTL time.Duration, clock clock.Clock) authenticator.Token { randomCacheKey := make([]byte, 32) if _, err := rand.Read(randomCacheKey); err != nil { panic(err) // rand should never fail diff --git a/staging/src/k8s.io/apiserver/pkg/authentication/token/cache/cached_token_authenticator_test.go b/staging/src/k8s.io/apiserver/pkg/authentication/token/cache/cached_token_authenticator_test.go index ed3abfc1d1f..80ef78ec9d1 100644 --- a/staging/src/k8s.io/apiserver/pkg/authentication/token/cache/cached_token_authenticator_test.go +++ b/staging/src/k8s.io/apiserver/pkg/authentication/token/cache/cached_token_authenticator_test.go @@ -31,13 +31,14 @@ import ( "time" "github.com/google/go-cmp/cmp" - utilclock "k8s.io/apimachinery/pkg/util/clock" "k8s.io/apimachinery/pkg/util/uuid" auditinternal "k8s.io/apiserver/pkg/apis/audit" "k8s.io/apiserver/pkg/audit" "k8s.io/apiserver/pkg/authentication/authenticator" "k8s.io/apiserver/pkg/authentication/user" "k8s.io/apiserver/pkg/endpoints/request" + "k8s.io/utils/clock" + testingclock "k8s.io/utils/clock/testing" ) func TestCachedTokenAuthenticator(t *testing.T) { @@ -52,7 +53,7 @@ func TestCachedTokenAuthenticator(t *testing.T) { calledWithToken = append(calledWithToken, token) return &authenticator.Response{User: resultUsers[token]}, resultOk, resultErr }) - fakeClock := utilclock.NewFakeClock(time.Now()) + fakeClock := testingclock.NewFakeClock(time.Now()) a := newWithClock(fakeAuth, true, time.Minute, 0, fakeClock) @@ -126,7 +127,7 @@ func TestCachedTokenAuthenticatorWithAudiences(t *testing.T) { auds, _ := authenticator.AudiencesFrom(ctx) return &authenticator.Response{User: resultUsers[auds[0]+token]}, true, nil }) - fakeClock := utilclock.NewFakeClock(time.Now()) + fakeClock := testingclock.NewFakeClock(time.Now()) a := newWithClock(fakeAuth, true, time.Minute, 0, fakeClock) @@ -546,7 +547,7 @@ func (s *singleBenchmark) bench(b *testing.B) { true, 4*time.Second, 500*time.Millisecond, - utilclock.RealClock{}, + clock.RealClock{}, ) b.ResetTimer() diff --git a/staging/src/k8s.io/apiserver/pkg/endpoints/filterlatency/filterlatency.go b/staging/src/k8s.io/apiserver/pkg/endpoints/filterlatency/filterlatency.go index 672bb7ad398..40e32a1a190 100644 --- a/staging/src/k8s.io/apiserver/pkg/endpoints/filterlatency/filterlatency.go +++ b/staging/src/k8s.io/apiserver/pkg/endpoints/filterlatency/filterlatency.go @@ -22,11 +22,11 @@ import ( "net/http" "time" - utilclock "k8s.io/apimachinery/pkg/util/clock" "k8s.io/apiserver/pkg/endpoints/metrics" apirequest "k8s.io/apiserver/pkg/endpoints/request" "k8s.io/apiserver/pkg/server/httplog" "k8s.io/klog/v2" + "k8s.io/utils/clock" ) type requestFilterRecordKeyType int @@ -55,13 +55,13 @@ func requestFilterRecordFrom(ctx context.Context) *requestFilterRecord { // TrackStarted measures the timestamp the given handler has started execution // by attaching a handler to the chain. func TrackStarted(handler http.Handler, name string) http.Handler { - return trackStarted(handler, name, utilclock.RealClock{}) + return trackStarted(handler, name, clock.RealClock{}) } // TrackCompleted measures the timestamp the given handler has completed execution and then // it updates the corresponding metric with the filter latency duration. func TrackCompleted(handler http.Handler) http.Handler { - return trackCompleted(handler, utilclock.RealClock{}, func(ctx context.Context, fr *requestFilterRecord, completedAt time.Time) { + return trackCompleted(handler, clock.RealClock{}, func(ctx context.Context, fr *requestFilterRecord, completedAt time.Time) { latency := completedAt.Sub(fr.startedTimestamp) metrics.RecordFilterLatency(ctx, fr.name, latency) if klog.V(3).Enabled() && latency > minFilterLatencyToLog { @@ -70,7 +70,7 @@ func TrackCompleted(handler http.Handler) http.Handler { }) } -func trackStarted(handler http.Handler, name string, clock utilclock.PassiveClock) http.Handler { +func trackStarted(handler http.Handler, name string, clock clock.PassiveClock) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { ctx := r.Context() if fr := requestFilterRecordFrom(ctx); fr != nil { @@ -90,7 +90,7 @@ func trackStarted(handler http.Handler, name string, clock utilclock.PassiveCloc }) } -func trackCompleted(handler http.Handler, clock utilclock.PassiveClock, action func(context.Context, *requestFilterRecord, time.Time)) http.Handler { +func trackCompleted(handler http.Handler, clock clock.PassiveClock, action func(context.Context, *requestFilterRecord, time.Time)) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { // The previous filter has just completed. completedAt := clock.Now() diff --git a/staging/src/k8s.io/apiserver/pkg/endpoints/filterlatency/filterlatency_test.go b/staging/src/k8s.io/apiserver/pkg/endpoints/filterlatency/filterlatency_test.go index f12e9456489..db900145aa1 100644 --- a/staging/src/k8s.io/apiserver/pkg/endpoints/filterlatency/filterlatency_test.go +++ b/staging/src/k8s.io/apiserver/pkg/endpoints/filterlatency/filterlatency_test.go @@ -23,7 +23,7 @@ import ( "testing" "time" - utilclock "k8s.io/apimachinery/pkg/util/clock" + testingclock "k8s.io/utils/clock/testing" ) func TestTrackStartedWithContextAlreadyHasFilterRecord(t *testing.T) { @@ -41,7 +41,7 @@ func TestTrackStartedWithContextAlreadyHasFilterRecord(t *testing.T) { }) requestFilterStarted := time.Now() - wrapped := trackStarted(handler, filterName, utilclock.NewFakeClock(requestFilterStarted)) + wrapped := trackStarted(handler, filterName, testingclock.NewFakeClock(requestFilterStarted)) testRequest, err := http.NewRequest(http.MethodGet, "/api/v1/namespaces", nil) if err != nil { @@ -84,7 +84,7 @@ func TestTrackStartedWithContextDoesNotHaveFilterRecord(t *testing.T) { }) requestFilterStarted := time.Now() - wrapped := trackStarted(handler, filterName, utilclock.NewFakeClock(requestFilterStarted)) + wrapped := trackStarted(handler, filterName, testingclock.NewFakeClock(requestFilterStarted)) testRequest, err := http.NewRequest(http.MethodGet, "/api/v1/namespaces", nil) if err != nil { @@ -121,7 +121,7 @@ func TestTrackCompletedContextHasFilterRecord(t *testing.T) { }) requestFilterEndedAt := time.Now() - wrapped := trackCompleted(handler, utilclock.NewFakeClock(requestFilterEndedAt), func(_ context.Context, fr *requestFilterRecord, completedAt time.Time) { + wrapped := trackCompleted(handler, testingclock.NewFakeClock(requestFilterEndedAt), func(_ context.Context, fr *requestFilterRecord, completedAt time.Time) { actionCallCount++ filterRecordGot = fr filterCompletedAtGot = completedAt @@ -157,7 +157,7 @@ func TestTrackCompletedContextDoesNotHaveFilterRecord(t *testing.T) { handlerCallCount++ }) - wrapped := trackCompleted(handler, utilclock.NewFakeClock(time.Now()), func(_ context.Context, _ *requestFilterRecord, _ time.Time) { + wrapped := trackCompleted(handler, testingclock.NewFakeClock(time.Now()), func(_ context.Context, _ *requestFilterRecord, _ time.Time) { actionCallCount++ }) diff --git a/staging/src/k8s.io/apiserver/pkg/endpoints/filters/request_deadline.go b/staging/src/k8s.io/apiserver/pkg/endpoints/filters/request_deadline.go index 1df8e5b5514..132ffab1cf6 100644 --- a/staging/src/k8s.io/apiserver/pkg/endpoints/filters/request_deadline.go +++ b/staging/src/k8s.io/apiserver/pkg/endpoints/filters/request_deadline.go @@ -27,13 +27,13 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime/schema" - utilclock "k8s.io/apimachinery/pkg/util/clock" utilruntime "k8s.io/apimachinery/pkg/util/runtime" auditinternal "k8s.io/apiserver/pkg/apis/audit" "k8s.io/apiserver/pkg/audit" "k8s.io/apiserver/pkg/endpoints/handlers/responsewriters" "k8s.io/apiserver/pkg/endpoints/request" "k8s.io/klog/v2" + "k8s.io/utils/clock" ) const ( @@ -48,11 +48,11 @@ const ( // requestTimeoutMaximum specifies the default request timeout value. func WithRequestDeadline(handler http.Handler, sink audit.Sink, policy audit.PolicyRuleEvaluator, longRunning request.LongRunningRequestCheck, negotiatedSerializer runtime.NegotiatedSerializer, requestTimeoutMaximum time.Duration) http.Handler { - return withRequestDeadline(handler, sink, policy, longRunning, negotiatedSerializer, requestTimeoutMaximum, utilclock.RealClock{}) + return withRequestDeadline(handler, sink, policy, longRunning, negotiatedSerializer, requestTimeoutMaximum, clock.RealClock{}) } func withRequestDeadline(handler http.Handler, sink audit.Sink, policy audit.PolicyRuleEvaluator, longRunning request.LongRunningRequestCheck, - negotiatedSerializer runtime.NegotiatedSerializer, requestTimeoutMaximum time.Duration, clock utilclock.PassiveClock) http.Handler { + negotiatedSerializer runtime.NegotiatedSerializer, requestTimeoutMaximum time.Duration, clock clock.PassiveClock) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) { ctx := req.Context() diff --git a/staging/src/k8s.io/apiserver/pkg/endpoints/filters/request_deadline_test.go b/staging/src/k8s.io/apiserver/pkg/endpoints/filters/request_deadline_test.go index 856e443e506..384c78092a5 100644 --- a/staging/src/k8s.io/apiserver/pkg/endpoints/filters/request_deadline_test.go +++ b/staging/src/k8s.io/apiserver/pkg/endpoints/filters/request_deadline_test.go @@ -32,10 +32,10 @@ import ( apierrors "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime/serializer" - utilclock "k8s.io/apimachinery/pkg/util/clock" auditinternal "k8s.io/apiserver/pkg/apis/audit" "k8s.io/apiserver/pkg/audit/policy" "k8s.io/apiserver/pkg/endpoints/request" + testingclock "k8s.io/utils/clock/testing" ) func TestParseTimeout(t *testing.T) { @@ -227,7 +227,7 @@ func TestWithRequestDeadlineWithClock(t *testing.T) { // if the deadline filter uses the clock instead of using the request started timestamp from the context // then we will see a request deadline of about a minute. receivedTimestampExpected := time.Now().Add(time.Minute) - fakeClock := utilclock.NewFakeClock(receivedTimestampExpected) + fakeClock := testingclock.NewFakeClock(receivedTimestampExpected) fakeSink := &fakeAuditSink{} fakeRuleEvaluator := policy.NewFakePolicyRuleEvaluator(auditinternal.LevelRequestResponse, nil) diff --git a/staging/src/k8s.io/apiserver/pkg/endpoints/filters/request_received_time.go b/staging/src/k8s.io/apiserver/pkg/endpoints/filters/request_received_time.go index d9e7369f671..576bb3e7a26 100644 --- a/staging/src/k8s.io/apiserver/pkg/endpoints/filters/request_received_time.go +++ b/staging/src/k8s.io/apiserver/pkg/endpoints/filters/request_received_time.go @@ -19,18 +19,18 @@ package filters import ( "net/http" - utilclock "k8s.io/apimachinery/pkg/util/clock" "k8s.io/apiserver/pkg/endpoints/request" + "k8s.io/utils/clock" ) // WithRequestReceivedTimestamp attaches the ReceivedTimestamp (the time the request reached // the apiserver) to the context. func WithRequestReceivedTimestamp(handler http.Handler) http.Handler { - return withRequestReceivedTimestampWithClock(handler, utilclock.RealClock{}) + return withRequestReceivedTimestampWithClock(handler, clock.RealClock{}) } // The clock is passed as a parameter, handy for unit testing. -func withRequestReceivedTimestampWithClock(handler http.Handler, clock utilclock.PassiveClock) http.Handler { +func withRequestReceivedTimestampWithClock(handler http.Handler, clock clock.PassiveClock) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) { ctx := req.Context() req = req.WithContext(request.WithReceivedTimestamp(ctx, clock.Now())) diff --git a/staging/src/k8s.io/apiserver/pkg/endpoints/filters/request_received_time_test.go b/staging/src/k8s.io/apiserver/pkg/endpoints/filters/request_received_time_test.go index f09bad40952..ec4ee68e053 100644 --- a/staging/src/k8s.io/apiserver/pkg/endpoints/filters/request_received_time_test.go +++ b/staging/src/k8s.io/apiserver/pkg/endpoints/filters/request_received_time_test.go @@ -22,8 +22,8 @@ import ( "testing" "time" - utilclock "k8s.io/apimachinery/pkg/util/clock" "k8s.io/apiserver/pkg/endpoints/request" + testingclock "k8s.io/utils/clock/testing" ) func TestWithRequestReceivedTimestamp(t *testing.T) { @@ -41,7 +41,7 @@ func TestWithRequestReceivedTimestamp(t *testing.T) { receivedTimestampGot, ok = request.ReceivedTimestampFrom(req.Context()) }) - wrapped := withRequestReceivedTimestampWithClock(handler, utilclock.NewFakeClock(receivedTimestampExpected)) + wrapped := withRequestReceivedTimestampWithClock(handler, testingclock.NewFakeClock(receivedTimestampExpected)) testRequest, err := http.NewRequest(http.MethodGet, "/api/v1/namespaces", nil) if err != nil { diff --git a/staging/src/k8s.io/apiserver/pkg/server/config.go b/staging/src/k8s.io/apiserver/pkg/server/config.go index f99d0ca1c51..524c8c0f5ae 100644 --- a/staging/src/k8s.io/apiserver/pkg/server/config.go +++ b/staging/src/k8s.io/apiserver/pkg/server/config.go @@ -35,7 +35,6 @@ import ( "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime/schema" "k8s.io/apimachinery/pkg/runtime/serializer" - "k8s.io/apimachinery/pkg/util/clock" "k8s.io/apimachinery/pkg/util/sets" utilwaitgroup "k8s.io/apimachinery/pkg/util/waitgroup" "k8s.io/apimachinery/pkg/version" @@ -73,6 +72,7 @@ import ( "k8s.io/klog/v2" openapicommon "k8s.io/kube-openapi/pkg/common" "k8s.io/kube-openapi/pkg/validation/spec" + "k8s.io/utils/clock" utilsnet "k8s.io/utils/net" // install apis diff --git a/staging/src/k8s.io/apiserver/pkg/server/egressselector/egress_selector_test.go b/staging/src/k8s.io/apiserver/pkg/server/egressselector/egress_selector_test.go index 815c54a0db3..4e9a56306a1 100644 --- a/staging/src/k8s.io/apiserver/pkg/server/egressselector/egress_selector_test.go +++ b/staging/src/k8s.io/apiserver/pkg/server/egressselector/egress_selector_test.go @@ -25,12 +25,12 @@ import ( "time" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/util/clock" utilnet "k8s.io/apimachinery/pkg/util/net" "k8s.io/apiserver/pkg/apis/apiserver" "k8s.io/apiserver/pkg/server/egressselector/metrics" "k8s.io/component-base/metrics/legacyregistry" "k8s.io/component-base/metrics/testutil" + testingclock "k8s.io/utils/clock/testing" ) type fakeEgressSelection struct { @@ -244,7 +244,7 @@ func TestMetrics(t *testing.T) { t.Run(tn, func(t *testing.T) { metrics.Metrics.Reset() - metrics.Metrics.SetClock(clock.NewFakeClock(time.Now())) + metrics.Metrics.SetClock(testingclock.NewFakeClock(time.Now())) d := dialerCreator{ connector: &fakeProxyServerConnector{ connectorErr: tc.connectorErr, diff --git a/staging/src/k8s.io/apiserver/pkg/server/egressselector/metrics/metrics.go b/staging/src/k8s.io/apiserver/pkg/server/egressselector/metrics/metrics.go index 04ad61c4fd0..af384618181 100644 --- a/staging/src/k8s.io/apiserver/pkg/server/egressselector/metrics/metrics.go +++ b/staging/src/k8s.io/apiserver/pkg/server/egressselector/metrics/metrics.go @@ -19,9 +19,9 @@ package metrics import ( "time" - "k8s.io/apimachinery/pkg/util/clock" "k8s.io/component-base/metrics" "k8s.io/component-base/metrics/legacyregistry" + "k8s.io/utils/clock" ) const ( diff --git a/staging/src/k8s.io/apiserver/pkg/server/genericapiserver.go b/staging/src/k8s.io/apiserver/pkg/server/genericapiserver.go index 8104cd2f05e..f3c17b626f3 100644 --- a/staging/src/k8s.io/apiserver/pkg/server/genericapiserver.go +++ b/staging/src/k8s.io/apiserver/pkg/server/genericapiserver.go @@ -31,7 +31,6 @@ import ( "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime/schema" "k8s.io/apimachinery/pkg/runtime/serializer" - "k8s.io/apimachinery/pkg/util/clock" "k8s.io/apimachinery/pkg/util/sets" utilwaitgroup "k8s.io/apimachinery/pkg/util/waitgroup" "k8s.io/apimachinery/pkg/version" @@ -56,6 +55,7 @@ import ( openapiutil "k8s.io/kube-openapi/pkg/util" openapiproto "k8s.io/kube-openapi/pkg/util/proto" "k8s.io/kube-openapi/pkg/validation/spec" + "k8s.io/utils/clock" ) // Info about an API group. diff --git a/staging/src/k8s.io/apiserver/pkg/server/healthz.go b/staging/src/k8s.io/apiserver/pkg/server/healthz.go index 61da5873ce2..d6d13444d70 100644 --- a/staging/src/k8s.io/apiserver/pkg/server/healthz.go +++ b/staging/src/k8s.io/apiserver/pkg/server/healthz.go @@ -21,8 +21,8 @@ import ( "net/http" "time" - "k8s.io/apimachinery/pkg/util/clock" "k8s.io/apiserver/pkg/server/healthz" + "k8s.io/utils/clock" ) // AddHealthChecks adds HealthCheck(s) to health endpoints (healthz, livez, readyz) but diff --git a/staging/src/k8s.io/apiserver/pkg/server/healthz_test.go b/staging/src/k8s.io/apiserver/pkg/server/healthz_test.go index eb4ce2abd31..a8f7025e835 100644 --- a/staging/src/k8s.io/apiserver/pkg/server/healthz_test.go +++ b/staging/src/k8s.io/apiserver/pkg/server/healthz_test.go @@ -20,13 +20,13 @@ import ( "testing" "time" - "k8s.io/apimachinery/pkg/util/clock" + testingclock "k8s.io/utils/clock/testing" ) func TestDelayedHealthCheck(t *testing.T) { t.Run("test that liveness check returns true until the delay has elapsed", func(t *testing.T) { t0 := time.Unix(0, 0) - c := clock.NewFakeClock(t0) + c := testingclock.NewFakeClock(t0) doneCh := make(chan struct{}) healthCheck := delayedHealthCheck(postStartHookHealthz{"test", doneCh}, c, time.Duration(10)*time.Second) @@ -52,7 +52,7 @@ func TestDelayedHealthCheck(t *testing.T) { }) t.Run("test that liveness check does not toggle false even if done channel is closed early", func(t *testing.T) { t0 := time.Unix(0, 0) - c := clock.NewFakeClock(t0) + c := testingclock.NewFakeClock(t0) doneCh := make(chan struct{}) diff --git a/staging/src/k8s.io/apiserver/pkg/storage/cacher/cacher.go b/staging/src/k8s.io/apiserver/pkg/storage/cacher/cacher.go index c4f9865c284..2053c818066 100644 --- a/staging/src/k8s.io/apiserver/pkg/storage/cacher/cacher.go +++ b/staging/src/k8s.io/apiserver/pkg/storage/cacher/cacher.go @@ -31,7 +31,6 @@ import ( "k8s.io/apimachinery/pkg/fields" "k8s.io/apimachinery/pkg/labels" "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/apimachinery/pkg/watch" @@ -41,6 +40,7 @@ import ( utilflowcontrol "k8s.io/apiserver/pkg/util/flowcontrol" "k8s.io/client-go/tools/cache" "k8s.io/klog/v2" + "k8s.io/utils/clock" utiltrace "k8s.io/utils/trace" ) diff --git a/staging/src/k8s.io/apiserver/pkg/storage/cacher/cacher_whitebox_test.go b/staging/src/k8s.io/apiserver/pkg/storage/cacher/cacher_whitebox_test.go index 74df2010318..7290ad80ab0 100644 --- a/staging/src/k8s.io/apiserver/pkg/storage/cacher/cacher_whitebox_test.go +++ b/staging/src/k8s.io/apiserver/pkg/storage/cacher/cacher_whitebox_test.go @@ -35,7 +35,6 @@ import ( "k8s.io/apimachinery/pkg/labels" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime/serializer" - "k8s.io/apimachinery/pkg/util/clock" "k8s.io/apimachinery/pkg/util/diff" utilruntime "k8s.io/apimachinery/pkg/util/runtime" "k8s.io/apimachinery/pkg/util/wait" @@ -44,6 +43,8 @@ import ( examplev1 "k8s.io/apiserver/pkg/apis/example/v1" "k8s.io/apiserver/pkg/storage" utilflowcontrol "k8s.io/apiserver/pkg/util/flowcontrol" + "k8s.io/utils/clock" + testingclock "k8s.io/utils/clock/testing" ) var ( @@ -603,7 +604,7 @@ func TestTimeBucketWatchersBasic(t *testing.T) { return newCacheWatcher(0, filter, forget, testVersioner{}, deadline, true, objectType, "") } - clock := clock.NewFakeClock(time.Now()) + clock := testingclock.NewFakeClock(time.Now()) watchers := newTimeBucketWatchers(clock, defaultBookmarkFrequency) now := clock.Now() watchers.addWatcher(newWatcher(now.Add(10 * time.Second))) diff --git a/staging/src/k8s.io/apiserver/pkg/storage/cacher/time_budget.go b/staging/src/k8s.io/apiserver/pkg/storage/cacher/time_budget.go index 2e14a782359..da77bd42b02 100644 --- a/staging/src/k8s.io/apiserver/pkg/storage/cacher/time_budget.go +++ b/staging/src/k8s.io/apiserver/pkg/storage/cacher/time_budget.go @@ -20,7 +20,7 @@ import ( "sync" "time" - "k8s.io/apimachinery/pkg/util/clock" + "k8s.io/utils/clock" ) const ( diff --git a/staging/src/k8s.io/apiserver/pkg/storage/cacher/time_budget_test.go b/staging/src/k8s.io/apiserver/pkg/storage/cacher/time_budget_test.go index 5bd7f44a58b..c35f34efe33 100644 --- a/staging/src/k8s.io/apiserver/pkg/storage/cacher/time_budget_test.go +++ b/staging/src/k8s.io/apiserver/pkg/storage/cacher/time_budget_test.go @@ -20,11 +20,11 @@ import ( "testing" "time" - "k8s.io/apimachinery/pkg/util/clock" + testingclock "k8s.io/utils/clock/testing" ) func TestTimeBudget(t *testing.T) { - fakeClock := clock.NewFakeClock(time.Now()) + fakeClock := testingclock.NewFakeClock(time.Now()) budget := &timeBudgetImpl{ clock: fakeClock, diff --git a/staging/src/k8s.io/apiserver/pkg/storage/cacher/watch_cache.go b/staging/src/k8s.io/apiserver/pkg/storage/cacher/watch_cache.go index b3c925e180c..65f002e6fdd 100644 --- a/staging/src/k8s.io/apiserver/pkg/storage/cacher/watch_cache.go +++ b/staging/src/k8s.io/apiserver/pkg/storage/cacher/watch_cache.go @@ -27,11 +27,11 @@ import ( "k8s.io/apimachinery/pkg/fields" "k8s.io/apimachinery/pkg/labels" "k8s.io/apimachinery/pkg/runtime" - "k8s.io/apimachinery/pkg/util/clock" "k8s.io/apimachinery/pkg/watch" "k8s.io/apiserver/pkg/storage" "k8s.io/client-go/tools/cache" "k8s.io/klog/v2" + "k8s.io/utils/clock" utiltrace "k8s.io/utils/trace" ) diff --git a/staging/src/k8s.io/apiserver/pkg/storage/cacher/watch_cache_test.go b/staging/src/k8s.io/apiserver/pkg/storage/cacher/watch_cache_test.go index acf34de1f17..4812650b762 100644 --- a/staging/src/k8s.io/apiserver/pkg/storage/cacher/watch_cache_test.go +++ b/staging/src/k8s.io/apiserver/pkg/storage/cacher/watch_cache_test.go @@ -31,13 +31,13 @@ import ( "k8s.io/apimachinery/pkg/fields" "k8s.io/apimachinery/pkg/labels" "k8s.io/apimachinery/pkg/runtime" - "k8s.io/apimachinery/pkg/util/clock" "k8s.io/apimachinery/pkg/util/wait" "k8s.io/apimachinery/pkg/watch" "k8s.io/apiserver/pkg/apis/example" "k8s.io/apiserver/pkg/storage" "k8s.io/apiserver/pkg/storage/etcd3" "k8s.io/client-go/tools/cache" + testingclock "k8s.io/utils/clock/testing" ) func makeTestPod(name string, resourceVersion uint64) *v1.Pod { @@ -81,7 +81,7 @@ func newTestWatchCache(capacity int, indexers *cache.Indexers) *watchCache { } versioner := etcd3.APIObjectVersioner{} mockHandler := func(*watchCacheEvent) {} - wc := newWatchCache(keyFunc, mockHandler, getAttrsFunc, versioner, indexers, clock.NewFakeClock(time.Now()), reflect.TypeOf(&example.Pod{})) + wc := newWatchCache(keyFunc, mockHandler, getAttrsFunc, versioner, indexers, testingclock.NewFakeClock(time.Now()), reflect.TypeOf(&example.Pod{})) // To preserve behavior of tests that assume a given capacity, // resize it to th expected size. wc.capacity = capacity @@ -443,7 +443,7 @@ func TestWaitUntilFreshAndGet(t *testing.T) { func TestWaitUntilFreshAndListTimeout(t *testing.T) { store := newTestWatchCache(3, &cache.Indexers{}) - fc := store.clock.(*clock.FakeClock) + fc := store.clock.(*testingclock.FakeClock) // In background, step clock after the below call starts the timer. go func() { diff --git a/staging/src/k8s.io/apiserver/pkg/storage/tests/cacher_test.go b/staging/src/k8s.io/apiserver/pkg/storage/tests/cacher_test.go index 32f03d7626f..9381b17ea4e 100644 --- a/staging/src/k8s.io/apiserver/pkg/storage/tests/cacher_test.go +++ b/staging/src/k8s.io/apiserver/pkg/storage/tests/cacher_test.go @@ -36,7 +36,6 @@ import ( "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime/schema" "k8s.io/apimachinery/pkg/runtime/serializer" - "k8s.io/apimachinery/pkg/util/clock" utilruntime "k8s.io/apimachinery/pkg/util/runtime" "k8s.io/apimachinery/pkg/util/sets" "k8s.io/apimachinery/pkg/util/wait" @@ -52,6 +51,8 @@ import ( "k8s.io/apiserver/pkg/storage/value" utilfeature "k8s.io/apiserver/pkg/util/feature" featuregatetesting "k8s.io/component-base/featuregate/testing" + "k8s.io/utils/clock" + testingclock "k8s.io/utils/clock/testing" ) var ( @@ -409,7 +410,7 @@ func TestWatch(t *testing.T) { // Inject one list error to make sure we test the relist case. etcdStorage = &injectListError{errors: 1, Interface: etcdStorage} defer server.Terminate(t) - fakeClock := clock.NewFakeClock(time.Now()) + fakeClock := testingclock.NewFakeClock(time.Now()) cacher, _, err := newTestCacherWithClock(etcdStorage, fakeClock) if err != nil { t.Fatalf("Couldn't create cacher: %v", err)