From 52214ab3f746ba4e849307bbd67a4f9d6179b871 Mon Sep 17 00:00:00 2001 From: Stefan Sedich Date: Wed, 12 Feb 2020 00:14:12 -0800 Subject: [PATCH] helm: add release name to log context for helm internal logs --- pkg/helm/v3/get.go | 2 +- pkg/helm/v3/helm.go | 14 ++++++++------ pkg/helm/v3/history.go | 2 +- pkg/helm/v3/rollback.go | 2 +- pkg/helm/v3/uninstall.go | 2 +- pkg/helm/v3/upgrade.go | 2 +- 6 files changed, 13 insertions(+), 11 deletions(-) diff --git a/pkg/helm/v3/get.go b/pkg/helm/v3/get.go index 092f1a42a..8068e7c76 100644 --- a/pkg/helm/v3/get.go +++ b/pkg/helm/v3/get.go @@ -9,7 +9,7 @@ import ( ) func (h *HelmV3) Get(releaseName string, opts helm.GetOptions) (*helm.Release, error) { - cfg, err := newActionConfig(h.kubeConfig, h.infoLogFunc, opts.Namespace, "") + cfg, err := newActionConfig(h.kubeConfig, h.infoLogFunc(opts.Namespace, releaseName), opts.Namespace, "") if err != nil { return nil, err } diff --git a/pkg/helm/v3/helm.go b/pkg/helm/v3/helm.go index d77ea575c..11cd16491 100644 --- a/pkg/helm/v3/helm.go +++ b/pkg/helm/v3/helm.go @@ -26,9 +26,9 @@ import ( const VERSION = "v3" var ( - repositoryConfig = helmpath.ConfigPath("repositories.yaml") - repositoryCache = helmpath.CachePath("repository") - pluginsDir = helmpath.DataPath("plugins") + repositoryConfig = helmpath.ConfigPath("repositories.yaml") + repositoryCache = helmpath.CachePath("repository") + pluginsDir = helmpath.DataPath("plugins") ) type HelmOptions struct { @@ -63,9 +63,11 @@ func (h *HelmV3) Version() string { // infoLogFunc allows us to pass our logger to components // that expect a klog.Infof function. -func (h *HelmV3) infoLogFunc(format string, args ...interface{}) { - message := fmt.Sprintf(format, args...) - h.logger.Log("info", message) +func (h *HelmV3) infoLogFunc(namespace string, releaseName string) infoLogFunc { + return func(format string, args ...interface{}) { + message := fmt.Sprintf(format, args...) + h.logger.Log("info", message, "targetNamespace", namespace, "release", releaseName) + } } func newActionConfig(config *rest.Config, logFunc infoLogFunc, namespace, driver string) (*action.Configuration, error) { diff --git a/pkg/helm/v3/history.go b/pkg/helm/v3/history.go index 1969f63d5..5e9b36e3c 100644 --- a/pkg/helm/v3/history.go +++ b/pkg/helm/v3/history.go @@ -10,7 +10,7 @@ import ( ) func (h *HelmV3) History(releaseName string, opts helm.HistoryOptions) ([]*helm.Release, error) { - cfg, err := newActionConfig(h.kubeConfig, h.infoLogFunc, opts.Namespace, "") + cfg, err := newActionConfig(h.kubeConfig, h.infoLogFunc(opts.Namespace, releaseName), opts.Namespace, "") if err != nil { return nil, err } diff --git a/pkg/helm/v3/rollback.go b/pkg/helm/v3/rollback.go index 8bb221442..279c0bd22 100644 --- a/pkg/helm/v3/rollback.go +++ b/pkg/helm/v3/rollback.go @@ -8,7 +8,7 @@ import ( ) func (h *HelmV3) Rollback(releaseName string, opts helm.RollbackOptions) (*helm.Release, error) { - cfg, err := newActionConfig(h.kubeConfig, h.infoLogFunc, opts.Namespace, "") + cfg, err := newActionConfig(h.kubeConfig, h.infoLogFunc(opts.Namespace, releaseName), opts.Namespace, "") if err != nil { return nil, err } diff --git a/pkg/helm/v3/uninstall.go b/pkg/helm/v3/uninstall.go index db78b4eb0..59d252a39 100644 --- a/pkg/helm/v3/uninstall.go +++ b/pkg/helm/v3/uninstall.go @@ -8,7 +8,7 @@ import ( ) func (h *HelmV3) Uninstall(releaseName string, opts helm.UninstallOptions) error { - cfg, err := newActionConfig(h.kubeConfig, h.infoLogFunc, opts.Namespace, "") + cfg, err := newActionConfig(h.kubeConfig, h.infoLogFunc(opts.Namespace, releaseName), opts.Namespace, "") if err != nil { return err } diff --git a/pkg/helm/v3/upgrade.go b/pkg/helm/v3/upgrade.go index 24beb42f6..c1180f207 100644 --- a/pkg/helm/v3/upgrade.go +++ b/pkg/helm/v3/upgrade.go @@ -14,7 +14,7 @@ import ( func (h *HelmV3) UpgradeFromPath(chartPath string, releaseName string, values []byte, opts helm.UpgradeOptions) (*helm.Release, error) { - cfg, err := newActionConfig(h.kubeConfig, h.infoLogFunc, opts.Namespace, "") + cfg, err := newActionConfig(h.kubeConfig, h.infoLogFunc(opts.Namespace, releaseName), opts.Namespace, "") if err != nil { return nil, err }