Skip to content

Commit

Permalink
feat: allow setting the version to latest
Browse files Browse the repository at this point in the history
  • Loading branch information
luisdavim committed Nov 19, 2022
1 parent 4044fb0 commit 0158672
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
20 changes: 14 additions & 6 deletions internal/app/helm_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,11 @@ func getChartInfo(chartName, chartVersion string) (*ChartInfo, error) {
log.Info("Chart [ " + chartName + " ] with version [ " + chartVersion + " ] was found locally.")
}

cmd := helmCmd([]string{"show", "chart", chartName, "--version", chartVersion}, "Getting latest non-local chart's version "+chartName+"-"+chartVersion+"")
args := []string{"show", "chart", chartName}
if chartVersion != "latest" {
args = append(args, "--version", chartVersion)
}
cmd := helmCmd(args, "Getting latest non-local chart's version "+chartName+"-"+chartVersion+"")

res, err := cmd.Exec()
if err != nil {
Expand Down Expand Up @@ -150,13 +154,17 @@ func helmExportChart(chart, dest string) error {
// helmPullChart pulls chart and exports it to the specified destination
// this should only be used with helm versions greater or equal to 3.7.0
func helmPullChart(chart, dest string) error {
version := "latest"
chartParts := strings.Split(chart, ":")
if len(chartParts) < 2 {
return fmt.Errorf("missing chart version")
if len(chartParts) >= 2 {
version = chartParts[len(chartParts)-1]
chart = strings.Join(chartParts[:len(chartParts)-1], ":")
}
args := []string{"pull", chart, "-d", dest}
if version != "latest" {
args = append(args, "--version", version)
}
version := chartParts[len(chartParts)-1]
chart = strings.Join(chartParts[:len(chartParts)-1], ":")
cmd := helmCmd([]string{"pull", chart, "-d", dest, "--version", version}, "Pulling chart [ "+chart+" ] to "+dest)
cmd := helmCmd(args, "Pulling chart [ "+chart+" ] to "+dest)
if _, err := cmd.Exec(); err != nil {
return err
}
Expand Down
10 changes: 7 additions & 3 deletions internal/app/release.go
Original file line number Diff line number Diff line change
Expand Up @@ -427,13 +427,17 @@ func (r *Release) getHelmArgsFor(action string, optionalNamespaceOverride ...str
if len(optionalNamespaceOverride) > 0 {
ns = optionalNamespaceOverride[0]
}
args := []string{r.Name, r.Chart, "--namespace", ns}
if r.Version != "latest" {
args = append(args, "--version", r.Version)
}
switch action {
case "template":
return concat([]string{"template", r.Name, r.Chart, "--version", r.Version, "--namespace", r.Namespace, "--skip-tests", "--no-hooks"}, r.getValuesFiles(), r.getSetValues(), r.getSetStringValues(), r.getSetFileValues(), r.getPostRenderer())
return concat([]string{"template"}, args, []string{"--skip-tests", "--no-hooks"}, r.getValuesFiles(), r.getSetValues(), r.getSetStringValues(), r.getSetFileValues(), r.getPostRenderer())
case "install", "upgrade":
return concat([]string{"upgrade", r.Name, r.Chart, "--install", "--version", r.Version, "--namespace", r.Namespace}, r.getValuesFiles(), r.getSetValues(), r.getSetStringValues(), r.getSetFileValues(), r.getHelmFlags(), r.getPostRenderer())
return concat([]string{"upgrade", "--install"}, args, r.getValuesFiles(), r.getSetValues(), r.getSetStringValues(), r.getSetFileValues(), r.getHelmFlags(), r.getPostRenderer())
case "diff":
return concat([]string{"upgrade", r.Name, r.Chart, "--version", r.Version, "--namespace", r.Namespace}, r.getValuesFiles(), r.getSetValues(), r.getSetStringValues(), r.getSetFileValues(), r.HelmDiffFlags, r.getPostRenderer())
return concat([]string{"upgrade"}, args, r.getValuesFiles(), r.getSetValues(), r.getSetStringValues(), r.getSetFileValues(), r.HelmDiffFlags, r.getPostRenderer())
case "uninstall":
return concat([]string{action, "--namespace", ns, r.Name}, flags.getRunFlags())
default:
Expand Down

0 comments on commit 0158672

Please sign in to comment.