Skip to content

Commit

Permalink
Fix: Deleting multiple networks stops at first delete fail
Browse files Browse the repository at this point in the history
Signed-off-by: yaozhenxiu <946666800@qq.com>
  • Loading branch information
yzxiu committed Dec 9, 2022
1 parent c2c648c commit ae16016
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions cmd/nerdctl/network_rm.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (

"github.com/containerd/nerdctl/pkg/idutil/netwalker"
"github.com/containerd/nerdctl/pkg/netutil"
"github.com/sirupsen/logrus"

"github.com/spf13/cobra"
)
Expand Down Expand Up @@ -91,16 +92,31 @@ func networkRmAction(cmd *cobra.Command, args []string) error {
},
}

status := 0
for _, name := range args {
if name == "host" || name == "none" {
return fmt.Errorf("pseudo network %q cannot be removed", name)
status = 1
logrus.Errorf("pseudo network %q cannot be removed", name)
continue
}

n, err := walker.Walk(cmd.Context(), name)
if err != nil {
return err
status = 1
logrus.Error(err)
continue
} else if n == 0 {
return fmt.Errorf("no such network %s", name)
status = 1
logrus.Errorf("No such network: %s", name)
continue
}
}

// compatible with docker
if status != 0 {
return ExitCodeError{
error: nil,
exitCode: status,
}
}
return nil
Expand Down

0 comments on commit ae16016

Please sign in to comment.