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

Commit

Permalink
Add Helm 3 compatibility for passing release name
Browse files Browse the repository at this point in the history
  • Loading branch information
John Esmet committed Nov 19, 2019
1 parent a6a0fbc commit a0dff58
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 4 deletions.
10 changes: 9 additions & 1 deletion ankh/execute.go
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,15 @@ func executeAnkhFile(ctx *ankh.ExecutionContext, ankhFile *ankh.AnkhFile) {
ctx.Logger.Fatalf("Failed to get helm version info: %v", err)
}
ctx.HelmVersion = ver
ctx.Logger.Debug("Using helm version: ", strings.TrimSpace(ver))
trimmed := strings.TrimSpace(ver)
ctx.Logger.Debug("Using Helm version: ", trimmed)

// Helm's version command is, itself, not written in a backwads compatible
// way. We choose the 'Client: ' magic sting to prove that Helm is version 2,
// because Tiller and the "client" distinction was removed in Helm 3+.
if strings.HasPrefix(trimmed, "Client: ") {
ctx.HelmV2 = true
}
}

logChartsExecute := func(charts []ankh.Chart, namespace string, extra string) {
Expand Down
2 changes: 1 addition & 1 deletion ankh/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -977,7 +977,7 @@ func main() {
ctx.Logger.Infof("Ankh version info:")
fmt.Println(AnkhBuildVersion)

ctx.Logger.Infof("`%v version --client` output:", ctx.AnkhConfig.Helm.Command)
ctx.Logger.Infof("`%v version --client --short` output:", ctx.AnkhConfig.Helm.Command)
ver, err := helm.Version(ctx)
check(err)
fmt.Print(ver)
Expand Down
2 changes: 2 additions & 0 deletions context/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ type ExecutionContext struct {

HelmVersion, KubectlVersion string

HelmV2 bool

Logger *logrus.Logger
}

Expand Down
2 changes: 1 addition & 1 deletion helm/helm.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ func FetchChartMeta(ctx *ankh.ExecutionContext, repository string, chart *ankh.C

func Version(ctx *ankh.ExecutionContext) (string, error) {
cmd := plan.NewCommand(ctx.AnkhConfig.Helm.Command)
cmd.AddArguments([]string{"version", "--client"})
cmd.AddArguments([]string{"version", "--client", "--short"})
// We want to return the output of the version command in Run, so use a pipe
cmd.PipeStdoutAndStderr = plan.PIPE_TYPE_PIPE
return cmd.Run(ctx, nil)
Expand Down
7 changes: 6 additions & 1 deletion helm/templatestage.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,12 @@ func templateChart(ctx *ankh.ExecutionContext, chart ankh.Chart, namespace strin
}

if currentContext.Release != "" {
helmArgs = append(helmArgs, []string{"--name", currentContext.Release}...)
// Helm 2 used `--name` to set release nam. Starting in Helm 3, this is a _positional_ argument.
if ctx.HelmV2 {
helmArgs = append(helmArgs, []string{"--name", currentContext.Release}...)
} else {
helmArgs = append(helmArgs, []string{currentContext.Release}...)
}
}

for key, val := range ctx.HelmSetValues {
Expand Down

0 comments on commit a0dff58

Please sign in to comment.