fix: error when more than one post-renderer is specified

We now make sure the post-renderer flag can be passed at most once instead of silently taking the last one passed.

Example:

```bash
$ helm template test ...  --post-renderer=true --post-renderer=cat
Error: invalid argument "cat" for "--post-renderer" flag: cannot set post-renderer more than once, given: cat, previous: true
```

Signed-off-by: Yarden Shoham <git@yardenshoham.com>
pull/30572/head
Yarden Shoham 7 months ago
parent 2cda65d444
commit 9e17871afb

@ -24,6 +24,7 @@ import (
"sort"
"strings"
"github.com/pkg/errors"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
"k8s.io/klog/v2"
@ -143,6 +144,9 @@ func (p *postRendererString) Set(val string) error {
if val == "" {
return nil
}
if p.options.binaryPath != "" && p.options.binaryPath != val {
return errors.Errorf("cannot set post-renderer more than once, given: %s, previous: %s", val, p.options.binaryPath)
}
p.options.binaryPath = val
pr, err := postrender.NewExec(p.options.binaryPath, p.options.args...)
if err != nil {

@ -20,6 +20,9 @@ import (
"fmt"
"testing"
"github.com/stretchr/testify/require"
"helm.sh/helm/v4/pkg/action"
"helm.sh/helm/v4/pkg/chart"
"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 ok
err = str.Set("echo")
require.NoError(t, err)
// Set the binary again to a different value is not ok
err = str.Set("cat")
require.Error(t, err)
}

Loading…
Cancel
Save