Skip to content

Commit

Permalink
cmd/gomote: add -new-group flag to create
Browse files Browse the repository at this point in the history
This flag creates a new group for the newly-created instances.

For golang/go#53956.

Change-Id: Ib65a6391a554dbeb1f6f0e44c286ad5b0d221757
Reviewed-on: https://go-review.googlesource.com/c/build/+/418302
Run-TryBot: Michael Knyszek <mknyszek@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Auto-Submit: Michael Knyszek <mknyszek@google.com>
Reviewed-by: Carlos Amedee <carlos@golang.org>
  • Loading branch information
mknyszek authored and gopherbot committed Nov 18, 2022
1 parent d44332d commit 1543103
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 15 deletions.
24 changes: 17 additions & 7 deletions cmd/gomote/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,8 @@ func create(args []string) error {
fs.IntVar(&count, "count", 1, "number of instances to create")
var setup bool
fs.BoolVar(&setup, "setup", false, "set up the instance by pushing GOROOT and building the Go toolchain")
var newGroup string
fs.StringVar(&newGroup, "new-group", "", "also create a new group and add the new instances to it")

fs.Parse(args)
if fs.NArg() != 1 {
Expand All @@ -180,7 +182,15 @@ func create(args []string) error {
}
}

var activeGroupMu sync.Mutex
var groupMu sync.Mutex
group := activeGroup
if newGroup != "" {
group, err = doCreateGroup(newGroup)
if err != nil {
return err
}
}

eg, ctx := errgroup.WithContext(context.Background())
client := gomoteServerClient(ctx)
for i := 0; i < count; i++ {
Expand All @@ -207,10 +217,10 @@ func create(args []string) error {
}
}
fmt.Println(inst)
if activeGroup != nil {
activeGroupMu.Lock()
activeGroup.Instances = append(activeGroup.Instances, inst)
activeGroupMu.Unlock()
if group != nil {
groupMu.Lock()
group.Instances = append(group.Instances, inst)
groupMu.Unlock()
}
if !setup {
return nil
Expand Down Expand Up @@ -239,8 +249,8 @@ func create(args []string) error {
if err := eg.Wait(); err != nil {
return err
}
if activeGroup != nil {
return storeGroup(activeGroup)
if group != nil {
return storeGroup(group)
}
return nil
}
16 changes: 8 additions & 8 deletions cmd/gomote/group.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,16 @@ func createGroup(args []string) error {
if len(args) != 1 {
usage()
}
name := args[0]
_, err := doCreateGroup(args[0])
return err
}

func doCreateGroup(name string) (*groupData, error) {
if _, err := loadGroup(name); err == nil {
return fmt.Errorf("group %q already exists", name)
return nil, fmt.Errorf("group %q already exists", name)
}
if err := storeGroup(&groupData{
Name: name,
}); err != nil {
return err
}
return nil
g := &groupData{Name: name}
return g, storeGroup(g)
}

func destroyGroup(args []string) error {
Expand Down

0 comments on commit 1543103

Please sign in to comment.