Skip to content

Commit

Permalink
Merge pull request #767 from fluxcd/fix-captured-logs-regression
Browse files Browse the repository at this point in the history
runner: address regression in captured Helm logs
  • Loading branch information
hiddeco authored Sep 11, 2023
2 parents 394ab5a + 1aa7390 commit c94ee3b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
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

0 comments on commit c94ee3b

Please sign in to comment.