From ca138c86e8aa710876ed4438d43e916147f0b92c Mon Sep 17 00:00:00 2001 From: c00522440 Date: Mon, 12 Apr 2021 10:27:54 +0800 Subject: [PATCH] Change time.Now().Sub(x) to time.Since(x) for cleanup Kubernetes-commit: 878548ceac9c109881c379911b8b0d8fce5ea68e --- plugin/pkg/client/auth/exec/exec.go | 2 +- tools/cache/mutation_detector.go | 2 +- transport/transport.go | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/plugin/pkg/client/auth/exec/exec.go b/plugin/pkg/client/auth/exec/exec.go index b23e57dd..52655c0b 100644 --- a/plugin/pkg/client/auth/exec/exec.go +++ b/plugin/pkg/client/auth/exec/exec.go @@ -461,7 +461,7 @@ func (a *Authenticator) refreshCredsLocked(r *clientauthentication.Response) err if oldCreds != nil && !reflect.DeepEqual(oldCreds.cert, a.cachedCreds.cert) { // Can be nil if the exec auth plugin only returned token auth. if oldCreds.cert != nil && oldCreds.cert.Leaf != nil { - metrics.ClientCertRotationAge.Observe(time.Now().Sub(oldCreds.cert.Leaf.NotBefore)) + metrics.ClientCertRotationAge.Observe(time.Since(oldCreds.cert.Leaf.NotBefore)) } a.connTracker.CloseAll() } diff --git a/tools/cache/mutation_detector.go b/tools/cache/mutation_detector.go index 4611e80f..b37537cb 100644 --- a/tools/cache/mutation_detector.go +++ b/tools/cache/mutation_detector.go @@ -99,7 +99,7 @@ func (d *defaultCacheMutationDetector) Run(stopCh <-chan struct{}) { for { if d.lastRotated.IsZero() { d.lastRotated = time.Now() - } else if time.Now().Sub(d.lastRotated) > d.retainDuration { + } else if time.Since(d.lastRotated) > d.retainDuration { d.retainedCachedObjs = d.cachedObjs d.cachedObjs = nil d.lastRotated = time.Now() diff --git a/transport/transport.go b/transport/transport.go index 88d89494..083364fd 100644 --- a/transport/transport.go +++ b/transport/transport.go @@ -269,7 +269,7 @@ type certificateCacheEntry struct { // isStale returns true when this cache entry is too old to be usable func (c *certificateCacheEntry) isStale() bool { - return time.Now().Sub(c.birth) > time.Second + return time.Since(c.birth) > time.Second } func newCertificateCacheEntry(certFile, keyFile string) certificateCacheEntry {