Skip to content

Commit 148ff27

Browse files
committed
cmd/coordinator: enable EC2 buildlet pool
This change enables the EC2 buildlet pools. Updates golang/go#38337 Fixes golang/go#36841 Change-Id: I3f9384c039dce8fab529650bc6acdbeda40f5819 Reviewed-on: https://go-review.googlesource.com/c/build/+/247908 Run-TryBot: Carlos Amedee <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Alexander Rakoczy <[email protected]> Reviewed-by: Dmitri Shuralyov <[email protected]>
1 parent 3dadacc commit 148ff27

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

cmd/coordinator/coordinator.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ import (
6060
"golang.org/x/build/gerrit"
6161
"golang.org/x/build/internal/buildgo"
6262
"golang.org/x/build/internal/buildstats"
63+
"golang.org/x/build/internal/cloud"
6364
"golang.org/x/build/internal/coordinator/pool"
6465
"golang.org/x/build/internal/secret"
6566
"golang.org/x/build/internal/singleflight"
@@ -115,6 +116,7 @@ var (
115116
mode = flag.String("mode", "", "Valid modes are 'dev', 'prod', or '' for auto-detect. dev means localhost development, not be confused with staging on go-dashboard-dev, which is still the 'prod' mode.")
116117
buildEnvName = flag.String("env", "", "The build environment configuration to use. Not required if running on GCE.")
117118
devEnableGCE = flag.Bool("dev_gce", false, "Whether or not to enable the GCE pool when in dev mode. The pool is enabled by default in prod mode.")
119+
devEnableEC2 = flag.Bool("dev_ec2", false, "Whether or not to enable the EC2 pool when in dev mode. The pool is enabled by default in prod mode.")
118120
shouldRunBench = flag.Bool("run_bench", false, "Whether or not to run benchmarks on trybot commits. Override by GCE project attribute 'farmer-run-bench'.")
119121
perfServer = flag.String("perf_server", "", "Upload benchmark results to `server`. Overrides buildenv default for testing.")
120122
)
@@ -296,6 +298,13 @@ func main() {
296298
log.Printf("Kube support disabled due to error initializing Kubernetes: %v", err)
297299
}
298300

301+
if *mode == "prod" || (*mode == "dev" && *devEnableEC2) {
302+
// TODO(golang.org/issues/38337) the coordinator will use a package scoped pool
303+
// until the coordinator is refactored to not require them.
304+
ec2Pool := mustCreateEC2BuildletPool(sc)
305+
defer ec2Pool.Close()
306+
}
307+
299308
go updateInstanceRecord()
300309

301310
switch *mode {
@@ -1634,6 +1643,8 @@ func poolForConf(conf *dashboard.HostConfig) pool.Buildlet {
16341643
panic("nil conf")
16351644
}
16361645
switch {
1646+
case conf.IsEC2():
1647+
return pool.EC2BuildetPool()
16371648
case conf.IsVM():
16381649
return pool.NewGCEConfiguration().BuildletPool()
16391650
case conf.IsContainer():
@@ -1751,6 +1762,9 @@ func (st *buildStatus) expectedBuildletStartDuration() time.Duration {
17511762
return 2 * time.Minute
17521763
}
17531764
return time.Minute
1765+
case *pool.EC2Buildlet:
1766+
// lack of historical data. 2 * time.Minute is a safe overestimate
1767+
return 2 * time.Minute
17541768
case *pool.ReverseBuildletPool:
17551769
goos, arch := st.conf.GOOS(), st.conf.GOARCH()
17561770
if goos == "darwin" {
@@ -4048,3 +4062,26 @@ func mustCreateSecretClientOnGCE() *secret.Client {
40484062
}
40494063
return client
40504064
}
4065+
4066+
func mustCreateEC2BuildletPool(sc *secret.Client) *pool.EC2Buildlet {
4067+
awsKeyID, err := sc.Retrieve(context.Background(), secret.NameAWSKeyID)
4068+
if err != nil {
4069+
log.Fatalf("unable to retrieve secret %q: %s", secret.NameAWSKeyID, err)
4070+
}
4071+
4072+
awsAccessKey, err := sc.Retrieve(context.Background(), secret.NameAWSAccessKey)
4073+
if err != nil {
4074+
log.Fatalf("unable to retrieve secret %q: %s", secret.NameAWSAccessKey, err)
4075+
}
4076+
4077+
awsClient, err := cloud.NewAWSClient(buildenv.Production.AWSRegion, awsKeyID, awsAccessKey)
4078+
if err != nil {
4079+
log.Fatalf("unable to create AWS client: %s", err)
4080+
}
4081+
4082+
ec2Pool, err := pool.NewEC2Buildlet(awsClient, buildenv.Production, dashboard.Hosts, isGCERemoteBuildlet)
4083+
if err != nil {
4084+
log.Fatalf("unable to create EC2 buildlet pool: %s", err)
4085+
}
4086+
return ec2Pool
4087+
}

cmd/coordinator/status.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -659,6 +659,11 @@ func handleStatus(w http.ResponseWriter, r *http.Request) {
659659
data.GCEPoolStatus = template.HTML(buf.String())
660660
buf.Reset()
661661

662+
buf.Reset()
663+
pool.EC2BuildetPool().WriteHTMLStatus(&buf)
664+
data.EC2PoolStatus = template.HTML(buf.String())
665+
buf.Reset()
666+
662667
pool.KubePool().WriteHTMLStatus(&buf)
663668
data.KubePoolStatus = template.HTML(buf.String())
664669
buf.Reset()
@@ -727,6 +732,7 @@ type statusData struct {
727732
TrybotsErr string
728733
Trybots template.HTML
729734
GCEPoolStatus template.HTML // TODO: embed template
735+
EC2PoolStatus template.HTML // TODO: embed template
730736
KubePoolStatus template.HTML // TODO: embed template
731737
ReversePoolStatus template.HTML // TODO: embed template
732738
RemoteBuildlets template.HTML
@@ -790,6 +796,7 @@ var statusTmpl = template.Must(template.New("status").Parse(`
790796
<h2 id=pools>Buildlet pools <a href='#pools'>¶</a></h2>
791797
<ul>
792798
<li>{{.GCEPoolStatus}}</li>
799+
<li>{{.EC2PoolStatus}}</li>
793800
<li>{{.KubePoolStatus}}</li>
794801
<li>{{.ReversePoolStatus}}</li>
795802
</ul>

0 commit comments

Comments
 (0)