Skip to content

Commit f45529d

Browse files
vadmesteAnis Elleuch
and
Anis Elleuch
authored
autocert: Renew when 80% of the time until expiration is elapsed (#1332)
Currently, the auto generated MinIO certificate is auto renewed before 48 hours of the expiration date. Since the operator does not set an expiry date, some certicates are short lived, therefore the operator will try to renew the certificate all the time. The solution is to renew only when 80% of the time until the certificate expiration date has elapsed. Co-authored-by: Anis Elleuch <[email protected]>
1 parent 0299cc8 commit f45529d

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

pkg/controller/cluster/minio.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ func (c *Controller) checkMinIOCertificatesStatus(ctx context.Context, tenant *m
293293
}
294294

295295
// certNeedsRenewal - returns true if the TLS certificate from given secret has expired or is
296-
// about to expire within the next two days.
296+
// about to expire shortly.
297297
func (c *Controller) certNeedsRenewal(tlsSecret *corev1.Secret) (bool, error) {
298298
var certPublicKey []byte
299299
var certPrivateKey []byte
@@ -330,7 +330,10 @@ func (c *Controller) certNeedsRenewal(tlsSecret *corev1.Secret) (bool, error) {
330330
}
331331
}
332332

333-
if leaf.NotAfter.Before(time.Now().Add(time.Hour * 48)) {
333+
// Renew the certificate when 80% of the time between the creation and expiration date
334+
// has elapsed so this can work with short lived certifcates as well.
335+
timeElapsedBeforeRenewal := time.Duration(float64(leaf.NotAfter.Sub(leaf.NotBefore)) * 0.8)
336+
if leaf.NotBefore.Add(timeElapsedBeforeRenewal).Before(time.Now()) {
334337
klog.V(2).Infof("TLS Certificate expiry on %s", leaf.NotAfter.String())
335338
return true, nil
336339
}

0 commit comments

Comments
 (0)