From eb3a4b84cdb45042ea4f4a299f179a55f6292149 Mon Sep 17 00:00:00 2001 From: Hidde Beydals Date: Mon, 11 Sep 2023 13:42:04 +0200 Subject: [PATCH 1/2] runner: address regression in captured Helm logs This addresses a regression in the Helm log capturing introduced in 3b25041385934e6ba7fc8e2eabf9ea17cd9d9474, which prevented valuable information from the Kube client logs (e.g. the specific reason for a timeout) to be added to the event emitted in case of a failure. Signed-off-by: Hidde Beydals --- internal/runner/runner.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/internal/runner/runner.go b/internal/runner/runner.go index be0bd355a..0488054f1 100644 --- a/internal/runner/runner.go +++ b/internal/runner/runner.go @@ -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 } From 1aa739028d4fc07dbfe3054547c3280fe568d18f Mon Sep 17 00:00:00 2001 From: Hidde Beydals Date: Mon, 11 Sep 2023 13:47:24 +0200 Subject: [PATCH 2/2] controller: strip newlines from Helm error message To prevent spurious newlines between the error message and the captured logs, as at times Helm ends error with one or multiple newlines. Signed-off-by: Hidde Beydals --- internal/controller/helmrelease_controller.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/controller/helmrelease_controller.go b/internal/controller/helmrelease_controller.go index afd58a6a2..fa96e5cac 100644 --- a/internal/controller/helmrelease_controller.go +++ b/internal/controller/helmrelease_controller.go @@ -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,