diff --git a/cmd/helm/flags.go b/cmd/helm/flags.go index 8d0f644d6..379b2140d 100644 --- a/cmd/helm/flags.go +++ b/cmd/helm/flags.go @@ -143,6 +143,9 @@ func (p *postRendererString) Set(val string) error { if val == "" { return nil } + if p.options.binaryPath != "" { + return fmt.Errorf("cannot specify --post-renderer flag more than once") + } p.options.binaryPath = val pr, err := postrender.NewExec(p.options.binaryPath, p.options.args...) if err != nil { diff --git a/cmd/helm/flags_test.go b/cmd/helm/flags_test.go index 3a9d7e6ef..e55c51ce4 100644 --- a/cmd/helm/flags_test.go +++ b/cmd/helm/flags_test.go @@ -20,6 +20,9 @@ import ( "fmt" "testing" + "github.com/stretchr/testify/require" + + "helm.sh/helm/v4/pkg/action" chart "helm.sh/helm/v4/pkg/chart/v2" "helm.sh/helm/v4/pkg/release" helmtime "helm.sh/helm/v4/pkg/time" @@ -93,3 +96,24 @@ func outputFlagCompletionTest(t *testing.T, cmdName string) { }} runTestCmd(t, tests) } + +func TestPostRendererFlagSetOnce(t *testing.T) { + cfg := action.Configuration{} + client := action.NewInstall(&cfg) + str := postRendererString{ + options: &postRendererOptions{ + renderer: &client.PostRenderer, + }, + } + // Set the binary once + err := str.Set("echo") + require.NoError(t, err) + + // Set the binary again to the same value is not ok + err = str.Set("echo") + require.Error(t, err) + + // Set the binary again to a different value is not ok + err = str.Set("cat") + require.Error(t, err) +}