Skip to content

Commit

Permalink
fixes 'kfctl creates invalid IAM policy binding file if email not set' (
Browse files Browse the repository at this point in the history
  • Loading branch information
kkasravi authored and k8s-ci-robot committed Mar 21, 2019
1 parent 89f9c5a commit bf09137
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions bootstrap/pkg/kfapp/gcp/gcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -768,6 +778,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()
Expand Down

0 comments on commit bf09137

Please sign in to comment.