Skip to content

Commit

Permalink
Fixed fetch command parsing when chart is not locally present
Browse files Browse the repository at this point in the history
  • Loading branch information
cvila84 committed Jun 30, 2022
1 parent 6488406 commit e23c3fa
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 17 deletions.
6 changes: 4 additions & 2 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 != "" {
Expand All @@ -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)
}
Expand Down
29 changes: 15 additions & 14 deletions pkg/helm/helm.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion plugin.yaml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down

0 comments on commit e23c3fa

Please sign in to comment.