rm: ensure context builder is not removed with all-inactive flag

Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
pull/1280/head
CrazyMax 3 years ago
parent 441853f189
commit 2c7984aaeb
No known key found for this signature in database
GPG Key ID: 3248E46B6BB8C7F7

@ -149,6 +149,11 @@ func rmAllInactive(ctx context.Context, txn *store.Txn, dockerCli command.Cli, i
builders[i] = &nginfo{ng: ng}
}
ctxbuilders, err := dockerCli.ContextStore().List()
if err != nil {
return err
}
eg, _ := errgroup.WithContext(ctx)
for _, b := range builders {
func(b *nginfo) {
@ -156,6 +161,11 @@ func rmAllInactive(ctx context.Context, txn *store.Txn, dockerCli command.Cli, i
if err := loadNodeGroupData(ctx, dockerCli, b); err != nil {
return errors.Wrapf(err, "cannot load %s", b.ng.Name)
}
for _, cb := range ctxbuilders {
if b.ng.Driver == "docker" && len(b.ng.Nodes) == 1 && b.ng.Nodes[0].Endpoint == cb.Name {
return errors.Errorf("context builder cannot be removed, run `docker context rm %s` to remove this context", cb.Name)
}
}
if b.ng.Dynamic {
return nil
}

Loading…
Cancel
Save