Skip to content

Commit

Permalink
use stdout from kind command when writing kubeconfig
Browse files Browse the repository at this point in the history
Signed-off-by: Chris Randles <[email protected]>
  • Loading branch information
crandles committed Nov 30, 2021
1 parent 9917308 commit bdb0467
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions support/kind/kind.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
package kind

import (
"bytes"
"fmt"
"io"
"io/ioutil"
Expand Down Expand Up @@ -48,8 +49,16 @@ func (k *Cluster) WithVersion(ver string) *Cluster {

func (k *Cluster) getKubeconfig() (string, error) {
kubecfg := fmt.Sprintf("%s-kubecfg", k.name)
p := k.e.RunProc(fmt.Sprintf(`kind get kubeconfig --name %s`, k.name))

p := k.e.StartProc(fmt.Sprintf(`kind get kubeconfig --name %s`, k.name))
if p.Err() != nil {
return "", fmt.Errorf("kind get kubeconfig: %w", p.Err())
}
var stdout bytes.Buffer
if _, err := stdout.ReadFrom(p.StdOut()); err != nil {
return "", fmt.Errorf("kind kubeconfig stdout bytes: %w", err)
}
if p.Wait().Err() != nil {
return "", fmt.Errorf("kind get kubeconfig: %s: %w", p.Result(), p.Err())
}

Expand All @@ -61,7 +70,7 @@ func (k *Cluster) getKubeconfig() (string, error) {

k.kubecfgFile = file.Name()

if n, err := io.Copy(file, strings.NewReader(p.Result())); n == 0 || err != nil {
if n, err := io.Copy(file, &stdout); n == 0 || err != nil {
return "", fmt.Errorf("kind kubecfg file: bytes copied: %d: %w]", n, err)
}

Expand Down

0 comments on commit bdb0467

Please sign in to comment.