Skip to content

Commit d0191c8

Browse files
committed
internal/pool: create a common buildlet naming function
The logic for naming buildlets appears in each particular buildlet pool implementation. This change creates a function which contains the buildlet naming logic. This is being added before the addition of a new buildlet pool. Updates golang/go#36841 Updates golang/go#38337 Change-Id: I8c03f9b513efde14414bcc6d823f3cf1a59c8f70 Reviewed-on: https://go-review.googlesource.com/c/build/+/243337 Run-TryBot: Carlos Amedee <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Andrew Bonventre <[email protected]> Reviewed-by: Alexander Rakoczy <[email protected]>
1 parent 3d574e5 commit d0191c8

File tree

3 files changed

+7
-3
lines changed

3 files changed

+7
-3
lines changed

internal/coordinator/pool/gce.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,7 @@ func (p *GCEBuildlet) GetBuildlet(ctx context.Context, hostType string, lg Logge
422422
deleteIn = deleteTimeout
423423
}
424424

425-
instName := "buildlet-" + strings.TrimPrefix(hostType, "host-") + "-rn" + randHex(7)
425+
instName := instanceName(hostType, 7)
426426
instName = strings.Replace(instName, "_", "-", -1) // Issue 22905; can't use underscores in GCE VMs
427427
p.setInstanceUsed(instName, true)
428428

@@ -724,7 +724,6 @@ func (p *GCEBuildlet) cleanZoneVMs(zone string) error {
724724
log.Printf("deleting VM %q in zone %q; %s ...", inst.Name, zone, deleteReason)
725725
deleteVM(zone, inst.Name)
726726
}
727-
728727
}
729728
return nil
730729
}

internal/coordinator/pool/kube.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ func (p *kubeBuildletPool) GetBuildlet(ctx context.Context, hostType string, lg
261261
deleteIn = podDeleteTimeout
262262
}
263263

264-
podName := "buildlet-" + strings.TrimPrefix(hostType, "host-") + "-rn" + randHex(7)
264+
podName := instanceName(hostType, 7)
265265

266266
// Get an estimate for when the pod will be started/running and set
267267
// the context timeout based on that

internal/coordinator/pool/pool.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"fmt"
1010
"log"
1111
"math/rand"
12+
"strings"
1213
"time"
1314

1415
"golang.org/x/build/buildlet"
@@ -56,3 +57,7 @@ func friendlyDuration(d time.Duration) string {
5657
d2 := ((d + 50*time.Microsecond) / (100 * time.Microsecond)) * (100 * time.Microsecond)
5758
return d2.String()
5859
}
60+
61+
func instanceName(hostType string, length int) string {
62+
return fmt.Sprintf("buildlet-%s-rn%s", strings.TrimPrefix(hostType, "host-"), randHex(length))
63+
}

0 commit comments

Comments
 (0)