From 627be7104e6aefc98f53cd11d5365bfad975c9cd Mon Sep 17 00:00:00 2001 From: Kam D Kasravi Date: Sat, 16 Mar 2019 08:04:35 -0700 Subject: [PATCH] fixes 'kfctl creates invalid IAM policy binding file if email not set' --- bootstrap/pkg/kfapp/gcp/gcp.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/bootstrap/pkg/kfapp/gcp/gcp.go b/bootstrap/pkg/kfapp/gcp/gcp.go index fa9893a52de..566b0f916c3 100644 --- a/bootstrap/pkg/kfapp/gcp/gcp.go +++ b/bootstrap/pkg/kfapp/gcp/gcp.go @@ -101,6 +101,16 @@ func GetClusterInfo(ctx context.Context, project string, loc string, cluster str return c.GetCluster(ctx, getClusterReq) } +// if --email is not supplied try and the get account info using gmail +func GetAccount() (string, error) { + output, err := exec.Command("gcloud", "config", "get-value", "account").Output() + if err != nil { + return "", fmt.Errorf("could not call 'gcloud config get-value account': %v", err) + } + account := string(output) + return strings.TrimSpace(account), nil +} + // BuildConfigFromClusterInfo returns k8s config using gcloud Application Default Credentials // typically $HOME/.config/gcloud/application_default_credentials.json func BuildConfigFromClusterInfo(ctx context.Context, cluster *containerpb.Cluster) (*rest.Config, error) { @@ -762,6 +772,13 @@ func (gcp *Gcp) createSecrets() error { } func (gcp *Gcp) Generate(resources kftypes.ResourceEnum) error { + if gcp.Spec.Email == "" { + account, err := GetAccount() + if err != nil { + return fmt.Errorf("--email not specified and cannot get gcloud value. Error: %v", err) + } + gcp.Spec.Email = account + } switch resources { case kftypes.K8S: generateK8sSpecsErr := gcp.downloadK8sManifests()