diff --git a/pkg/postrender/exec.go b/pkg/postrender/exec.go index 0860e7c35..c3a45a215 100644 --- a/pkg/postrender/exec.go +++ b/pkg/postrender/exec.go @@ -21,29 +21,34 @@ import ( "io" "os/exec" "path/filepath" + "strings" "github.com/pkg/errors" ) type execRender struct { binaryPath string + args []string } // NewExec returns a PostRenderer implementation that calls the provided binary. // It returns an error if the binary cannot be found. If the path does not // contain any separators, it will search in $PATH, otherwise it will resolve // any relative paths to a fully qualified path -func NewExec(binaryPath string) (PostRenderer, error) { +func NewExec(command string) (PostRenderer, error) { + commandList := strings.Split(command, " ") + binaryPath, args := commandList[0], commandList[1:] + fullPath, err := getFullPath(binaryPath) if err != nil { return nil, err } - return &execRender{fullPath}, nil + return &execRender{fullPath, args}, nil } // Run the configured binary for the post render func (p *execRender) Run(renderedManifests *bytes.Buffer) (*bytes.Buffer, error) { - cmd := exec.Command(p.binaryPath) + cmd := exec.Command(p.binaryPath, p.args...) stdin, err := cmd.StdinPipe() if err != nil { return nil, err diff --git a/pkg/postrender/exec_test.go b/pkg/postrender/exec_test.go index ef0956949..8275cb0e2 100644 --- a/pkg/postrender/exec_test.go +++ b/pkg/postrender/exec_test.go @@ -31,7 +31,7 @@ import ( ) const testingScript = `#!/bin/sh -sed s/FOOTEST/BARTEST/g <&0 +sed s/FOOTEST/${1:-BARTEST}/g <&0 ` func TestGetFullPath(t *testing.T) { @@ -124,6 +124,23 @@ func TestExecRun(t *testing.T) { is.Contains(output.String(), "BARTEST") } +func TestExecRunWithArgs(t *testing.T) { + if runtime.GOOS == "windows" { + // the actual Run test uses a basic sed example, so skip this test on windows + t.Skip("skipping on windows") + } + is := assert.New(t) + testpath, cleanup := setupTestingScript(t) + defer cleanup() + + renderer, err := NewExec(testpath + " ARGUMENT") + require.NoError(t, err) + + output, err := renderer.Run(bytes.NewBufferString("FOOTEST")) + is.NoError(err) + is.Contains(output.String(), "ARGUMENT") +} + func setupTestingScript(t *testing.T) (filepath string, cleanup func()) { t.Helper()