From 8122e9b05d55dc96215fa2ca80f8ed6d0bfabf9f Mon Sep 17 00:00:00 2001 From: Rob Best Date: Fri, 31 Jan 2020 09:14:14 +0000 Subject: [PATCH] discard the contents of the kustomize pipe before calling Wait() If kubectl exited before kustomize had written to stdout, Wait() would wait indefinitely for the contents of the pipe to be read from. Discarding the contents of the pipe before waiting resolves this issue. --- kube/client.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/kube/client.go b/kube/client.go index 0447c003..841648e1 100644 --- a/kube/client.go +++ b/kube/client.go @@ -3,6 +3,7 @@ package kube import ( "encoding/json" "fmt" + "io" "io/ioutil" "os" "os/exec" @@ -142,11 +143,11 @@ func (c *Client) Apply(path, namespace string, dryRun, prune, kustomize bool, pr if kustomize { cmdStr = "kustomize build " + path + " | " + strings.Join(args, " ") kustomizeCmd := exec.Command("kustomize", "build", path) - pipe, err := kustomizeCmd.StdoutPipe() + kustomizeStdout, err := kustomizeCmd.StdoutPipe() if err != nil { return cmdStr, "", err } - kubectlCmd.Stdin = pipe + kubectlCmd.Stdin = kustomizeStdout err = kustomizeCmd.Start() if err != nil { @@ -154,6 +155,7 @@ func (c *Client) Apply(path, namespace string, dryRun, prune, kustomize bool, pr return cmdStr, "", err } defer func() { + io.Copy(ioutil.Discard, kustomizeStdout) err = kustomizeCmd.Wait() if err != nil { fmt.Printf("%s", err)