Skip to content

Commit cc98a76

Browse files
committed
internal/coordinator/pool: check if EC2 instance is a buildlet
Before destroying an untracked EC2 instance, verify that it is a buildlet. Non buildlets will be destroyed manually as they are most likely instances created while an operator is debugging a problem. For golang/go#36841 Change-Id: Id0f65192ce4e72f9ecc495dd3e94750724091b51 Reviewed-on: https://go-review.googlesource.com/c/build/+/249121 Run-TryBot: Carlos Amedee <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Dmitri Shuralyov <[email protected]>
1 parent 7c9f64d commit cc98a76

File tree

3 files changed

+16
-8
lines changed

3 files changed

+16
-8
lines changed

internal/coordinator/pool/ec2.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,12 @@ func (eb *EC2Buildlet) destroyUntrackedInstances() {
341341
}
342342
deleteInsts := make([]string, 0, len(insts))
343343
for _, inst := range insts {
344+
if !isBuildlet(inst.Name) {
345+
// Non-buildlets have not been created by the EC2 buildlet pool. Their lifecycle
346+
// should not be managed by the pool.
347+
log.Printf("destroyUntrackedInstances: skipping non-buildlet %q", inst.Name)
348+
continue
349+
}
344350
if eb.isRemoteBuildlet(inst.Name) {
345351
// Remote buildlets have their own expiration mechanism that respects active SSH sessions.
346352
log.Printf("destroyUntrackedInstances: skipping remote buildlet %q", inst.Name)

internal/coordinator/pool/ec2_test.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -512,11 +512,11 @@ func TestEC2BuildletRetrieveAndSetInstanceTypes(t *testing.T) {
512512

513513
func TestEC2BuildeletDestroyUntrackedInstances(t *testing.T) {
514514
awsC := cloud.NewFakeAWSClient()
515-
create := func() *cloud.Instance {
515+
create := func(name string) *cloud.Instance {
516516
inst, err := awsC.CreateInstance(context.Background(), &cloud.EC2VMConfiguration{
517517
Description: "test instance",
518518
ImageID: "image-x",
519-
Name: instanceName("host-test-type", 10),
519+
Name: name,
520520
SSHKeyID: "key-14",
521521
Tags: map[string]string{},
522522
Type: "type-x",
@@ -529,10 +529,11 @@ func TestEC2BuildeletDestroyUntrackedInstances(t *testing.T) {
529529
}
530530
// create untracked instances
531531
for it := 0; it < 10; it++ {
532-
_ = create()
532+
_ = create(instanceName("host-test-type", 10))
533533
}
534-
wantTrackedInst := create()
535-
wantRemoteInst := create()
534+
wantTrackedInst := create(instanceName("host-test-type", 10))
535+
wantRemoteInst := create(instanceName("host-test-type", 10))
536+
_ = create("debug-tiger-host-14") // non buildlet instance
536537

537538
pool := &EC2Buildlet{
538539
awsClient: awsC,
@@ -556,9 +557,10 @@ func TestEC2BuildeletDestroyUntrackedInstances(t *testing.T) {
556557
},
557558
}
558559
pool.destroyUntrackedInstances()
560+
wantInstCount := 3
559561
gotInsts, err := awsC.RunningInstances(context.Background())
560-
if err != nil || len(gotInsts) != 2 {
561-
t.Errorf("awsClient.RunningInstances(ctx) = %+v, %s; want single inst and no error", gotInsts, err)
562+
if err != nil || len(gotInsts) != wantInstCount {
563+
t.Errorf("awsClient.RunningInstances(ctx) = %+v, %s; want %d instances and no error", gotInsts, err, wantInstCount)
562564
}
563565
}
564566

internal/coordinator/pool/gce.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -683,7 +683,7 @@ func (p *GCEBuildlet) cleanZoneVMs(zone string) error {
683683
}
684684
}
685685
}
686-
isBuildlet := strings.HasPrefix(inst.Name, "buildlet-")
686+
isBuildlet := isBuildlet(inst.Name)
687687

688688
if isBuildlet && !sawDeleteAt && !p.instanceUsed(inst.Name) {
689689
createdAt, _ := time.Parse(time.RFC3339Nano, inst.CreationTimestamp)

0 commit comments

Comments
 (0)