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

runner: address regression in captured Helm logs #767

Merged
merged 2 commits into from
Sep 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion internal/controller/helmrelease_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -715,7 +715,7 @@ func (r *HelmReleaseReconciler) handleHelmActionResult(ctx context.Context,
err = fmt.Errorf("Helm %s failed: %w", action, err)
msg := err.Error()
if actionErr := (*runner.ActionError)(nil); errors.As(err, &actionErr) {
msg = msg + "\n\nLast Helm logs:\n\n" + actionErr.CapturedLogs
msg = strings.TrimSpace(msg) + "\n\nLast Helm logs:\n\n" + actionErr.CapturedLogs
}
newCondition := metav1.Condition{
Type: condition,
Expand Down
11 changes: 10 additions & 1 deletion internal/runner/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,22 @@ func NewRunner(getter genericclioptions.RESTClientGetter, storageNamespace strin
runner := &Runner{
logBuffer: NewLogBuffer(NewDebugLog(logger.V(runtimelogger.DebugLevel)), defaultBufferSize),
}

// Default to the trace level logger for the Helm action configuration,
// to ensure storage logs are captured.
cfg := new(action.Configuration)
if err := cfg.Init(getter, storageNamespace, "secret", NewDebugLog(logger.V(runtimelogger.TraceLevel))); err != nil {
return nil, err
}
// Override the logger used by the Helm actions with the log buffer.

// Override the logger used by the Helm actions and Kube client with the log buffer,
// which provides useful information in the event of an error.
cfg.Log = runner.logBuffer.Log
if kc, ok := cfg.KubeClient.(*kube.Client); ok {
kc.Log = runner.logBuffer.Log
}
runner.config = cfg

return runner, nil
}

Expand Down