@@ -11,7 +11,8 @@ import (
1111)
1212
1313type rmOptions struct {
14- builder string
14+ builder string
15+ keepState bool
1516}
1617
1718func runRm (dockerCli command.Cli , in rmOptions ) error {
@@ -28,7 +29,7 @@ func runRm(dockerCli command.Cli, in rmOptions) error {
2829 if err != nil {
2930 return err
3031 }
31- err1 := stop (ctx , dockerCli , ng , true )
32+ err1 := rm (ctx , dockerCli , ng , in . keepState )
3233 if err := txn .Remove (ng .Name ); err != nil {
3334 return err
3435 }
@@ -40,7 +41,7 @@ func runRm(dockerCli command.Cli, in rmOptions) error {
4041 return err
4142 }
4243 if ng != nil {
43- err1 := stop (ctx , dockerCli , ng , true )
44+ err1 := rm (ctx , dockerCli , ng , in . keepState )
4445 if err := txn .Remove (ng .Name ); err != nil {
4546 return err
4647 }
@@ -66,10 +67,13 @@ func rmCmd(dockerCli command.Cli, rootOpts *rootOptions) *cobra.Command {
6667 },
6768 }
6869
70+ flags := cmd .Flags ()
71+ flags .BoolVar (& options .keepState , "keep-state" , false , "Keep BuildKit state" )
72+
6973 return cmd
7074}
7175
72- func stop (ctx context.Context , dockerCli command.Cli , ng * store.NodeGroup , rm bool ) error {
76+ func rm (ctx context.Context , dockerCli command.Cli , ng * store.NodeGroup , keepState bool ) error {
7377 dis , err := driversForNodeGroup (ctx , dockerCli , ng , "" )
7478 if err != nil {
7579 return err
@@ -79,34 +83,9 @@ func stop(ctx context.Context, dockerCli command.Cli, ng *store.NodeGroup, rm bo
7983 if err := di .Driver .Stop (ctx , true ); err != nil {
8084 return err
8185 }
82- if rm {
83- if err := di .Driver .Rm (ctx , true ); err != nil {
84- return err
85- }
86- }
87- }
88- if di .Err != nil {
89- err = di .Err
90- }
91- }
92- return err
93- }
94-
95- func stopCurrent (ctx context.Context , dockerCli command.Cli , rm bool ) error {
96- dis , err := getDefaultDrivers (ctx , dockerCli , false , "" )
97- if err != nil {
98- return err
99- }
100- for _ , di := range dis {
101- if di .Driver != nil {
102- if err := di .Driver .Stop (ctx , true ); err != nil {
86+ if err := di .Driver .Rm (ctx , true , ! keepState ); err != nil {
10387 return err
10488 }
105- if rm {
106- if err := di .Driver .Rm (ctx , true ); err != nil {
107- return err
108- }
109- }
11089 }
11190 if di .Err != nil {
11291 err = di .Err
0 commit comments