Skip to content
This repository has been archived by the owner on Nov 1, 2022. It is now read-only.

helm/v3: add release name to log context for internal Helm logs #291

Merged
merged 1 commit into from
Feb 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pkg/helm/v3/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
14 changes: 8 additions & 6 deletions pkg/helm/v3/helm.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/helm/v3/history.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/helm/v3/rollback.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/helm/v3/uninstall.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/helm/v3/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down