Skip to content

Commit

Permalink
cmd/gomote: list swarming builders on create
Browse files Browse the repository at this point in the history
If a create is issued without a gomote instance type, the gomote
client will query the gomote server for all available instance types.
This adds the ability to query for swarming builder types.

Updates golang/go#61773
For golang/go#61772

Change-Id: If8d9a2d6b0aa509aafd199ec140659cb7d664308
Reviewed-on: https://go-review.googlesource.com/c/build/+/518799
Reviewed-by: Dmitri Shuralyov <[email protected]>
TryBot-Result: Gopher Robot <[email protected]>
Reviewed-by: Dmitri Shuralyov <[email protected]>
Run-TryBot: Carlos Amedee <[email protected]>
LUCI-TryBot-Result: Go LUCI <[email protected]>
  • Loading branch information
cagedmantis committed Aug 14, 2023
1 parent 8e06b07 commit 27b08b3
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 9 deletions.
40 changes: 31 additions & 9 deletions cmd/gomote/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,16 @@ func builders() (bt []builderType) {
return
}

func swarmingBuilders() ([]string, error) {
ctx, _ := context.WithTimeout(context.Background(), 5*time.Second)
client := gomoteServerClient(ctx)
resp, err := client.ListSwarmingBuilders(ctx, &protos.ListSwarmingBuildersRequest{})
if err != nil {
return nil, fmt.Errorf("unable to retrieve swarming builders: %s", err)
}
return resp.Builders, nil
}

func create(args []string) error {
fs := flag.NewFlagSet("create", flag.ContinueOnError)

Expand All @@ -91,18 +101,30 @@ func create(args []string) error {
fmt.Fprintln(os.Stderr, "added to that group.")
fs.PrintDefaults()
fmt.Fprintln(os.Stderr, "\nValid types:")
for _, bt := range builders() {
var warn string
if bt.IsReverse {
if bt.ExpectNum > 0 {
warn = fmt.Sprintf(" [limited capacity: %d machines]", bt.ExpectNum)
} else {
warn = " [limited capacity]"
if luciEnabled() {
swarmingBuilders, err := swarmingBuilders()
if err != nil {
fmt.Fprintf(os.Stderr, " %s\n", err)
} else {
for _, builder := range swarmingBuilders {
fmt.Fprintf(os.Stderr, " * %s\n", builder)
}
}
os.Exit(1)
} else {
for _, bt := range builders() {
var warn string
if bt.IsReverse {
if bt.ExpectNum > 0 {
warn = fmt.Sprintf(" [limited capacity: %d machines]", bt.ExpectNum)
} else {
warn = " [limited capacity]"
}
}
fmt.Fprintf(os.Stderr, " * %s%s\n", bt.Name, warn)
}
fmt.Fprintf(os.Stderr, " * %s%s\n", bt.Name, warn)
os.Exit(1)
}
os.Exit(1)
}
var status bool
fs.BoolVar(&status, "status", true, "print regular status updates while waiting")
Expand Down
6 changes: 6 additions & 0 deletions cmd/gomote/gomote.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ import (
"fmt"
"os"
"sort"
"strconv"

"golang.org/x/build/buildenv"
"golang.org/x/build/buildlet"
Expand Down Expand Up @@ -296,3 +297,8 @@ func instanceDoesNotExist(err error) bool {
}
return false
}

func luciEnabled() bool {
on, _ := strconv.ParseBool(os.Getenv("GOMOTELUCI"))
return on
}

0 comments on commit 27b08b3

Please sign in to comment.