@@ -65,7 +65,7 @@ func gceAPIGate() {
65
65
// is a GCE remote buildlet.
66
66
type IsGCERemoteBuildletFunc func (instanceName string ) bool
67
67
68
- // Initialized by initGCE :
68
+ // Initialized by InitGCE :
69
69
// TODO(http://golang.org/issue/38337): These should be moved into a struct as
70
70
// part of the effort to reduce package level variables.
71
71
var (
@@ -74,40 +74,37 @@ var (
74
74
// dsClient is a datastore client for the build project (symbolic-datum-552), where build progress is stored.
75
75
dsClient * datastore.Client
76
76
// 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
87
89
88
90
// values created due to seperating the buildlet pools into a seperate package
89
91
gceMode string
90
92
deleteTimeout time.Duration
91
93
testFiles map [string ]string
92
94
basePinErr * atomic.Value
93
95
isGCERemoteBuildlet IsGCERemoteBuildletFunc
94
-
95
- initGCECalled bool
96
96
)
97
97
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
-
102
98
// InitGCE initializes the GCE buildlet pool.
103
99
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
105
101
deleteTimeout = vmDeleteTimeout
106
102
testFiles = tFiles
107
103
basePinErr = basePin
108
104
isGCERemoteBuildlet = fn
109
- var err error
105
+
110
106
ctx := context .Background ()
107
+ var err error
111
108
112
109
// If the coordinator is running on a GCE instance and a
113
110
// 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
214
211
log .Printf ("TryBot builders enabled." )
215
212
}
216
213
217
- if mode != "dev" {
214
+ if mode != "dev" && metadata . OnGCE () && ( buildEnv == buildenv . Production || buildEnv == buildenv . Staging ) {
218
215
go syncBuildStatsLoop (buildEnv )
216
+ go gcePool .pollQuotaLoop ()
217
+ go createBasepinDisks (ctx )
219
218
}
220
219
221
- gceMode = mode
222
-
223
- go gcePool .pollQuotaLoop ()
224
- go createBasepinDisks (context .Background ())
225
220
return nil
226
221
}
227
222
@@ -360,14 +355,6 @@ type GCEBuildlet struct {
360
355
}
361
356
362
357
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
- }
371
358
for {
372
359
p .pollQuota ()
373
360
time .Sleep (5 * time .Second )
@@ -827,9 +814,6 @@ func syncBuildStatsLoop(env *buildenv.Environment) {
827
814
// Other than a list call, this a no-op unless new VM images were
828
815
// added or updated recently.
829
816
func createBasepinDisks (ctx context.Context ) {
830
- if ! metadata .OnGCE () || (buildEnv != buildenv .Production && buildEnv != buildenv .Staging ) {
831
- return
832
- }
833
817
for {
834
818
t0 := time .Now ()
835
819
bgc , err := buildgo .NewClient (ctx , buildEnv )
0 commit comments