diff --git a/commands/create.go b/commands/create.go index 63ae4de0..657d6618 100644 --- a/commands/create.go +++ b/commands/create.go @@ -29,7 +29,7 @@ func runCreate(dockerCli command.Cli, in createOptions, args []string) error { ctx := appcontext.Context() if in.name == "default" { - return errors.Errorf("default is a reserved name and can't be used to identify builder instance") + return errors.Errorf("default is a reserved name and cannot be used to identify builder instance") } if in.actionLeave { @@ -91,6 +91,12 @@ func runCreate(dockerCli command.Cli, in createOptions, args []string) error { } } + if ng != nil { + if in.nodeName == "" && !in.actionAppend { + return errors.Errorf("existing instance for %s but no append mode, specify --node to make changes for existing instances", name) + } + } + if ng == nil { ng = &store.NodeGroup{ Name: name, diff --git a/commands/inspect.go b/commands/inspect.go index 3707b943..e21fa01e 100644 --- a/commands/inspect.go +++ b/commands/inspect.go @@ -77,11 +77,15 @@ func runInspect(dockerCli command.Cli, in inspectOptions, args []string) error { err = loadNodeGroupData(timeoutCtx, dockerCli, ngi) if in.bootstrap { - if err := boot(ctx, ngi); err != nil { + var ok bool + ok, err = boot(ctx, ngi) + if err != nil { return err } - ngi = &nginfo{ng: ng} - err = loadNodeGroupData(ctx, dockerCli, ngi) + if ok { + ngi = &nginfo{ng: ng} + err = loadNodeGroupData(ctx, dockerCli, ngi) + } } w := tabwriter.NewWriter(os.Stdout, 0, 0, 1, ' ', 0) @@ -92,22 +96,24 @@ func runInspect(dockerCli command.Cli, in inspectOptions, args []string) error { } else if ngi.err != nil { fmt.Fprintf(w, "Error:\t%s\n", ngi.err.Error()) } - fmt.Fprintln(w, "") - fmt.Fprintln(w, "Nodes:") - - for i, n := range ngi.ng.Nodes { - if i != 0 { - fmt.Fprintln(w, "") - } - fmt.Fprintf(w, "Name:\t%s\n", n.Name) - fmt.Fprintf(w, "Endpoint:\t%s\n", n.Endpoint) - if err := ngi.drivers[i].di.Err; err != nil { - fmt.Fprintf(w, "Error:\t%s\n", err.Error()) - } else if err := ngi.drivers[i].err; err != nil { - fmt.Fprintf(w, "Error:\t%s\n", err.Error()) - } else { - fmt.Fprintf(w, "Status:\t%s\n", ngi.drivers[i].info.Status) - fmt.Fprintf(w, "Platforms:\t%s\n", strings.Join(append(n.Platforms, ngi.drivers[i].platforms...), ", ")) + if err == nil { + fmt.Fprintln(w, "") + fmt.Fprintln(w, "Nodes:") + + for i, n := range ngi.ng.Nodes { + if i != 0 { + fmt.Fprintln(w, "") + } + fmt.Fprintf(w, "Name:\t%s\n", n.Name) + fmt.Fprintf(w, "Endpoint:\t%s\n", n.Endpoint) + if err := ngi.drivers[i].di.Err; err != nil { + fmt.Fprintf(w, "Error:\t%s\n", err.Error()) + } else if err := ngi.drivers[i].err; err != nil { + fmt.Fprintf(w, "Error:\t%s\n", err.Error()) + } else { + fmt.Fprintf(w, "Status:\t%s\n", ngi.drivers[i].info.Status) + fmt.Fprintf(w, "Platforms:\t%s\n", strings.Join(append(n.Platforms, ngi.drivers[i].platforms...), ", ")) + } } } @@ -137,7 +143,7 @@ func inspectCmd(dockerCli command.Cli) *cobra.Command { return cmd } -func boot(ctx context.Context, ngi *nginfo) error { +func boot(ctx context.Context, ngi *nginfo) (bool, error) { toBoot := make([]int, 0, len(ngi.drivers)) for i, d := range ngi.drivers { if d.err != nil || d.di.Err != nil || d.di.Driver == nil || d.info == nil { @@ -148,7 +154,7 @@ func boot(ctx context.Context, ngi *nginfo) error { } } if len(toBoot) == 0 { - return nil + return false, nil } pw := progress.NewPrinter(context.TODO(), os.Stderr, "auto") @@ -171,5 +177,5 @@ func boot(ctx context.Context, ngi *nginfo) error { }(idx) } - return eg.Wait() + return true, eg.Wait() } diff --git a/commands/ls.go b/commands/ls.go index c15c9d39..2f867586 100644 --- a/commands/ls.go +++ b/commands/ls.go @@ -90,7 +90,7 @@ func runLs(dockerCli command.Cli, in lsOptions) error { } w := tabwriter.NewWriter(os.Stdout, 0, 0, 1, ' ', 0) - fmt.Fprintf(w, "NAME\tDRIVER/ENDPOINT\tSTATUS\tPLATFORMS\n") + fmt.Fprintf(w, "NAME/NODE\tDRIVER/ENDPOINT\tSTATUS\tPLATFORMS\n") currentSet := false for _, b := range builders { diff --git a/commands/use.go b/commands/use.go index c92d2a06..9b55a2ac 100644 --- a/commands/use.go +++ b/commands/use.go @@ -39,7 +39,7 @@ func runUse(dockerCli command.Cli, in useOptions, name string) error { } for _, l := range list { if l.Name == name { - return errors.Errorf("to switch to context %s use `docker context use %s`", name, name) + return errors.Errorf("run `docker context use %s` to switch to context %s", name, name) } } diff --git a/commands/util.go b/commands/util.go index 41bd3d87..969471e3 100644 --- a/commands/util.go +++ b/commands/util.go @@ -285,7 +285,8 @@ func loadNodeGroupData(ctx context.Context, dockerCli command.Cli, ngi *nginfo) } ngi.drivers = make([]dinfo, len(dis)) for i, di := range dis { - ngi.drivers[i].di = &di + d := di + ngi.drivers[i].di = &d func(d *dinfo) { eg.Go(func() error { if err := loadInfoData(ctx, d); err != nil { diff --git a/store/nodegroup.go b/store/nodegroup.go index 56a489b2..21a4816b 100644 --- a/store/nodegroup.go +++ b/store/nodegroup.go @@ -33,6 +33,9 @@ func (ng *NodeGroup) Leave(name string) error { func (ng *NodeGroup) Update(name, endpoint string, platforms []string, endpointsSet bool, actionAppend bool) error { i := ng.findNode(name) if i == -1 && !actionAppend { + if len(ng.Nodes) > 0 { + return errors.Errorf("node %s not found, did you mean to append?", name) + } ng.Nodes = nil } if i != -1 { @@ -87,13 +90,12 @@ func (ng *NodeGroup) validateDuplicates(ep string) error { } func (ng *NodeGroup) findNode(name string) int { - i := -1 - for ii, n := range ng.Nodes { + for i, n := range ng.Nodes { if n.Name == name { - i = ii + return i } } - return i + return -1 } func (ng *NodeGroup) nextNodeName() string {