Skip to content

Commit

Permalink
rely on HELM_BIN envvar to execute helm from plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
cvila84 committed Sep 17, 2020
1 parent e54235f commit e43c055
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
6 changes: 5 additions & 1 deletion cmd/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ type listCmd struct {
chartName string
namespace string
valuesOpts cliValues.Options
helmPath string
verbose bool
debug bool
}
Expand Down Expand Up @@ -109,6 +110,9 @@ func newListCmd(out io.Writer) *cobra.Command {
flags.StringArrayVar(&l.valuesOpts.FileValues, "set-file", []string{}, "set values from respective files specified via the command line (can specify multiple or separate values with commas: key1=path1,key2=path2)")
flags.BoolVarP(&l.verbose, "verbose", "v", false, "enable verbose output")

// When called through helm, helm path is transmitted through the HELM_BIN envvar
l.helmPath = os.Getenv("HELM_BIN")

// When called through helm, debug mode is transmitted through the HELM_DEBUG envvar
helmDebug := os.Getenv("HELM_DEBUG")
if helmDebug == "1" || strings.EqualFold(helmDebug, "true") || strings.EqualFold(helmDebug, "on") {
Expand Down Expand Up @@ -220,7 +224,7 @@ func (l *listCmd) processChart(images *imagesList, chartName string, valuesSet [
return fmt.Errorf("creating temporary directory to write rendered manifests: %w", err)
}
defer removeTempDir(tempDir)
err = helm.Template(tempDir, l.namespace, l.chartName, l.valuesOpts.ValueFiles, valuesSet, l.valuesOpts.StringValues, l.valuesOpts.FileValues, l.debug)
err = helm.Template(l.helmPath, tempDir, l.namespace, l.chartName, l.valuesOpts.ValueFiles, valuesSet, l.valuesOpts.StringValues, l.valuesOpts.FileValues, l.debug)
if err != nil {
return err
}
Expand Down
6 changes: 3 additions & 3 deletions internal/helm/helm.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ var httpProvider = getter.Provider{
New: getter.NewHTTPGetter,
}

func Template(manifestDir string, namespace string, chartPath string, valueFiles []string, valuesSet []string, valuesSetString []string, valuesSetFile []string, debug bool) error {
func Template(helmPath string, manifestDir string, namespace string, chartPath string, valueFiles []string, valuesSet []string, valuesSetString []string, valuesSetFile []string, debug bool) error {
// Prepare parameters...
var myargs = []string{"template", chartPath, "--disable-openapi-validation", "--output-dir", manifestDir, "--namespace", namespace}

Expand All @@ -47,9 +47,9 @@ func Template(manifestDir string, namespace string, chartPath string, valueFiles

// Run the upgrade command
if debug {
log.Printf("Running helm %s\n", myargs)
log.Printf("Running %s %v\n", helmPath, myargs)
}
cmd := exec.Command("helm", myargs...)
cmd := exec.Command(helmPath, myargs...)
cmdOutput := &bytes.Buffer{}
cmd.Stderr = os.Stderr
cmd.Stdout = cmdOutput
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: "image"
version: 1.0.1
version: 1.0.2
usage: "get docker images from a chart"
description: "Helm plugin for getting docker images from a chart"
command: "$HELM_PLUGIN_DIR/bin/helm-image"
Expand Down

0 comments on commit e43c055

Please sign in to comment.