Skip to content

Commit

Permalink
Move helm home logic
Browse files Browse the repository at this point in the history
  • Loading branch information
lblackstone committed Aug 26, 2020
1 parent 404b029 commit 4f2ad27
Showing 1 changed file with 19 additions and 19 deletions.
38 changes: 19 additions & 19 deletions provider/pkg/provider/invoke_helm_template.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,25 @@ func helmTemplate(opts HelmChartOpts) (string, error) {
chartDir: tempDir,
}

// If the 'home' option is specified, set the HELM_HOME env var for the duration of the invoke and then reset it
// to its previous state.
if chart.opts.Home != "" {
if helmHome, ok := os.LookupEnv("HELM_HOME"); ok {
chart.helmHome = &helmHome
}
err := os.Setenv("HELM_HOME", chart.opts.Home)
if err != nil {
return "", pkgerrors.Wrap(err, "failed to set HELM_HOME")
}
defer func() {
if chart.helmHome != nil {
_ = os.Setenv("HELM_HOME", *chart.helmHome)
} else {
_ = os.Unsetenv("HELM_HOME")
}
}()
}

// If Path is set, use a local Chart, otherwise fetch from a remote.
if len(chart.opts.Path) > 0 {
chart.chartDir = chart.opts.Path
Expand Down Expand Up @@ -117,25 +136,6 @@ func (c *chart) fetch() error {
p.Username = c.opts.Username
p.Verify = c.opts.Verify

// If the 'home' option is specified, set the HELM_HOME env var for the duration of the invoke and then reset it
// to its previous state.
if c.opts.Home != "" {
if helmHome, ok := os.LookupEnv("HELM_HOME"); ok {
c.helmHome = &helmHome
}
err := os.Setenv("HELM_HOME", c.opts.Home)
if err != nil {
return pkgerrors.Wrap(err, "failed to set HELM_HOME")
}
defer func() {
if c.helmHome != nil {
_ = os.Setenv("HELM_HOME", *c.helmHome)
} else {
_ = os.Unsetenv("HELM_HOME")
}
}()
}

if c.opts.Version == "" && c.opts.Devel {
p.Version = ">0.0.0-0"
} else {
Expand Down

0 comments on commit 4f2ad27

Please sign in to comment.