mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-06 18:54:06 +00:00
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 <ahmetb@google.com>
This commit is contained in:
parent
c3ed0f2663
commit
1334523c73
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user