Skip to content

Commit

Permalink
add better logging for failures with kubeadm init
Browse files Browse the repository at this point in the history
  • Loading branch information
alexmasi committed May 28, 2024
1 parent 78a83df commit cdda7ad
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions deploy/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -462,9 +462,19 @@ func (k *KubeadmSpec) Deploy(ctx context.Context) error {
if k.TokenTTL != "" {
args = append(args, "--token-ttl", k.TokenTTL)
}
if err := run.LogCommand("sudo", args...); err != nil {
return err
log.Infof("Creating kubeadm cluster with: %v", args)
if out, err := run.OutLogCommand("sudo", args...); err != nil {
msg := []string{}
// Filter output to only show lines relevant to the error message. For kind these are lines
// prefixed with "ERROR" or "Command Output".
for _, line := range strings.Split(string(out), "\n") {
if strings.HasPrefix(line, "ERROR") || strings.HasPrefix(line, "Command Output") {
msg = append(msg, line)
}
}
return fmt.Errorf("%w: %v", err, strings.Join(msg, ", "))
}
log.Infof("Deployed kubeadm cluster")
kubeDir := filepath.Join(homeDir(), ".kube")
if err := os.MkdirAll(kubeDir, 0750); err != nil {
return err
Expand Down

0 comments on commit cdda7ad

Please sign in to comment.