commands: fix invalid reload on boot

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
This commit is contained in:
Tonis Tiigi 2019-04-15 17:01:00 -07:00
parent 0f4de0d7e4
commit f7dac5a178
6 changed files with 44 additions and 29 deletions

View File

@ -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,

View File

@ -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:")
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...), ", "))
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()
}

View File

@ -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 {

View File

@ -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)
}
}

View File

@ -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 {

View File

@ -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 {