Skip to content

Commit

Permalink
Remove owner check
Browse files Browse the repository at this point in the history
Signed-off-by: JenTing Hsiao <[email protected]>
  • Loading branch information
JenTing Hsiao committed May 19, 2020
1 parent 8d3b583 commit edd466d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 40 deletions.
20 changes: 5 additions & 15 deletions pkg/cert/node/certificate.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,14 @@ import (
"github.com/jenting/kucero/pkg/host"
)

type OWNER string

const (
kubeadm OWNER = "kubeadm"
)

type Certificate interface {
// CheckExpiration checks node certificate
// returns the certificates which are going to expires
CheckExpiration() (map[OWNER][]string, error)
CheckExpiration() ([]string, error)

// Rotate rotates the node certificates
// which are going to expires
Rotate(expiryCertificates map[OWNER][]string) error
Rotate(expiryCertificates []string) error
}

// checkCertificateExpiry checks if the time `t` is less than the time duration `expiryTimeToRotate`
Expand Down Expand Up @@ -64,15 +58,11 @@ func backupCertificate(nodeName string, certificateName, certificatePath string)

// rotateCertificate calls `kubeadm alpha certs renew <cert-name>`
// on the host system to rotates kubeadm issued certificates
func rotateCertificate(nodeName string, owner OWNER, certificateName, certificatePath string) error {
logrus.Infof("Commanding rotate %s node owner %s certificate %s path %s", nodeName, string(owner), certificateName, certificatePath)
func rotateCertificate(nodeName string, certificateName, certificatePath string) error {
logrus.Infof("Commanding rotate %s node certificate %s path %s", nodeName, certificateName, certificatePath)

var err error
switch owner {
case kubeadm:
err = kubeadmRenewCerts(certificateName, certificatePath)
}

err = kubeadmRenewCerts(certificateName, certificatePath)
if err != nil {
logrus.Errorf("Error invoking command: %v", err)
}
Expand Down
40 changes: 15 additions & 25 deletions pkg/cert/node/master.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,40 +33,30 @@ func NewMaster(nodeName string, expiryTimeToRotate time.Duration) Certificate {

// CheckExpiration checks master node certificate
// returns the certificates which are going to expires
func (m *Master) CheckExpiration() (map[OWNER][]string, error) {
expiryCertificates := map[OWNER][]string{}

func (m *Master) CheckExpiration() ([]string, error) {
logrus.Infof("Commanding check %s node certificate expiration", m.nodeName)

kubeadmExpiryCertificates, err := kubeadmCheckExpiration(m.expiryTimeToRotate, m.clock)
if err != nil {
return expiryCertificates, err
}
expiryCertificates[kubeadm] = kubeadmExpiryCertificates

return expiryCertificates, nil
return kubeadmCheckExpiration(m.expiryTimeToRotate, m.clock)
}

// Rotate executes the steps to rotates the certificate
// including backing up certificate, rotates certificate, and restart kubelet
func (m *Master) Rotate(expiryCertificates map[OWNER][]string) error {
func (m *Master) Rotate(expiryCertificates []string) error {
var errs error
for owner, certificates := range expiryCertificates {
for _, certificateName := range certificates {
certificatePath, ok := m.certificates[certificateName]
if !ok {
continue
}
for _, certificateName := range expiryCertificates {
certificatePath, ok := m.certificates[certificateName]
if !ok {
continue
}

if err := backupCertificate(m.nodeName, certificateName, certificatePath); err != nil {
errs = fmt.Errorf("%w; ", err)
continue
}
if err := backupCertificate(m.nodeName, certificateName, certificatePath); err != nil {
errs = fmt.Errorf("%w; ", err)
continue
}

if err := rotateCertificate(m.nodeName, owner, certificateName, certificatePath); err != nil {
errs = fmt.Errorf("%w; ", err)
continue
}
if err := rotateCertificate(m.nodeName, certificateName, certificatePath); err != nil {
errs = fmt.Errorf("%w; ", err)
continue
}
}
if errs != nil {
Expand Down

0 comments on commit edd466d

Please sign in to comment.