expiration.go 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /*
  2. Copyright 2019 The Kubernetes Authors.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. package renewal
  14. import (
  15. "crypto/x509"
  16. "time"
  17. )
  18. // ExpirationInfo defines expiration info for a certificate
  19. type ExpirationInfo struct {
  20. // Name of the certificate
  21. // For PKI certificates, it is the name defined in the certsphase package, while for certificates
  22. // embedded in the kubeConfig files, it is the kubeConfig file name defined in the kubeadm constants package.
  23. // If you use the CertificateRenewHandler returned by Certificates func, handler.Name already contains the right value.
  24. Name string
  25. // ExpirationDate defines certificate expiration date
  26. ExpirationDate time.Time
  27. // ExternallyManaged defines if the certificate is externally managed, that is when
  28. // the signing CA certificate is provided without the certificate key (In this case kubeadm can't renew the certificate)
  29. ExternallyManaged bool
  30. }
  31. // newExpirationInfo returns a new ExpirationInfo
  32. func newExpirationInfo(name string, cert *x509.Certificate, externallyManaged bool) *ExpirationInfo {
  33. return &ExpirationInfo{
  34. Name: name,
  35. ExpirationDate: cert.NotAfter,
  36. ExternallyManaged: externallyManaged,
  37. }
  38. }
  39. // ResidualTime returns the time missing to expiration
  40. func (e *ExpirationInfo) ResidualTime() time.Duration {
  41. return time.Until(e.ExpirationDate)
  42. }