From 01e593fbcd7f4df7b3db75c0db79c067f3372df4 Mon Sep 17 00:00:00 2001 From: Taylor Thomas Date: Fri, 11 Oct 2019 11:39:40 -0600 Subject: [PATCH] fix(action): Fixes ordering of variable binding The recent init action config switched the order of how variables get bound and where. This led to the namespace variable not being propagated down into the calls to kubernetes. Co-authored-by: Matthew Fisher Signed-off-by: Taylor Thomas --- cmd/helm/helm.go | 7 +++---- cmd/helm/list.go | 4 +++- pkg/action/action.go | 16 +++++++--------- 3 files changed, 13 insertions(+), 14 deletions(-) diff --git a/cmd/helm/helm.go b/cmd/helm/helm.go index c309edf71..0e935addb 100644 --- a/cmd/helm/helm.go +++ b/cmd/helm/helm.go @@ -64,9 +64,10 @@ func initKubeLogs() { func main() { initKubeLogs() - actionConfig, err := action.InitActionConfig(settings, false, os.Getenv("HELM_DRIVER"), debug) + actionConfig := new(action.Configuration) + cmd := newRootCmd(actionConfig, os.Stdout, os.Args[1:]) - if err != nil { + if err := actionConfig.Init(settings, false, os.Getenv("HELM_DRIVER"), debug); err != nil { debug("%+v", err) switch e := err.(type) { case pluginError: @@ -76,8 +77,6 @@ func main() { } } - cmd := newRootCmd(actionConfig, os.Stdout, os.Args[1:]) - if err := cmd.Execute(); err != nil { debug("%+v", err) os.Exit(1) diff --git a/cmd/helm/list.go b/cmd/helm/list.go index 50f9a7441..2200c153b 100644 --- a/cmd/helm/list.go +++ b/cmd/helm/list.go @@ -70,7 +70,9 @@ func newListCmd(cfg *action.Configuration, out io.Writer) *cobra.Command { Args: require.NoArgs, RunE: func(cmd *cobra.Command, args []string) error { if client.AllNamespaces { - action.InitActionConfig(settings, true, os.Getenv("HELM_DRIVER"), debug) + if err := cfg.Init(settings, true, os.Getenv("HELM_DRIVER"), debug); err != nil { + return err + } } client.SetStateMask() diff --git a/pkg/action/action.go b/pkg/action/action.go index 7cfe4a7d3..a36454321 100644 --- a/pkg/action/action.go +++ b/pkg/action/action.go @@ -210,9 +210,7 @@ func (c *Configuration) recordRelease(r *release.Release) { } // InitActionConfig initializes the action configuration -func InitActionConfig(envSettings *cli.EnvSettings, allNamespaces bool, helmDriver string, log DebugLog) (*Configuration, error) { - - var actionConfig Configuration +func (c *Configuration) Init(envSettings *cli.EnvSettings, allNamespaces bool, helmDriver string, log DebugLog) error { kubeconfig := envSettings.KubeConfig() kc := kube.New(kubeconfig) @@ -220,7 +218,7 @@ func InitActionConfig(envSettings *cli.EnvSettings, allNamespaces bool, helmDriv clientset, err := kc.Factory.KubernetesClientSet() if err != nil { - return nil, err + return err } var namespace string if !allNamespaces { @@ -245,10 +243,10 @@ func InitActionConfig(envSettings *cli.EnvSettings, allNamespaces bool, helmDriv panic("Unknown driver in HELM_DRIVER: " + helmDriver) } - actionConfig.RESTClientGetter = kubeconfig - actionConfig.KubeClient = kc - actionConfig.Releases = store - actionConfig.Log = log + c.RESTClientGetter = kubeconfig + c.KubeClient = kc + c.Releases = store + c.Log = log - return &actionConfig, nil + return nil }