Fix renewalTime skew issue

Ensure the time returned by RenewalTime function is the same time as that which will be read from Certificate's status

Signed-off-by: irbekrm <irbekrm@gmail.com>
This commit is contained in:
irbekrm 2021-08-20 16:38:29 +01:00
parent 38ab6f4bdd
commit 50e90dfe6e
2 changed files with 2 additions and 2 deletions

View File

@ -307,6 +307,6 @@ func RenewalTime(notBefore, notAfter time.Time, renewBeforeOverride *metav1.Dura
// 2. Calculate when a cert should be renewed
rt := metav1.NewTime(notAfter.Add(-1 * renewBefore))
rt := metav1.NewTime(notAfter.Add(-1 * renewBefore).Truncate(time.Second))
return &rt
}

View File

@ -302,7 +302,7 @@ func TestRenewalTime(t *testing.T) {
renewBeforeOverride *metav1.Duration
expectedRenewalTime *metav1.Time
}
now := time.Now()
now := time.Now().Truncate(time.Second)
tests := map[string]scenario{
"short lived cert, spec.renewBefore is not set": {
notBefore: now,