Skip to content

Commit

Permalink
Merge pull request #1408 from garethjevans/labels
Browse files Browse the repository at this point in the history
feat: using terraform to manange resource labels for cluster
  • Loading branch information
garethjevans committed Aug 1, 2018
2 parents 8902398 + 956c36c commit f83bf4e
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 41 deletions.
2 changes: 1 addition & 1 deletion pkg/jx/cmd/create_codeship.go
Expand Up @@ -419,7 +419,7 @@ func ProjectExists(ctx context.Context, org *codeship.Organization, codeshipOrg

func jxVersion() string {
if version.Version == "1.0.1" {
return "1.3.132"
return "1.3.143"
}
return version.Version
}
Expand Down
42 changes: 2 additions & 40 deletions pkg/jx/cmd/create_terraform.go
Expand Up @@ -676,7 +676,7 @@ func (o *CreateTerraformOptions) writeGitIgnoreFile(dir string) error {
}
defer file.Close()

_, err = file.WriteString("**/*.key.json\n.terraform\n**/*.tfstate\n")
_, err = file.WriteString("**/*.key.json\n.terraform\n**/*.tfstate\njx\n")
if err != nil {
return err
}
Expand Down Expand Up @@ -832,10 +832,6 @@ func (o *CreateTerraformOptions) applyTerraformGKE(g *GKECluster, path string) e
}

log.Info("Applying Terraform changes\n")
user, err := os_user.Current()
if err != nil {
return err
}

terraformVars := filepath.Join(path, "terraform.tfvars")

Expand All @@ -859,7 +855,7 @@ func (o *CreateTerraformOptions) applyTerraformGKE(g *GKECluster, path string) e
serviceAccountName := fmt.Sprintf("jx-%s-%s", o.Flags.OrganisationName, g.Name())
fmt.Fprintf(o.Stdout(), "No GCP service account provided, creating %s\n", util.ColorInfo(serviceAccountName))

_, err = gke.GetOrCreateServiceAccount(serviceAccountName, g.ProjectId, filepath.Dir(path))
_, err := gke.GetOrCreateServiceAccount(serviceAccountName, g.ProjectId, filepath.Dir(path))
if err != nil {
return err
}
Expand Down Expand Up @@ -926,40 +922,6 @@ func (o *CreateTerraformOptions) applyTerraformGKE(g *GKECluster, path string) e
return err
}

// should we setup the labels at this point?
args := []string{"container",
"clusters",
"update",
g.ClusterName(),
"--project",
g.ProjectId,
"--zone",
g.Zone}

labels := ""
if err == nil && user != nil {
username := sanitizeLabel(user.Username)
if username != "" {
sep := ""
if labels != "" {
sep = ","
}
labels += sep + "created-by=" + username
}
}

sep := ""
if labels != "" {
sep = ","
}
labels += sep + fmt.Sprintf("created-with=terraform,created-on=%s", time.Now().Format("20060102150405"))
args = append(args, "--update-labels="+strings.ToLower(labels))

err = o.runCommand("gcloud", args...)
if err != nil {
return err
}

output, err := o.getCommandOutput("", "gcloud", "container", "clusters", "get-credentials", g.ClusterName(), "--zone", g.Zone, "--project", g.ProjectId)
if err != nil {
return err
Expand Down

0 comments on commit f83bf4e

Please sign in to comment.