Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix CSR approving issue for existing nodes with already approved and GCed CSRs #1894

Merged
merged 2 commits into from
Mar 17, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions pkg/tasks/certs.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,7 @@ func saveCABundleOnControlPlane(s *state.State, _ *kubeoneapi.HostConfig, conn s
}

func approvePendingCSR(s *state.State, node *kubeoneapi.HostConfig, conn ssh.Connection) error {
approveErr := errors.Errorf("no CSR found for node %q", node.Hostname)

var csrFound bool
sleepTime := 20 * time.Second
s.Logger.Infof("Waiting %s for CSRs to approve...", sleepTime)
time.Sleep(sleepTime)
Expand Down Expand Up @@ -219,16 +218,16 @@ func approvePendingCSR(s *state.State, node *kubeoneapi.HostConfig, conn ssh.Con
}
}
if approved {
// CSR matched but it's already approved, no need to raise an error
approveErr = nil
// CSR matched but it's already approved
csrFound = true

continue
}

if err := validateCSR(csr.Spec); err != nil {
return fmt.Errorf("failed to validate CSR: %w", err)
}
approveErr = nil
csrFound = true

csr := csr.DeepCopy()
csr.Status.Conditions = append(csr.Status.Conditions, certificatesv1.CertificateSigningRequestCondition{
Expand All @@ -244,7 +243,11 @@ func approvePendingCSR(s *state.State, node *kubeoneapi.HostConfig, conn ssh.Con
}
}

return approveErr
if !csrFound {
s.Logger.Info("no CSR found for node %q, assuming it was garbage-collected", node.Hostname)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: uppercase log messages.

Suggested change
s.Logger.Info("no CSR found for node %q, assuming it was garbage-collected", node.Hostname)
s.Logger.Info("No CSR found for node %q, assuming it was garbage-collected", node.Hostname)

}

return nil
}

func validateCSR(spec certificatesv1.CertificateSigningRequestSpec) error {
Expand Down