...

Source file src/k8s.io/kubernetes/cmd/kubeadm/app/phases/certs/renewal/expiration.go

Documentation: k8s.io/kubernetes/cmd/kubeadm/app/phases/certs/renewal

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

View as plain text