From 2c7984aaebf77acba1412cd5275888a2d3067549 Mon Sep 17 00:00:00 2001 From: CrazyMax Date: Thu, 18 Aug 2022 14:38:25 +0200 Subject: [PATCH] rm: ensure context builder is not removed with all-inactive flag Signed-off-by: CrazyMax --- commands/rm.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/commands/rm.go b/commands/rm.go index 73144066..9e72af03 100644 --- a/commands/rm.go +++ b/commands/rm.go @@ -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 }