Skip to content

Commit

Permalink
runner: configure Helm action cfg log levels
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
hiddeco committed Mar 2, 2023
1 parent 877c4c7 commit 3b25041
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
2 changes: 1 addition & 1 deletion internal/runner/log_buffer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
11 changes: 8 additions & 3 deletions internal/runner/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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
}

Expand Down

0 comments on commit 3b25041

Please sign in to comment.