From 4c7cb9c83dcdeb5e32f515ba07115815a52bf9eb Mon Sep 17 00:00:00 2001 From: Ash Caire Date: Wed, 1 Apr 2020 15:12:27 +0800 Subject: [PATCH] WIP: Post Render args example Signed-off-by: Ash Caire --- pkg/postrender/exec.go | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/pkg/postrender/exec.go b/pkg/postrender/exec.go index 0860e7c35..7f21275a3 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) { - fullPath, err := getFullPath(binaryPath) +// Any passed arguments are joined by commas, and sent as one argument +func NewExec(binaryPathAndArgs string) (PostRenderer, error) { + binaryPathAndArgsCsv := strings.Split(binaryPathAndArgs, ",") + args := []string{strings.Join(binaryPathAndArgsCsv[1:], ",")} + fullPath, err := getFullPath(binaryPathAndArgsCsv[0]) 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