Skip to content

Commit

Permalink
cmd/coordinator: restore partial support for -mode=dev
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
dmitshur committed Jul 24, 2020
1 parent 70303fc commit b405858
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 36 deletions.
54 changes: 19 additions & 35 deletions internal/coordinator/pool/gce.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func gceAPIGate() {
// is a GCE remote buildlet.
type IsGCERemoteBuildletFunc func(instanceName string) bool

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

// values created due to seperating the buildlet pools into a seperate package
gceMode string
deleteTimeout time.Duration
testFiles map[string]string
basePinErr *atomic.Value
isGCERemoteBuildlet IsGCERemoteBuildletFunc

initGCECalled bool
)

// oAuthHTTPClient is the OAuth2 HTTP client used to make API calls to Google Cloud APIs.
// It is initialized by initGCE.
var oAuthHTTPClient *http.Client

// InitGCE initializes the GCE buildlet pool.
func InitGCE(sc *secret.Client, vmDeleteTimeout time.Duration, tFiles map[string]string, basePin *atomic.Value, fn IsGCERemoteBuildletFunc, buildEnvName, mode string) error {
initGCECalled = true
gceMode = mode
deleteTimeout = vmDeleteTimeout
testFiles = tFiles
basePinErr = basePin
isGCERemoteBuildlet = fn
var err error

ctx := context.Background()
var err error

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

if mode != "dev" {
if mode != "dev" && metadata.OnGCE() && (buildEnv == buildenv.Production || buildEnv == buildenv.Staging) {
go syncBuildStatsLoop(buildEnv)
go gcePool.pollQuotaLoop()
go createBasepinDisks(ctx)
}

gceMode = mode

go gcePool.pollQuotaLoop()
go createBasepinDisks(context.Background())
return nil
}

Expand Down Expand Up @@ -360,14 +355,6 @@ type GCEBuildlet struct {
}

func (p *GCEBuildlet) pollQuotaLoop() {
if computeService == nil {
log.Printf("pollQuotaLoop: no GCE access; not checking quota.")
return
}
if buildEnv.ProjectName == "" {
log.Printf("pollQuotaLoop: no GCE project name configured; not checking quota.")
return
}
for {
p.pollQuota()
time.Sleep(5 * time.Second)
Expand Down Expand Up @@ -827,9 +814,6 @@ func syncBuildStatsLoop(env *buildenv.Environment) {
// Other than a list call, this a no-op unless new VM images were
// added or updated recently.
func createBasepinDisks(ctx context.Context) {
if !metadata.OnGCE() || (buildEnv != buildenv.Production && buildEnv != buildenv.Staging) {
return
}
for {
t0 := time.Now()
bgc, err := buildgo.NewClient(ctx, buildEnv)
Expand Down
2 changes: 1 addition & 1 deletion internal/coordinator/pool/kube.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func InitKube(monitorGitMirror MonitorGitMirrorFunc) error {
return errors.New("Kubernetes builders disabled due to KubeBuild.MaxNodes == 0")
}

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

0 comments on commit b405858

Please sign in to comment.