diff --git a/cmd/kubeadm/app/phases/upgrade/postupgrade.go b/cmd/kubeadm/app/phases/upgrade/postupgrade.go index cfc62bc751..ca1e51ad59 100644 --- a/cmd/kubeadm/app/phases/upgrade/postupgrade.go +++ b/cmd/kubeadm/app/phases/upgrade/postupgrade.go @@ -276,7 +276,7 @@ func shouldBackupAPIServerCertAndKey(certAndKeyDir string) (bool, error) { return false, errors.New("no certificate data found") } - if time.Now().Sub(certs[0].NotBefore) > expiry { + if time.Since(certs[0].NotBefore) > expiry { return true, nil } diff --git a/pkg/cloudprovider/providers/gce/gce_tpu.go b/pkg/cloudprovider/providers/gce/gce_tpu.go index b9fae1da2f..ff4217eb18 100644 --- a/pkg/cloudprovider/providers/gce/gce_tpu.go +++ b/pkg/cloudprovider/providers/gce/gce_tpu.go @@ -158,7 +158,7 @@ func (g *Cloud) waitForTPUOp(ctx context.Context, op *tpuapi.Operation) (*tpuapi start := time.Now() g.operationPollRateLimiter.Accept() - duration := time.Now().Sub(start) + duration := time.Since(start) if duration > 5*time.Second { klog.V(2).Infof("Getting operation %q throttled for %v", op.Name, duration) } diff --git a/pkg/controller/route/route_controller.go b/pkg/controller/route/route_controller.go index 27719b178e..b5dd1ca978 100644 --- a/pkg/controller/route/route_controller.go +++ b/pkg/controller/route/route_controller.go @@ -192,7 +192,7 @@ func (rc *RouteController) reconcile(nodes []*v1.Node, routes []*cloudprovider.R klog.V(4).Infof(msg) return err } - klog.Infof("Created route for node %s %s with hint %s after %v", nodeName, route.DestinationCIDR, nameHint, time.Now().Sub(startTime)) + klog.Infof("Created route for node %s %s with hint %s after %v", nodeName, route.DestinationCIDR, nameHint, time.Since(startTime)) return nil }) if err != nil { diff --git a/pkg/kubelet/kuberuntime/kuberuntime_manager.go b/pkg/kubelet/kuberuntime/kuberuntime_manager.go index b6313fb8bd..336f5d294c 100644 --- a/pkg/kubelet/kuberuntime/kuberuntime_manager.go +++ b/pkg/kubelet/kuberuntime/kuberuntime_manager.go @@ -854,7 +854,7 @@ func (m *kubeGenericRuntimeManager) cleanupErrorTimeouts() { m.errorMapLock.Lock() defer m.errorMapLock.Unlock() for name, timeout := range m.errorPrinted { - if time.Now().Sub(timeout) >= identicalErrorDelay { + if time.Since(timeout) >= identicalErrorDelay { delete(m.errorPrinted, name) delete(m.lastError, name) } @@ -913,7 +913,7 @@ func (m *kubeGenericRuntimeManager) GetPodStatus(uid kubetypes.UID, name, namesp defer m.errorMapLock.Unlock() if err != nil { lastMsg, ok := m.lastError[podFullName] - if !ok || err.Error() != lastMsg || time.Now().Sub(m.errorPrinted[podFullName]) >= identicalErrorDelay { + if !ok || err.Error() != lastMsg || time.Since(m.errorPrinted[podFullName]) >= identicalErrorDelay { klog.Errorf("getPodContainerStatuses for pod %q failed: %v", podFullName, err) m.errorPrinted[podFullName] = time.Now() m.lastError[podFullName] = err.Error() diff --git a/pkg/kubelet/remote/remote_runtime.go b/pkg/kubelet/remote/remote_runtime.go index 88b9bce953..0ed4157cad 100644 --- a/pkg/kubelet/remote/remote_runtime.go +++ b/pkg/kubelet/remote/remote_runtime.go @@ -296,7 +296,7 @@ func (r *RemoteRuntimeService) cleanupErrorTimeouts() { r.errorMapLock.Lock() defer r.errorMapLock.Unlock() for ID, timeout := range r.errorPrinted { - if time.Now().Sub(timeout) >= identicalErrorDelay { + if time.Since(timeout) >= identicalErrorDelay { delete(r.lastError, ID) delete(r.errorPrinted, ID) } @@ -317,7 +317,7 @@ func (r *RemoteRuntimeService) ContainerStatus(containerID string) (*runtimeapi. if err != nil { // Don't spam the log with endless messages about the same failure. lastMsg, ok := r.lastError[containerID] - if !ok || err.Error() != lastMsg || time.Now().Sub(r.errorPrinted[containerID]) >= identicalErrorDelay { + if !ok || err.Error() != lastMsg || time.Since(r.errorPrinted[containerID]) >= identicalErrorDelay { klog.Errorf("ContainerStatus %q from runtime service failed: %v", containerID, err) r.errorPrinted[containerID] = time.Now() r.lastError[containerID] = err.Error() @@ -505,7 +505,7 @@ func (r *RemoteRuntimeService) ContainerStats(containerID string) (*runtimeapi.C defer r.errorMapLock.Unlock() if err != nil { lastMsg, ok := r.lastError[containerID] - if !ok || err.Error() != lastMsg || time.Now().Sub(r.errorPrinted[containerID]) >= identicalErrorDelay { + if !ok || err.Error() != lastMsg || time.Since(r.errorPrinted[containerID]) >= identicalErrorDelay { klog.Errorf("ContainerStatus %q from runtime service failed: %v", containerID, err) r.errorPrinted[containerID] = time.Now() r.lastError[containerID] = err.Error() diff --git a/pkg/printers/internalversion/printers.go b/pkg/printers/internalversion/printers.go index 782a569a3a..322836b275 100644 --- a/pkg/printers/internalversion/printers.go +++ b/pkg/printers/internalversion/printers.go @@ -856,7 +856,7 @@ func printJob(obj *batch.Job, options printers.PrintOptions) ([]metav1beta1.Tabl switch { case obj.Status.StartTime == nil: case obj.Status.CompletionTime == nil: - jobDuration = duration.HumanDuration(time.Now().Sub(obj.Status.StartTime.Time)) + jobDuration = duration.HumanDuration(time.Since(obj.Status.StartTime.Time)) default: jobDuration = duration.HumanDuration(obj.Status.CompletionTime.Sub(obj.Status.StartTime.Time)) } diff --git a/plugin/pkg/auth/authorizer/node/node_authorizer_test.go b/plugin/pkg/auth/authorizer/node/node_authorizer_test.go index afe1bdaf02..45a8aa4a45 100644 --- a/plugin/pkg/auth/authorizer/node/node_authorizer_test.go +++ b/plugin/pkg/auth/authorizer/node/node_authorizer_test.go @@ -828,7 +828,7 @@ func BenchmarkAuthorization(b *testing.B) { }, }, }) - diff := time.Now().Sub(start) + diff := time.Since(start) atomic.AddInt64(&writes, 1) switch { case diff < time.Millisecond: diff --git a/staging/src/k8s.io/apimachinery/pkg/api/meta/table/table.go b/staging/src/k8s.io/apimachinery/pkg/api/meta/table/table.go index 798cc41bdd..11c4afacb0 100644 --- a/staging/src/k8s.io/apimachinery/pkg/api/meta/table/table.go +++ b/staging/src/k8s.io/apimachinery/pkg/api/meta/table/table.go @@ -67,5 +67,5 @@ func ConvertToHumanReadableDateType(timestamp metav1.Time) string { if timestamp.IsZero() { return "" } - return duration.HumanDuration(time.Now().Sub(timestamp.Time)) + return duration.HumanDuration(time.Since(timestamp.Time)) } diff --git a/staging/src/k8s.io/apimachinery/pkg/util/clock/clock_test.go b/staging/src/k8s.io/apimachinery/pkg/util/clock/clock_test.go index c7b371fc6d..495c2c3c86 100644 --- a/staging/src/k8s.io/apimachinery/pkg/util/clock/clock_test.go +++ b/staging/src/k8s.io/apimachinery/pkg/util/clock/clock_test.go @@ -44,8 +44,8 @@ func TestFakeClock(t *testing.T) { tt := tc.Now() tc.SetTime(tt.Add(time.Hour)) - if tc.Now().Sub(tt) != time.Hour { - t.Errorf("input: %s now=%s gap=%s expected=%s", tt, tc.Now(), tc.Now().Sub(tt), time.Hour) + if tc.Since(tt) != time.Hour { + t.Errorf("input: %s now=%s gap=%s expected=%s", tt, tc.Now(), tc.Since(tt), time.Hour) } } diff --git a/staging/src/k8s.io/apimachinery/pkg/util/wait/wait_test.go b/staging/src/k8s.io/apimachinery/pkg/util/wait/wait_test.go index 975abebd78..8cad6eaf93 100644 --- a/staging/src/k8s.io/apimachinery/pkg/util/wait/wait_test.go +++ b/staging/src/k8s.io/apimachinery/pkg/util/wait/wait_test.go @@ -531,7 +531,7 @@ func TestWaitForWithEarlyClosingWaitFunc(t *testing.T) { }, func() (bool, error) { return false, nil }, stopCh) - duration := time.Now().Sub(start) + duration := time.Since(start) // The WaitFor should return immediately, so the duration is close to 0s. if duration >= ForeverTestTimeout/2 { @@ -555,7 +555,7 @@ func TestWaitForWithClosedChannel(t *testing.T) { }, func() (bool, error) { return false, nil }, stopCh) - duration := time.Now().Sub(start) + duration := time.Since(start) // The WaitFor should return immediately, so the duration is close to 0s. if duration >= ForeverTestTimeout/2 { t.Errorf("expected short timeout duration") diff --git a/staging/src/k8s.io/client-go/tools/cache/reflector.go b/staging/src/k8s.io/client-go/tools/cache/reflector.go index c43b7fc52d..a629fd4e8d 100644 --- a/staging/src/k8s.io/client-go/tools/cache/reflector.go +++ b/staging/src/k8s.io/client-go/tools/cache/reflector.go @@ -363,7 +363,7 @@ loop: } } - watchDuration := r.clock.Now().Sub(start) + watchDuration := r.clock.Since(start) if watchDuration < 1*time.Second && eventCount == 0 { return fmt.Errorf("very short watch: %s: Unexpected watch close - watch lasted less than a second and no items received", r.name) } diff --git a/staging/src/k8s.io/client-go/util/flowcontrol/backoff.go b/staging/src/k8s.io/client-go/util/flowcontrol/backoff.go index b7cb70ea74..39cd72f953 100644 --- a/staging/src/k8s.io/client-go/util/flowcontrol/backoff.go +++ b/staging/src/k8s.io/client-go/util/flowcontrol/backoff.go @@ -99,7 +99,7 @@ func (p *Backoff) IsInBackOffSince(id string, eventTime time.Time) bool { if hasExpired(eventTime, entry.lastUpdate, p.maxDuration) { return false } - return p.Clock.Now().Sub(eventTime) < entry.backoff + return p.Clock.Since(eventTime) < entry.backoff } // Returns True if time since lastupdate is less than the current backoff window. diff --git a/staging/src/k8s.io/client-go/util/flowcontrol/backoff_test.go b/staging/src/k8s.io/client-go/util/flowcontrol/backoff_test.go index b14ab341b0..4d061d54a4 100644 --- a/staging/src/k8s.io/client-go/util/flowcontrol/backoff_test.go +++ b/staging/src/k8s.io/client-go/util/flowcontrol/backoff_test.go @@ -114,14 +114,14 @@ func TestBackoffGC(t *testing.T) { b.GC() _, found := b.perItemBackoff[id] if !found { - t.Errorf("expected GC to skip entry, elapsed time=%s maxDuration=%s", tc.Now().Sub(lastUpdate), maxDuration) + t.Errorf("expected GC to skip entry, elapsed time=%s maxDuration=%s", tc.Since(lastUpdate), maxDuration) } tc.Step(maxDuration + step) b.GC() r, found := b.perItemBackoff[id] if found { - t.Errorf("expected GC of entry after %s got entry %v", tc.Now().Sub(lastUpdate), r) + t.Errorf("expected GC of entry after %s got entry %v", tc.Since(lastUpdate), r) } } diff --git a/test/integration/kubelet/watch_manager_test.go b/test/integration/kubelet/watch_manager_test.go index c1354a1515..226b1baeb1 100644 --- a/test/integration/kubelet/watch_manager_test.go +++ b/test/integration/kubelet/watch_manager_test.go @@ -96,7 +96,7 @@ func TestWatchBasedManager(t *testing.T) { if err != nil { t.Fatalf("failed on %s: %v", name, err) } - if d := time.Now().Sub(start); d > time.Second { + if d := time.Since(start); d > time.Second { t.Logf("%s took %v", name, d) } }