Skip to content

Commit 5c9f4d9

Browse files
committed
replace time.Now().Sub with time.Since
1 parent 66674f5 commit 5c9f4d9

File tree

14 files changed

+20
-20
lines changed

14 files changed

+20
-20
lines changed

cmd/kubeadm/app/phases/upgrade/postupgrade.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ func shouldBackupAPIServerCertAndKey(certAndKeyDir string) (bool, error) {
278278
return false, errors.New("no certificate data found")
279279
}
280280

281-
if time.Now().Sub(certs[0].NotBefore) > expiry {
281+
if time.Since(certs[0].NotBefore) > expiry {
282282
return true, nil
283283
}
284284

pkg/cloudprovider/providers/gce/gce_tpu.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ func (g *Cloud) waitForTPUOp(ctx context.Context, op *tpuapi.Operation) (*tpuapi
158158

159159
start := time.Now()
160160
g.operationPollRateLimiter.Accept()
161-
duration := time.Now().Sub(start)
161+
duration := time.Since(start)
162162
if duration > 5*time.Second {
163163
klog.V(2).Infof("Getting operation %q throttled for %v", op.Name, duration)
164164
}

pkg/controller/route/route_controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ func (rc *RouteController) reconcile(nodes []*v1.Node, routes []*cloudprovider.R
192192
klog.V(4).Infof(msg)
193193
return err
194194
}
195-
klog.Infof("Created route for node %s %s with hint %s after %v", nodeName, route.DestinationCIDR, nameHint, time.Now().Sub(startTime))
195+
klog.Infof("Created route for node %s %s with hint %s after %v", nodeName, route.DestinationCIDR, nameHint, time.Since(startTime))
196196
return nil
197197
})
198198
if err != nil {

pkg/kubelet/kuberuntime/kuberuntime_manager.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -854,7 +854,7 @@ func (m *kubeGenericRuntimeManager) cleanupErrorTimeouts() {
854854
m.errorMapLock.Lock()
855855
defer m.errorMapLock.Unlock()
856856
for name, timeout := range m.errorPrinted {
857-
if time.Now().Sub(timeout) >= identicalErrorDelay {
857+
if time.Since(timeout) >= identicalErrorDelay {
858858
delete(m.errorPrinted, name)
859859
delete(m.lastError, name)
860860
}
@@ -913,7 +913,7 @@ func (m *kubeGenericRuntimeManager) GetPodStatus(uid kubetypes.UID, name, namesp
913913
defer m.errorMapLock.Unlock()
914914
if err != nil {
915915
lastMsg, ok := m.lastError[podFullName]
916-
if !ok || err.Error() != lastMsg || time.Now().Sub(m.errorPrinted[podFullName]) >= identicalErrorDelay {
916+
if !ok || err.Error() != lastMsg || time.Since(m.errorPrinted[podFullName]) >= identicalErrorDelay {
917917
klog.Errorf("getPodContainerStatuses for pod %q failed: %v", podFullName, err)
918918
m.errorPrinted[podFullName] = time.Now()
919919
m.lastError[podFullName] = err.Error()

pkg/kubelet/remote/remote_runtime.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ func (r *RemoteRuntimeService) cleanupErrorTimeouts() {
296296
r.errorMapLock.Lock()
297297
defer r.errorMapLock.Unlock()
298298
for ID, timeout := range r.errorPrinted {
299-
if time.Now().Sub(timeout) >= identicalErrorDelay {
299+
if time.Since(timeout) >= identicalErrorDelay {
300300
delete(r.lastError, ID)
301301
delete(r.errorPrinted, ID)
302302
}
@@ -317,7 +317,7 @@ func (r *RemoteRuntimeService) ContainerStatus(containerID string) (*runtimeapi.
317317
if err != nil {
318318
// Don't spam the log with endless messages about the same failure.
319319
lastMsg, ok := r.lastError[containerID]
320-
if !ok || err.Error() != lastMsg || time.Now().Sub(r.errorPrinted[containerID]) >= identicalErrorDelay {
320+
if !ok || err.Error() != lastMsg || time.Since(r.errorPrinted[containerID]) >= identicalErrorDelay {
321321
klog.Errorf("ContainerStatus %q from runtime service failed: %v", containerID, err)
322322
r.errorPrinted[containerID] = time.Now()
323323
r.lastError[containerID] = err.Error()
@@ -505,7 +505,7 @@ func (r *RemoteRuntimeService) ContainerStats(containerID string) (*runtimeapi.C
505505
defer r.errorMapLock.Unlock()
506506
if err != nil {
507507
lastMsg, ok := r.lastError[containerID]
508-
if !ok || err.Error() != lastMsg || time.Now().Sub(r.errorPrinted[containerID]) >= identicalErrorDelay {
508+
if !ok || err.Error() != lastMsg || time.Since(r.errorPrinted[containerID]) >= identicalErrorDelay {
509509
klog.Errorf("ContainerStatus %q from runtime service failed: %v", containerID, err)
510510
r.errorPrinted[containerID] = time.Now()
511511
r.lastError[containerID] = err.Error()

pkg/printers/internalversion/printers.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -845,7 +845,7 @@ func printJob(obj *batch.Job, options printers.PrintOptions) ([]metav1beta1.Tabl
845845
switch {
846846
case obj.Status.StartTime == nil:
847847
case obj.Status.CompletionTime == nil:
848-
jobDuration = duration.HumanDuration(time.Now().Sub(obj.Status.StartTime.Time))
848+
jobDuration = duration.HumanDuration(time.Since(obj.Status.StartTime.Time))
849849
default:
850850
jobDuration = duration.HumanDuration(obj.Status.CompletionTime.Sub(obj.Status.StartTime.Time))
851851
}

plugin/pkg/auth/authorizer/node/node_authorizer_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -828,7 +828,7 @@ func BenchmarkAuthorization(b *testing.B) {
828828
},
829829
},
830830
})
831-
diff := time.Now().Sub(start)
831+
diff := time.Since(start)
832832
atomic.AddInt64(&writes, 1)
833833
switch {
834834
case diff < time.Millisecond:

staging/src/k8s.io/apimachinery/pkg/api/meta/table/table.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,5 +67,5 @@ func ConvertToHumanReadableDateType(timestamp metav1.Time) string {
6767
if timestamp.IsZero() {
6868
return "<unknown>"
6969
}
70-
return duration.HumanDuration(time.Now().Sub(timestamp.Time))
70+
return duration.HumanDuration(time.Since(timestamp.Time))
7171
}

staging/src/k8s.io/apimachinery/pkg/util/clock/clock_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ func TestFakeClock(t *testing.T) {
4444

4545
tt := tc.Now()
4646
tc.SetTime(tt.Add(time.Hour))
47-
if tc.Now().Sub(tt) != time.Hour {
48-
t.Errorf("input: %s now=%s gap=%s expected=%s", tt, tc.Now(), tc.Now().Sub(tt), time.Hour)
47+
if tc.Since(tt) != time.Hour {
48+
t.Errorf("input: %s now=%s gap=%s expected=%s", tt, tc.Now(), tc.Since(tt), time.Hour)
4949
}
5050
}
5151

staging/src/k8s.io/apimachinery/pkg/util/wait/wait_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -531,7 +531,7 @@ func TestWaitForWithEarlyClosingWaitFunc(t *testing.T) {
531531
}, func() (bool, error) {
532532
return false, nil
533533
}, stopCh)
534-
duration := time.Now().Sub(start)
534+
duration := time.Since(start)
535535

536536
// The WaitFor should return immediately, so the duration is close to 0s.
537537
if duration >= ForeverTestTimeout/2 {
@@ -555,7 +555,7 @@ func TestWaitForWithClosedChannel(t *testing.T) {
555555
}, func() (bool, error) {
556556
return false, nil
557557
}, stopCh)
558-
duration := time.Now().Sub(start)
558+
duration := time.Since(start)
559559
// The WaitFor should return immediately, so the duration is close to 0s.
560560
if duration >= ForeverTestTimeout/2 {
561561
t.Errorf("expected short timeout duration")

0 commit comments

Comments
 (0)