From e23c3fabec30b28a0b026061a02c2b0513669934 Mon Sep 17 00:00:00 2001 From: Christophe VILA Date: Thu, 30 Jun 2022 15:48:40 +0200 Subject: [PATCH] Fixed fetch command parsing when chart is not locally present --- cmd/root.go | 6 ++++-- pkg/helm/helm.go | 29 +++++++++++++++-------------- plugin.yaml | 2 +- 3 files changed, 20 insertions(+), 17 deletions(-) diff --git a/cmd/root.go b/cmd/root.go index dc7010e..df9de49 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -119,10 +119,11 @@ func NewRootCmd() *cobra.Command { log.Info(1, "fetching chart from URL \"%s\"...", s.ChartName) } var err error - s.ChartName, err = helm.Fetch(s.ChartName, s.ChartVersion) + fetchedChartName, err := helm.Fetch(s.ChartName, s.ChartVersion) if err != nil { return fmt.Errorf("fetching chart %s with version %s: %w", s.ChartName, s.ChartVersion, err) } + s.ChartName = fetchedChartName } else if _, err := os.Stat(s.ChartName); err != nil { // If local file (or directory) does not exist, then fetch it from a repo. if s.ChartVersion != "" { @@ -131,10 +132,11 @@ func NewRootCmd() *cobra.Command { log.Info(1, "fetching chart \"%s\" from repos...", s.ChartName) } var err error - s.ChartName, err = helm.Fetch(s.ChartName, s.ChartVersion) + fetchedChartName, err := helm.Fetch(s.ChartName, s.ChartVersion) if err != nil { return fmt.Errorf("fetching chart %s with version %s: %w", s.ChartName, s.ChartVersion, err) } + s.ChartName = fetchedChartName } else { log.Info(1, "processing chart from local file or directory \"%s\"...", s.ChartName) } diff --git a/pkg/helm/helm.go b/pkg/helm/helm.go index a218053..06ac935 100644 --- a/pkg/helm/helm.go +++ b/pkg/helm/helm.go @@ -151,29 +151,30 @@ func Fetch(chart string, version string) (string, error) { } defer removeTempDir(tempDir) - var command string var cmd *exec.Cmd + + var args = []string{"fetch", chart, "--destination", tempDir} + if version != "" { + args = append(args, "--version", version) + } + cmd = exec.Command("helm", args...) + cmd.Stdout = os.Stdout + cmd.Stderr = os.Stderr + if err := cmd.Run(); err != nil { + return "", err + } + + var command string var endOfLine string if runtime.GOOS == "windows" { - if version != "" { - command = "helm fetch " + chart + " --destination " + tempDir + " --version " + version - } else { - command = "helm fetch " + chart + " --destination " + tempDir - } - command = command + " && dir /b " + tempDir + " && copy " + tempDir + "\\* ." + command = "dir /b " + tempDir + " && copy " + tempDir + "\\* ." cmd = exec.Command("cmd", "/C", command) endOfLine = "\r\n" } else { - if version != "" { - command = "helm fetch " + chart + " --destination " + tempDir + " --version " + version - } else { - command = "helm fetch " + chart + " --destination " + tempDir - } - command = command + " && ls " + tempDir + " && cp " + tempDir + "/* ." + command = "ls " + tempDir + " && cp " + tempDir + "/* ." cmd = exec.Command("sh", "-c", command) endOfLine = "\n" } - cmdOutput := &bytes.Buffer{} cmd.Stdout = cmdOutput cmd.Stderr = os.Stderr diff --git a/plugin.yaml b/plugin.yaml index b047686..bd0ee79 100644 --- a/plugin.yaml +++ b/plugin.yaml @@ -1,5 +1,5 @@ name: "spray" -version: 4.0.11-beta.2 +version: 4.0.11-beta.3 usage: "upgrade sub-charts from an umbrella chart with dependency orders" description: "Helm plugin for upgrading sub-charts from umbrella chart with dependency orders" command: "$HELM_PLUGIN_DIR/bin/helm-spray"