Skip to content

Add logs for kubeadm#125

Merged
bcho merged 1 commit intomainfrom
add-kubeadm-logs
Mar 13, 2026
Merged

Add logs for kubeadm#125
bcho merged 1 commit intomainfrom
add-kubeadm-logs

Conversation

@anson627
Copy link
Collaborator

This pull request improves error reporting for kubeadm join and kubeadm reset operations by including the command output in error messages. This will help with debugging by providing more context when these commands fail.

Enhanced error reporting for kubeadm commands:

  • Updated the runJoin method in join.go to use CombinedOutput() and include the output of the kubeadm join command in error messages.
  • Updated the runReset method in reset.go to use CombinedOutput() and include the output of the kubeadm reset command in error messages.

Copilot AI review requested due to automatic review settings March 12, 2026 19:42
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Improves error reporting for kubeadm operations in the v20260301 kubeadm action implementations by capturing and surfacing command output when kubeadm join / kubeadm reset fail.

Changes:

  • Switch kubeadm join execution to CombinedOutput() and append stdout/stderr to the returned error.
  • Switch kubeadm reset execution to CombinedOutput() and append stdout/stderr to the returned error.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.

File Description
components/kubeadm/v20260301/join.go Captures kubeadm join output and includes it in failure errors.
components/kubeadm/v20260301/reset.go Captures kubeadm reset output and includes it in failure errors.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Comment on lines +270 to +271
if output, err := utilexec.New().CommandContext(ctx, kubeadmCommand, "join", "--config", joinConfig, "-v", "5").CombinedOutput(); err != nil {
return status.Errorf(codes.Internal, "kubeadm join: %s\n%s", err, string(output))
Copy link

Copilot AI Mar 12, 2026

Choose a reason for hiding this comment

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

CombinedOutput() buffers all kubeadm stdout/stderr in memory and then embeds it verbatim into the gRPC status message. This makes the returned error unbounded in size (potentially causing high memory usage and/or exceeding gRPC message/log size limits). Consider truncating the captured output (e.g., last N KB/lines) and/or logging full output separately, and only including a bounded summary in the returned error message.

Copilot uses AI. Check for mistakes.
if err := utilexec.New().CommandContext(ctx, kubeadmCommand, "join", "--config", joinConfig, "-v", "5").Run(); err != nil {
return status.Errorf(codes.Internal, "kubeadm join: %s", err)
if output, err := utilexec.New().CommandContext(ctx, kubeadmCommand, "join", "--config", joinConfig, "-v", "5").CombinedOutput(); err != nil {
return status.Errorf(codes.Internal, "kubeadm join: %s\n%s", err, string(output))
Copy link

Copilot AI Mar 12, 2026

Choose a reason for hiding this comment

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

The error formatting always adds a newline and string(output), even when the command produced no output. This can result in noisy/odd error strings (trailing blank line). Consider conditionally appending the output only when it is non-empty (and trimming whitespace) so the error message stays clean.

Suggested change
return status.Errorf(codes.Internal, "kubeadm join: %s\n%s", err, string(output))
trimmedOutput := strings.TrimSpace(string(output))
if trimmedOutput != "" {
return status.Errorf(codes.Internal, "kubeadm join: %s\n%s", err, trimmedOutput)
}
return status.Errorf(codes.Internal, "kubeadm join: %s", err)

Copilot uses AI. Check for mistakes.
Comment on lines +78 to +81
if output, err := utilexec.New().CommandContext(
ctx, kubeadmBinary, "reset", "--force", "-v", "5",
).Run(); err != nil {
return status.Errorf(codes.Internal, "kubeadm reset: %s", err)
).CombinedOutput(); err != nil {
return status.Errorf(codes.Internal, "kubeadm reset: %s\n%s", err, string(output))
Copy link

Copilot AI Mar 12, 2026

Choose a reason for hiding this comment

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

CombinedOutput() captures the full kubeadm output into memory and then returns it in the gRPC error. Since kubeadm can be quite verbose (especially with -v 5), this can cause large allocations and very large error payloads/log lines. Consider bounding/truncating the output and/or emitting the full output to logs instead of returning it verbatim.

Copilot uses AI. Check for mistakes.
Comment on lines +80 to +81
).CombinedOutput(); err != nil {
return status.Errorf(codes.Internal, "kubeadm reset: %s\n%s", err, string(output))
Copy link

Copilot AI Mar 12, 2026

Choose a reason for hiding this comment

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

The returned error string always includes a newline plus string(output), even if output is empty. Consider only appending trimmed output when it is non-empty to avoid trailing blank lines in the error message.

Copilot uses AI. Check for mistakes.
Copy link
Member

@bcho bcho left a comment

Choose a reason for hiding this comment

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

LGTM -- we have a open item #116 for improving this part, but can take this for now

@bcho bcho merged commit 042419f into main Mar 13, 2026
13 checks passed
@bcho bcho deleted the add-kubeadm-logs branch March 13, 2026 10:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants