mirror of
https://gitea.com/Lydanne/buildx.git
synced 2025-05-18 00:47:48 +08:00
commands: fix invalid reload on boot
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
This commit is contained in:
parent
0f4de0d7e4
commit
f7dac5a178
@ -29,7 +29,7 @@ func runCreate(dockerCli command.Cli, in createOptions, args []string) error {
|
|||||||
ctx := appcontext.Context()
|
ctx := appcontext.Context()
|
||||||
|
|
||||||
if in.name == "default" {
|
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 {
|
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 {
|
if ng == nil {
|
||||||
ng = &store.NodeGroup{
|
ng = &store.NodeGroup{
|
||||||
Name: name,
|
Name: name,
|
||||||
|
@ -77,11 +77,15 @@ func runInspect(dockerCli command.Cli, in inspectOptions, args []string) error {
|
|||||||
err = loadNodeGroupData(timeoutCtx, dockerCli, ngi)
|
err = loadNodeGroupData(timeoutCtx, dockerCli, ngi)
|
||||||
|
|
||||||
if in.bootstrap {
|
if in.bootstrap {
|
||||||
if err := boot(ctx, ngi); err != nil {
|
var ok bool
|
||||||
|
ok, err = boot(ctx, ngi)
|
||||||
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
ngi = &nginfo{ng: ng}
|
if ok {
|
||||||
err = loadNodeGroupData(ctx, dockerCli, ngi)
|
ngi = &nginfo{ng: ng}
|
||||||
|
err = loadNodeGroupData(ctx, dockerCli, ngi)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
w := tabwriter.NewWriter(os.Stdout, 0, 0, 1, ' ', 0)
|
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 {
|
} else if ngi.err != nil {
|
||||||
fmt.Fprintf(w, "Error:\t%s\n", ngi.err.Error())
|
fmt.Fprintf(w, "Error:\t%s\n", ngi.err.Error())
|
||||||
}
|
}
|
||||||
fmt.Fprintln(w, "")
|
if err == nil {
|
||||||
fmt.Fprintln(w, "Nodes:")
|
fmt.Fprintln(w, "")
|
||||||
|
fmt.Fprintln(w, "Nodes:")
|
||||||
|
|
||||||
for i, n := range ngi.ng.Nodes {
|
for i, n := range ngi.ng.Nodes {
|
||||||
if i != 0 {
|
if i != 0 {
|
||||||
fmt.Fprintln(w, "")
|
fmt.Fprintln(w, "")
|
||||||
}
|
}
|
||||||
fmt.Fprintf(w, "Name:\t%s\n", n.Name)
|
fmt.Fprintf(w, "Name:\t%s\n", n.Name)
|
||||||
fmt.Fprintf(w, "Endpoint:\t%s\n", n.Endpoint)
|
fmt.Fprintf(w, "Endpoint:\t%s\n", n.Endpoint)
|
||||||
if err := ngi.drivers[i].di.Err; err != nil {
|
if err := ngi.drivers[i].di.Err; err != nil {
|
||||||
fmt.Fprintf(w, "Error:\t%s\n", err.Error())
|
fmt.Fprintf(w, "Error:\t%s\n", err.Error())
|
||||||
} else if err := ngi.drivers[i].err; err != nil {
|
} else if err := ngi.drivers[i].err; err != nil {
|
||||||
fmt.Fprintf(w, "Error:\t%s\n", err.Error())
|
fmt.Fprintf(w, "Error:\t%s\n", err.Error())
|
||||||
} else {
|
} else {
|
||||||
fmt.Fprintf(w, "Status:\t%s\n", ngi.drivers[i].info.Status)
|
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...), ", "))
|
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
|
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))
|
toBoot := make([]int, 0, len(ngi.drivers))
|
||||||
for i, d := range ngi.drivers {
|
for i, d := range ngi.drivers {
|
||||||
if d.err != nil || d.di.Err != nil || d.di.Driver == nil || d.info == nil {
|
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 {
|
if len(toBoot) == 0 {
|
||||||
return nil
|
return false, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
pw := progress.NewPrinter(context.TODO(), os.Stderr, "auto")
|
pw := progress.NewPrinter(context.TODO(), os.Stderr, "auto")
|
||||||
@ -171,5 +177,5 @@ func boot(ctx context.Context, ngi *nginfo) error {
|
|||||||
}(idx)
|
}(idx)
|
||||||
}
|
}
|
||||||
|
|
||||||
return eg.Wait()
|
return true, eg.Wait()
|
||||||
}
|
}
|
||||||
|
@ -90,7 +90,7 @@ func runLs(dockerCli command.Cli, in lsOptions) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
w := tabwriter.NewWriter(os.Stdout, 0, 0, 1, ' ', 0)
|
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
|
currentSet := false
|
||||||
for _, b := range builders {
|
for _, b := range builders {
|
||||||
|
@ -39,7 +39,7 @@ func runUse(dockerCli command.Cli, in useOptions, name string) error {
|
|||||||
}
|
}
|
||||||
for _, l := range list {
|
for _, l := range list {
|
||||||
if l.Name == name {
|
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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -285,7 +285,8 @@ func loadNodeGroupData(ctx context.Context, dockerCli command.Cli, ngi *nginfo)
|
|||||||
}
|
}
|
||||||
ngi.drivers = make([]dinfo, len(dis))
|
ngi.drivers = make([]dinfo, len(dis))
|
||||||
for i, di := range dis {
|
for i, di := range dis {
|
||||||
ngi.drivers[i].di = &di
|
d := di
|
||||||
|
ngi.drivers[i].di = &d
|
||||||
func(d *dinfo) {
|
func(d *dinfo) {
|
||||||
eg.Go(func() error {
|
eg.Go(func() error {
|
||||||
if err := loadInfoData(ctx, d); err != nil {
|
if err := loadInfoData(ctx, d); err != nil {
|
||||||
|
@ -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 {
|
func (ng *NodeGroup) Update(name, endpoint string, platforms []string, endpointsSet bool, actionAppend bool) error {
|
||||||
i := ng.findNode(name)
|
i := ng.findNode(name)
|
||||||
if i == -1 && !actionAppend {
|
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
|
ng.Nodes = nil
|
||||||
}
|
}
|
||||||
if i != -1 {
|
if i != -1 {
|
||||||
@ -87,13 +90,12 @@ func (ng *NodeGroup) validateDuplicates(ep string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (ng *NodeGroup) findNode(name string) int {
|
func (ng *NodeGroup) findNode(name string) int {
|
||||||
i := -1
|
for i, n := range ng.Nodes {
|
||||||
for ii, n := range ng.Nodes {
|
|
||||||
if n.Name == name {
|
if n.Name == name {
|
||||||
i = ii
|
return i
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return i
|
return -1
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ng *NodeGroup) nextNodeName() string {
|
func (ng *NodeGroup) nextNodeName() string {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user