diff --git a/cmd/list.go b/cmd/list.go index a3850fa..b104596 100644 --- a/cmd/list.go +++ b/cmd/list.go @@ -75,6 +75,7 @@ type listCmd struct { chartName string namespace string valuesOpts cliValues.Options + helmPath string verbose bool debug bool } @@ -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") { @@ -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 } diff --git a/internal/helm/helm.go b/internal/helm/helm.go index d51150e..6b3b347 100644 --- a/internal/helm/helm.go +++ b/internal/helm/helm.go @@ -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} @@ -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 diff --git a/plugin.yaml b/plugin.yaml index 64d0101..2ab8db0 100644 --- a/plugin.yaml +++ b/plugin.yaml @@ -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"