Skip to content

Commit

Permalink
internal/pool: create a common buildlet naming function
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
cagedmantis committed Jul 20, 2020
1 parent 3d574e5 commit d0191c8
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
3 changes: 1 addition & 2 deletions internal/coordinator/pool/gce.go
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ func (p *GCEBuildlet) GetBuildlet(ctx context.Context, hostType string, lg Logge
deleteIn = deleteTimeout
}

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

Expand Down Expand Up @@ -724,7 +724,6 @@ func (p *GCEBuildlet) cleanZoneVMs(zone string) error {
log.Printf("deleting VM %q in zone %q; %s ...", inst.Name, zone, deleteReason)
deleteVM(zone, inst.Name)
}

}
return nil
}
Expand Down
2 changes: 1 addition & 1 deletion internal/coordinator/pool/kube.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ func (p *kubeBuildletPool) GetBuildlet(ctx context.Context, hostType string, lg
deleteIn = podDeleteTimeout
}

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

// Get an estimate for when the pod will be started/running and set
// the context timeout based on that
Expand Down
5 changes: 5 additions & 0 deletions internal/coordinator/pool/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"fmt"
"log"
"math/rand"
"strings"
"time"

"golang.org/x/build/buildlet"
Expand Down Expand Up @@ -56,3 +57,7 @@ func friendlyDuration(d time.Duration) string {
d2 := ((d + 50*time.Microsecond) / (100 * time.Microsecond)) * (100 * time.Microsecond)
return d2.String()
}

func instanceName(hostType string, length int) string {
return fmt.Sprintf("buildlet-%s-rn%s", strings.TrimPrefix(hostType, "host-"), randHex(length))
}

0 comments on commit d0191c8

Please sign in to comment.