Skip to content

Commit 6c8dc32

Browse files
committed
dashboard, buildenv: label EC2 instances
This change adds a boolean which identified when an instance is an EC2 instance. Various EC2 related variables have been renamed to be more consistent. Updates golang/go#36841 Change-Id: Ief385bf9d41e320ebd7d31bc0108e8053f337afd Reviewed-on: https://go-review.googlesource.com/c/build/+/233801 Run-TryBot: Carlos Amedee <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Alexander Rakoczy <[email protected]>
1 parent 6d6d183 commit 6c8dc32

File tree

4 files changed

+67
-11
lines changed

4 files changed

+67
-11
lines changed

buildenv/envs.go

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -74,17 +74,17 @@ type Environment struct {
7474
// other fields.
7575
ControlZone string
7676

77-
// PreferredAvailabilityZone is the preffered AWS availability zone.
78-
PreferredAvailabilityZone string
77+
// PreferredEC2Zone is the preffered AWS availability zone.
78+
PreferredEC2Zone string
7979

8080
// VMZones are the GCE zones that the VMs will be deployed to. These
8181
// GCE zones will be periodically cleaned by deleting old VMs. The zones
8282
// should all exist within a single region.
8383
VMZones []string
8484

85-
// VMAvailabilityZones are the AWS availability zones that the VMs will be deployed to.
85+
// VMEC2Zones are the AWS availability zones that the VMs will be deployed to.
8686
// The availability zones should all exist within a single region.
87-
VMAvailabilityZones []string
87+
VMEC2Zones []string
8888

8989
// StaticIP is the public, static IP address that will be attached to the
9090
// coordinator instance. The zero value means the address will be looked
@@ -158,14 +158,14 @@ func (e Environment) RandomVMZone() string {
158158
return e.VMZones[rand.Intn(len(e.VMZones))]
159159
}
160160

161-
// RandomAWSVMZone returns a randomly selected zone from the zones in
161+
// RandomEC2VMZone returns a randomly selected zone from the zones in
162162
// VMAvailabilityZones. The PreferredAvailabilityZone value will be
163163
// returned if VMAvailabilityZones is not set.
164-
func (e Environment) RandomAWSVMZone() string {
165-
if len(e.VMAvailabilityZones) == 0 {
166-
return e.PreferredAvailabilityZone
164+
func (e Environment) RandomEC2VMZone() string {
165+
if len(e.VMEC2Zones) == 0 {
166+
return e.PreferredEC2Zone
167167
}
168-
return e.VMAvailabilityZones[rand.Intn(len(e.VMZones))]
168+
return e.VMEC2Zones[rand.Intn(len(e.VMEC2Zones))]
169169
}
170170

171171
// Region returns the GCE region, derived from its zone.
@@ -289,6 +289,7 @@ var Production = &Environment{
289289
IsProd: true,
290290
ControlZone: "us-central1-f",
291291
VMZones: []string{"us-central1-a", "us-central1-b", "us-central1-c", "us-central1-f"},
292+
VMEC2Zones: []string{"us-east-2a", "us-east-2b"},
292293
StaticIP: "107.178.219.46",
293294
MachineType: "n1-standard-4",
294295
PreferContainersOnCOS: true,

buildenv/envs_test.go

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,48 @@ func TestEnvironmentNextZone(t *testing.T) {
5050
}
5151
}
5252

53+
func TestEnvironmentRandomEC2VMZone(t *testing.T) {
54+
testCases := []struct {
55+
name string
56+
env Environment
57+
wantOneOf []string
58+
}{
59+
{
60+
name: "zones-not-set",
61+
env: Environment{
62+
PreferredEC2Zone: "zone-a",
63+
VMEC2Zones: []string{},
64+
},
65+
wantOneOf: []string{"zone-a"},
66+
},
67+
{
68+
name: "zone-and-zones-set",
69+
env: Environment{
70+
PreferredEC2Zone: "zone-a",
71+
VMEC2Zones: []string{"zone-b", "zone-c"},
72+
},
73+
74+
wantOneOf: []string{"zone-b", "zone-c"},
75+
},
76+
{
77+
name: "zones-only-contains-one-entry",
78+
env: Environment{
79+
PreferredEC2Zone: "zone-a",
80+
VMEC2Zones: []string{"zone-b"},
81+
},
82+
wantOneOf: []string{"zone-b"},
83+
},
84+
}
85+
for _, tc := range testCases {
86+
t.Run(tc.name, func(t *testing.T) {
87+
got := tc.env.RandomEC2VMZone()
88+
if !containsString(got, tc.wantOneOf) {
89+
t.Errorf("got=%q; want %v", got, tc.wantOneOf)
90+
}
91+
})
92+
}
93+
}
94+
5395
func containsString(item string, items []string) bool {
5496
for _, s := range items {
5597
if item == s {

buildlet/aws.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ func (c *AWSClient) StartNewVM(ctx context.Context, buildEnv *buildenv.Environme
8585
opts.Description = fmt.Sprintf("Go Builder for %s", hostType)
8686
}
8787
if opts.Zone == "" {
88-
opts.Zone = buildEnv.RandomAWSVMZone()
88+
opts.Zone = buildEnv.RandomEC2VMZone()
8989
}
9090
if opts.DeleteIn == 0 {
9191
opts.DeleteIn = 30 * time.Minute

dashboard/builders.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -552,9 +552,10 @@ var Hosts = map[string]*HostConfig{
552552
SSHUsername: "root",
553553
},
554554
"host-linux-arm64-aws": &HostConfig{
555-
Notes: "Debian Buster, EC2 arm64 instance. See x/build/env/linux-arm64/arm",
555+
Notes: "Debian Buster, EC2 arm64 instance. See x/build/env/linux-arm64/aws",
556556
VMImage: "ami-0454a5239a73a9e81",
557557
machineType: "a1.xlarge",
558+
isEC2: true,
558559
env: []string{"GOROOT_BOOTSTRAP=/usr/local/go-bootstrap"},
559560
buildletURLTmpl: "http://storage.googleapis.com/$BUCKET/buildlet.linux-amd64",
560561
SSHUsername: "admin",
@@ -713,6 +714,9 @@ type HostConfig struct {
713714
RegularDisk bool // if true, use spinning disk instead of SSD
714715
MinCPUPlatform string // optional; https://cloud.google.com/compute/docs/instances/specify-min-cpu-platform
715716

717+
// EC2 options
718+
isEC2 bool // if true, the instance is configured to run on EC2
719+
716720
// ReverseOptions:
717721
ExpectNum int // expected number of reverse buildlets of this type
718722
HermeticReverse bool // whether reverse buildlet has fresh env per conn
@@ -1296,6 +1300,11 @@ func (c *HostConfig) MachineType() string {
12961300
return "n1-highcpu-2"
12971301
}
12981302

1303+
// IsEC2 returns true if the machine type is an EC2 arm64 type.
1304+
func (c *HostConfig) IsEC2() bool {
1305+
return c.isEC2
1306+
}
1307+
12991308
// ShortOwner returns a short human-readable owner.
13001309
func (c BuildConfig) ShortOwner() string {
13011310
owner := c.HostConfig().Owner
@@ -1316,6 +1325,8 @@ func (c *HostConfig) PoolName() string {
13161325
switch {
13171326
case c.IsReverse:
13181327
return "Reverse (dedicated machine/VM)"
1328+
case c.IsEC2():
1329+
return "EC2 VM"
13191330
case c.IsVM():
13201331
return "GCE VM"
13211332
case c.IsContainer():
@@ -1349,6 +1360,8 @@ func (c *HostConfig) IsHermetic() bool {
13491360
switch {
13501361
case c.IsReverse:
13511362
return c.HermeticReverse
1363+
case c.IsEC2():
1364+
return true
13521365
case c.IsVM():
13531366
return true
13541367
case c.IsContainer():

0 commit comments

Comments
 (0)