From 5ed3cd03be311d8889007ccef793875ad4878d2a Mon Sep 17 00:00:00 2001 From: Ahmet Alp Balkan Date: Wed, 15 Nov 2017 21:45:09 -0800 Subject: [PATCH] auth/gcp: capture stderr from gcloud config-helper Fixes https://github.com/kubernetes/client-go/issues/327 Currently we're not capturing stderr when shelling out to "gcloud config config-helper --format=json" fails. This patch is capturing the stderr in the error message returned. This gcloud command sometimes returns an upgrade reminder (in stderr) so using `cmd.CombinedOutput()` is not an option here. Maybe we should also add an unit test in gcp_test.go capturing this situation, too, in case someone decides to replace this with CombinedOutput someday. Signed-off-by: Ahmet Alp Balkan Kubernetes-commit: 1334523c73fea3b3d9d0e90f287b3e385c79e6cd --- plugin/pkg/client/auth/gcp/gcp.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/plugin/pkg/client/auth/gcp/gcp.go b/plugin/pkg/client/auth/gcp/gcp.go index d2e622ba..5ed1203b 100644 --- a/plugin/pkg/client/auth/gcp/gcp.go +++ b/plugin/pkg/client/auth/gcp/gcp.go @@ -228,9 +228,11 @@ func newCmdTokenSource(cmd string, args []string, tokenKey, expiryKey, timeFmt s func (c *commandTokenSource) Token() (*oauth2.Token, error) { fullCmd := strings.Join(append([]string{c.cmd}, c.args...), " ") cmd := execCommand(c.cmd, c.args...) + var stderr bytes.Buffer + cmd.Stderr = &stderr output, err := cmd.Output() if err != nil { - return nil, fmt.Errorf("error executing access token command %q: err=%v output=%s", fullCmd, err, output) + return nil, fmt.Errorf("error executing access token command %q: err=%v output=%s stderr=%s", fullCmd, err, output, string(stderr.Bytes())) } token, err := c.parseTokenCmdOutput(output) if err != nil {