From 3b25041385934e6ba7fc8e2eabf9ea17cd9d9474 Mon Sep 17 00:00:00 2001 From: Hidde Beydals Date: Wed, 1 Mar 2023 17:38:55 +0100 Subject: [PATCH] runner: configure Helm action cfg log levels This reduces the amount of log lines pushed to `debug` by configuring the kube client and storage loggers to only log to `trace`. In addition, the log buffer used in events will now just contain the most relevant information about a failure as reported by the Helm action itself, and not the in-depth information from the underlying client and/or storage. Signed-off-by: Hidde Beydals --- internal/runner/log_buffer.go | 2 +- internal/runner/runner.go | 11 ++++++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/internal/runner/log_buffer.go b/internal/runner/log_buffer.go index a3d571299..50d0cb0d6 100644 --- a/internal/runner/log_buffer.go +++ b/internal/runner/log_buffer.go @@ -37,7 +37,7 @@ func NewDebugLog(log logr.Logger) *DebugLog { } func (l *DebugLog) Log(format string, v ...interface{}) { - l.log.V(1).Info(fmt.Sprintf(format, v...)) + l.log.Info(fmt.Sprintf(format, v...)) } type LogBuffer struct { diff --git a/internal/runner/runner.go b/internal/runner/runner.go index 8f9d4057c..d8d12c78f 100644 --- a/internal/runner/runner.go +++ b/internal/runner/runner.go @@ -42,6 +42,8 @@ import ( "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime/schema" + runtimelogger "github.com/fluxcd/pkg/runtime/logger" + v2 "github.com/fluxcd/helm-controller/api/v2beta1" "github.com/fluxcd/helm-controller/internal/features" ) @@ -74,12 +76,15 @@ type Runner struct { // namespace configured to the provided values. func NewRunner(getter genericclioptions.RESTClientGetter, storageNamespace string, logger logr.Logger) (*Runner, error) { runner := &Runner{ - logBuffer: NewLogBuffer(NewDebugLog(logger).Log, defaultBufferSize), + logBuffer: NewLogBuffer(NewDebugLog(logger.V(runtimelogger.DebugLevel)).Log, defaultBufferSize), } - runner.config = new(action.Configuration) - if err := runner.config.Init(getter, storageNamespace, "secret", runner.logBuffer.Log); err != nil { + cfg := new(action.Configuration) + if err := cfg.Init(getter, storageNamespace, "secret", NewDebugLog(logger.V(runtimelogger.TraceLevel)).Log); err != nil { return nil, err } + // Override the logger used by the Helm actions with the log buffer. + cfg.Log = runner.logBuffer.Log + runner.config = cfg return runner, nil }