cmd/gcpinit: delete
I noticed some unused-looking fields in the Environment type. gcpinit
looks dead to me, so delete it. Correct me if I'm wrong.
For golang/go#48408.
Change-Id: Ie0732177ada8c291f2bddc1b64a6b242a521d5bc
Reviewed-on: https://go-review.googlesource.com/c/build/+/350113
Trust: Heschi Kreinick <heschi@google.com>
Run-TryBot: Heschi Kreinick <heschi@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Alexander Rakoczy <alex@golang.org>
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
diff --git a/buildenv/envs.go b/buildenv/envs.go
index fbbd247..677b774 100644
--- a/buildenv/envs.go
+++ b/buildenv/envs.go
@@ -28,26 +28,13 @@
// KubeConfig describes the configuration of a Kubernetes cluster.
type KubeConfig struct {
- // MinNodes is the minimum number of nodes in the Kubernetes cluster.
- // The autoscaler will ensure that at least this many nodes is always
- // running despite any scale-down decision.
- MinNodes int64
-
- // MaxNodes is the maximum number of nodes that the autoscaler can
- // provision in the Kubernetes cluster.
- // If MaxNodes is 0, Kubernetes is not used.
- MaxNodes int64
-
- // MachineType is the GCE machine type to use for the Kubernetes cluster nodes.
- MachineType string
-
// The zone of the cluster. Autopilot clusters have no single zone.
Zone string
// The region of the cluster.
Region string
- // Name is the name of the Kubernetes cluster that will be created.
+ // Name is the name of the Kubernetes cluster that will be used.
Name string
// Namespace is the Kubernetes namespace to use within the cluster.
@@ -100,9 +87,6 @@
// up by name. This field is optional.
StaticIP string
- // MachineType is the GCE machine type to use for the coordinator.
- MachineType string
-
// KubeBuild is the cluster that runs buildlets.
KubeBuild KubeConfig
// KubeServices is the cluster that runs the coordinator and other services.
@@ -254,24 +238,17 @@
IsProd: true,
VMZones: []string{"us-central1-a", "us-central1-b", "us-central1-c", "us-central1-f"},
StaticIP: "104.154.113.235",
- MachineType: "n1-standard-1",
PreferContainersOnCOS: true,
KubeBuild: KubeConfig{
- MinNodes: 1,
- MaxNodes: 1, // auto-scaling disabled
- Zone: "us-central1-f",
- Region: "us-central1",
- Name: "buildlets",
- MachineType: "n1-standard-4", // only used for make.bash due to PreferContainersOnCOS
+ Zone: "us-central1-f",
+ Region: "us-central1",
+ Name: "buildlets",
},
KubeServices: KubeConfig{
- MinNodes: 3,
- MaxNodes: 3,
- Zone: "us-central1-f",
- Region: "us-central1",
- Name: "go",
- MachineType: "n1-standard-4",
- Namespace: "default",
+ Zone: "us-central1-f",
+ Region: "us-central1",
+ Name: "go",
+ Namespace: "default",
},
DashURL: "https://build-staging.golang.org/",
PerfDataURL: "https://perfdata.golang.org",
@@ -293,23 +270,16 @@
IsProd: true,
VMZones: []string{"us-central1-a", "us-central1-b", "us-central1-c", "us-central1-f"},
StaticIP: "107.178.219.46",
- MachineType: "n1-standard-4",
PreferContainersOnCOS: true,
KubeBuild: KubeConfig{
- MinNodes: 2,
- MaxNodes: 2, // auto-scaling disabled
- Zone: "us-central1-f",
- Region: "us-central1",
- Name: "buildlets",
- MachineType: "n1-standard-4", // only used for make.bash due to PreferContainersOnCOS
+ Zone: "us-central1-f",
+ Region: "us-central1",
+ Name: "buildlets",
},
KubeServices: KubeConfig{
- MinNodes: 4,
- MaxNodes: 4,
- Region: "us-central1",
- Name: "services",
- MachineType: "n1-standard-4",
- Namespace: "prod",
+ Region: "us-central1",
+ Name: "services",
+ Namespace: "prod",
},
DashURL: "https://build.golang.org/",
PerfDataURL: "https://perfdata.golang.org",
diff --git a/cmd/gcpinit/README.md b/cmd/gcpinit/README.md
deleted file mode 100644
index f5d884f..0000000
--- a/cmd/gcpinit/README.md
+++ /dev/null
@@ -1,4 +0,0 @@
-# golang.org/x/build/cmd/gcpinit
-
-The `gcpinit` command is a bootstrapping tool to create resources on
-GCP needed by the Go build system.
diff --git a/cmd/gcpinit/gcpinit.go b/cmd/gcpinit/gcpinit.go
deleted file mode 100644
index 9f60852..0000000
--- a/cmd/gcpinit/gcpinit.go
+++ /dev/null
@@ -1,176 +0,0 @@
-// Copyright 2014 The Go Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-package main // import "golang.org/x/build/cmd/gcpinit"
-
-import (
- "bytes"
- "context"
- "crypto/rand"
- "flag"
- "fmt"
- "log"
- "strings"
- "text/template"
- "time"
-
- "golang.org/x/build/buildenv"
- "golang.org/x/build/internal/buildgo"
- dm "google.golang.org/api/deploymentmanager/v2"
-)
-
-var (
- makeClusters = flag.String("make-clusters", "go,buildlets", "comma-separated list of clusters to create. Empty means none.")
-)
-
-// Deployment Manager V2 manifest for creating a Google Container Engine
-// cluster to run buildlets, as well as an autoscaler attached to the
-// cluster's instance group to add capacity based on CPU utilization
-const kubeConfig = `
-resources:
-- name: "{{ .Kube.Name }}"
- type: container.v1.cluster
- properties:
- zone: "{{ .Env.KubeServices.Zone }}"
- cluster:
- initial_node_count: {{ .Kube.MinNodes }}
- network: "default"
- logging_service: "logging.googleapis.com"
- monitoring_service: "none"
- node_config:
- machine_type: "{{ .Kube.MachineType }}"
- oauth_scopes:
- - "https://www.googleapis.com/auth/cloud-platform"
- - "https://www.googleapis.com/auth/userinfo.email"
- master_auth:
- username: "admin"
- password: "{{ .Password }}"`
-
-// Old autoscaler part:
-/*
-`
-- name: autoscaler
- type: compute.v1.autoscaler
- properties:
- zone: "{{ .Zone }}"
- name: "{{ .KubeName }}"
- target: "$(ref.{{ .KubeName }}.instanceGroupUrls[0])"
- autoscalingPolicy:
- minNumReplicas: {{ .KubeMinNodes }}
- maxNumReplicas: {{ .KubeMaxNodes }}
- coolDownPeriodSec: 1200
- cpuUtilization:
- utilizationTarget: .6`
-*/
-
-func main() {
- buildenv.RegisterStagingFlag()
- flag.Parse()
-
- buildenv.CheckUserCredentials()
- buildEnv := buildenv.FromFlags()
- ctx := context.Background()
-
- bgc, err := buildgo.NewClient(ctx, buildEnv)
- if err != nil {
- log.Fatalf("could not create client: %v", err)
- }
-
- for _, c := range []*buildenv.KubeConfig{&buildEnv.KubeBuild, &buildEnv.KubeServices} {
- err := createCluster(bgc, c)
- if err != nil {
- log.Fatalf("Error creating Kubernetes cluster %q: %v", c.Name, err)
- }
- }
-}
-
-type deploymentTemplateData struct {
- Env *buildenv.Environment
- Kube *buildenv.KubeConfig
- Password string
-}
-
-func wantClusterCreate(name string) bool {
- for _, want := range strings.Split(*makeClusters, ",") {
- if want == name {
- return true
- }
- }
- return false
-}
-
-func createCluster(bgc *buildgo.Client, kube *buildenv.KubeConfig) error {
- if !wantClusterCreate(kube.Name) {
- log.Printf("skipping kubernetes cluster %q per flag", kube.Name)
- return nil
- }
- log.Printf("Creating Kubernetes cluster: %v", kube.Name)
- deploySvc, _ := dm.New(bgc.Client)
-
- if kube.MaxNodes == 0 || kube.MinNodes == 0 {
- return fmt.Errorf("MaxNodes/MinNodes values cannot be 0")
- }
-
- tpl, err := template.New("kube").Parse(kubeConfig)
- if err != nil {
- return fmt.Errorf("could not parse Deployment Manager template: %v", err)
- }
-
- var result bytes.Buffer
- err = tpl.Execute(&result, deploymentTemplateData{
- Env: bgc.Env,
- Kube: kube,
- Password: randomPassword(),
- })
- if err != nil {
- return fmt.Errorf("could not execute Deployment Manager template: %v", err)
- }
-
- deployment := &dm.Deployment{
- Name: kube.Name,
- Target: &dm.TargetConfiguration{
- Config: &dm.ConfigFile{
- Content: result.String(),
- },
- },
- }
- op, err := deploySvc.Deployments.Insert(bgc.Env.ProjectName, deployment).Do()
- if err != nil {
- return fmt.Errorf("Failed to create cluster with Deployment Manager: %v", err)
- }
- opName := op.Name
- log.Printf("Created. Waiting on operation %v", opName)
-OpLoop:
- for {
- time.Sleep(2 * time.Second)
- op, err := deploySvc.Operations.Get(bgc.Env.ProjectName, opName).Do()
- if err != nil {
- return fmt.Errorf("Failed to get op %s: %v", opName, err)
- }
- switch op.Status {
- case "PENDING", "RUNNING":
- log.Printf("Waiting on operation %v", opName)
- continue
- case "DONE":
- // If no errors occurred, op.StatusMessage is empty.
- if op.StatusMessage != "" {
- log.Printf("Error: %+v", op.StatusMessage)
- return fmt.Errorf("Failed to create.")
- }
- log.Printf("Success.")
- break OpLoop
- default:
- return fmt.Errorf("Unknown status %q: %+v", op.Status, op)
- }
- }
- return nil
-}
-
-func randomPassword() string {
- buf := make([]byte, 10)
- if _, err := rand.Read(buf); err != nil {
- log.Fatalf("randomPassword: %v", err)
- }
- return fmt.Sprintf("%x", buf)
-}
diff --git a/cmd/gcpinit/gcpinit_test.go b/cmd/gcpinit/gcpinit_test.go
deleted file mode 100644
index c75c647..0000000
--- a/cmd/gcpinit/gcpinit_test.go
+++ /dev/null
@@ -1,56 +0,0 @@
-// Copyright 2016 The Go Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-package main // import "golang.org/x/build/cmd/gcpinit"
-
-import (
- "bytes"
- "testing"
- "text/template"
-
- "golang.org/x/build/buildenv"
-)
-
-func TestDeploymentManagerManifest(t *testing.T) {
- tests := []struct {
- env *buildenv.Environment
- kube *buildenv.KubeConfig
- expected string
- }{
- {buildenv.Staging, &buildenv.Staging.KubeBuild, `
-resources:
-- name: "buildlets"
- type: container.v1.cluster
- properties:
- zone: "us-central1-f"
- cluster:
- initial_node_count: 1
- network: "default"
- logging_service: "logging.googleapis.com"
- monitoring_service: "none"
- node_config:
- machine_type: "n1-standard-4"
- oauth_scopes:
- - "https://www.googleapis.com/auth/cloud-platform"
- - "https://www.googleapis.com/auth/userinfo.email"
- master_auth:
- username: "admin"
- password: ""`},
- }
- for _, test := range tests {
- tpl, err := template.New("kube").Parse(kubeConfig)
- if err != nil {
- t.Errorf("could not parse Deployment Manager template: %v", err)
- }
-
- var result bytes.Buffer
- err = tpl.Execute(&result, deploymentTemplateData{Env: test.env, Kube: test.kube})
- if err != nil {
- t.Errorf("could not execute Deployment Manager template: %v", err)
- }
- if result.String() != test.expected {
- t.Errorf("Rendered template did not match. Rendered: %v\n\n\nExpected: %v\n", result.String(), test.expected)
- }
- }
-}
diff --git a/internal/coordinator/pool/kube.go b/internal/coordinator/pool/kube.go
index c5e2e38..5e336ae 100644
--- a/internal/coordinator/pool/kube.go
+++ b/internal/coordinator/pool/kube.go
@@ -59,8 +59,8 @@
func InitKube(monitorGitMirror MonitorGitMirrorFunc) error {
gce := NewGCEConfiguration()
gceBuildEnv := gce.BuildEnv()
- if gceBuildEnv.KubeBuild.MaxNodes == 0 {
- return errors.New("Kubernetes builders disabled due to KubeBuild.MaxNodes == 0")
+ if gceBuildEnv.KubeBuild.Name == "" {
+ return errors.New("Kubernetes builders disabled due to empty KubeBuild.Name")
}
// projectID was set by InitGCE.