Skip to content

Commit b405858

Browse files
committed
cmd/coordinator: restore partial support for -mode=dev
Set gceMode earlier in InitGCE. Its value is used by some of the code that runs inside InitGCE. Don't try to run gcePool.pollQuotaLoop in dev mode. Make the code more clear and consistent about this and createBasepinDisks calls. Merge oAuthHTTPClient into the "Initialized by InitGCE" var block above. Remove initGCECalled, it has become unused. For golang/go#34744. For golang/go#38337. Change-Id: Ic47870fa9aed0eded0cfdf14e18e63c1acda4554 Reviewed-on: https://go-review.googlesource.com/c/build/+/244398 Run-TryBot: Dmitri Shuralyov <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Carlos Amedee <[email protected]> Reviewed-by: Alexander Rakoczy <[email protected]>
1 parent 70303fc commit b405858

File tree

2 files changed

+20
-36
lines changed

2 files changed

+20
-36
lines changed

internal/coordinator/pool/gce.go

Lines changed: 19 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ func gceAPIGate() {
6565
// is a GCE remote buildlet.
6666
type IsGCERemoteBuildletFunc func(instanceName string) bool
6767

68-
// Initialized by initGCE:
68+
// Initialized by InitGCE:
6969
// TODO(http://golang.org/issue/38337): These should be moved into a struct as
7070
// part of the effort to reduce package level variables.
7171
var (
@@ -74,40 +74,37 @@ var (
7474
// dsClient is a datastore client for the build project (symbolic-datum-552), where build progress is stored.
7575
dsClient *datastore.Client
7676
// goDSClient is a datastore client for golang-org, where build status is stored.
77-
goDSClient *datastore.Client
78-
computeService *compute.Service
79-
gcpCreds *google.Credentials
80-
errTryDeps error // non-nil if try bots are disabled
81-
gerritClient *gerrit.Client
82-
storageClient *storage.Client
83-
metricsClient *monapi.MetricClient
84-
inStaging bool // are we running in the staging project? (named -dev)
85-
errorsClient *errorreporting.Client // Stackdriver errors client
86-
gkeNodeIP string
77+
goDSClient *datastore.Client
78+
// oAuthHTTPClient is the OAuth2 HTTP client used to make API calls to Google Cloud APIs.
79+
oAuthHTTPClient *http.Client
80+
computeService *compute.Service
81+
gcpCreds *google.Credentials
82+
errTryDeps error // non-nil if try bots are disabled
83+
gerritClient *gerrit.Client
84+
storageClient *storage.Client
85+
metricsClient *monapi.MetricClient
86+
inStaging bool // are we running in the staging project? (named -dev)
87+
errorsClient *errorreporting.Client // Stackdriver errors client
88+
gkeNodeIP string
8789

8890
// values created due to seperating the buildlet pools into a seperate package
8991
gceMode string
9092
deleteTimeout time.Duration
9193
testFiles map[string]string
9294
basePinErr *atomic.Value
9395
isGCERemoteBuildlet IsGCERemoteBuildletFunc
94-
95-
initGCECalled bool
9696
)
9797

98-
// oAuthHTTPClient is the OAuth2 HTTP client used to make API calls to Google Cloud APIs.
99-
// It is initialized by initGCE.
100-
var oAuthHTTPClient *http.Client
101-
10298
// InitGCE initializes the GCE buildlet pool.
10399
func InitGCE(sc *secret.Client, vmDeleteTimeout time.Duration, tFiles map[string]string, basePin *atomic.Value, fn IsGCERemoteBuildletFunc, buildEnvName, mode string) error {
104-
initGCECalled = true
100+
gceMode = mode
105101
deleteTimeout = vmDeleteTimeout
106102
testFiles = tFiles
107103
basePinErr = basePin
108104
isGCERemoteBuildlet = fn
109-
var err error
105+
110106
ctx := context.Background()
107+
var err error
111108

112109
// If the coordinator is running on a GCE instance and a
113110
// buildEnv was not specified with the env flag, set the
@@ -214,14 +211,12 @@ func InitGCE(sc *secret.Client, vmDeleteTimeout time.Duration, tFiles map[string
214211
log.Printf("TryBot builders enabled.")
215212
}
216213

217-
if mode != "dev" {
214+
if mode != "dev" && metadata.OnGCE() && (buildEnv == buildenv.Production || buildEnv == buildenv.Staging) {
218215
go syncBuildStatsLoop(buildEnv)
216+
go gcePool.pollQuotaLoop()
217+
go createBasepinDisks(ctx)
219218
}
220219

221-
gceMode = mode
222-
223-
go gcePool.pollQuotaLoop()
224-
go createBasepinDisks(context.Background())
225220
return nil
226221
}
227222

@@ -360,14 +355,6 @@ type GCEBuildlet struct {
360355
}
361356

362357
func (p *GCEBuildlet) pollQuotaLoop() {
363-
if computeService == nil {
364-
log.Printf("pollQuotaLoop: no GCE access; not checking quota.")
365-
return
366-
}
367-
if buildEnv.ProjectName == "" {
368-
log.Printf("pollQuotaLoop: no GCE project name configured; not checking quota.")
369-
return
370-
}
371358
for {
372359
p.pollQuota()
373360
time.Sleep(5 * time.Second)
@@ -827,9 +814,6 @@ func syncBuildStatsLoop(env *buildenv.Environment) {
827814
// Other than a list call, this a no-op unless new VM images were
828815
// added or updated recently.
829816
func createBasepinDisks(ctx context.Context) {
830-
if !metadata.OnGCE() || (buildEnv != buildenv.Production && buildEnv != buildenv.Staging) {
831-
return
832-
}
833817
for {
834818
t0 := time.Now()
835819
bgc, err := buildgo.NewClient(ctx, buildEnv)

internal/coordinator/pool/kube.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ func InitKube(monitorGitMirror MonitorGitMirrorFunc) error {
6262
return errors.New("Kubernetes builders disabled due to KubeBuild.MaxNodes == 0")
6363
}
6464

65-
// projectID was set by initGCE
65+
// projectID was set by InitGCE.
6666
registryPrefix += "/" + gceBuildEnv.ProjectName
6767
if !hasCloudPlatformScope() {
6868
return errors.New("coordinator not running with access to the Cloud Platform scope.")

0 commit comments

Comments
 (0)