Skip to content

Commit

Permalink
fix podman delete network
Browse files Browse the repository at this point in the history
  • Loading branch information
Antonio Ojea committed Aug 22, 2020
1 parent 2c9be89 commit 5c624bf
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 27 deletions.
4 changes: 2 additions & 2 deletions pkg/cluster/internal/providers/podman/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ func createNetwork(name, subnet string) error {
// delete network if exists, otherwise do nothing
func deleteNetwork(name string) error {
networkName := fmt.Sprintf("%s-%s", fixedNetworkPrefix, name)
if err := exec.Command("podman", "network", "inspect", networkName); err != nil {
return nil
if err := exec.Command("podman", "network", "inspect", networkName).Run(); err != nil {
return err
}
return exec.Command("podman", "network", "rm", networkName).Run()
}
Expand Down
49 changes: 24 additions & 25 deletions pkg/cluster/internal/providers/podman/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,34 +137,33 @@ func (p *Provider) DeleteCluster(name string) error {
return errors.Wrap(err, "error listing nodes")
}

if len(n) == 0 {
return nil
}
const command = "podman"
args := make([]string, 0, len(n)+3) // allocate once
args = append(args,
"rm",
"-f", // force the container to be delete now
"-v", // delete volumes
)
for _, node := range n {
args = append(args, node.String())
}
if err := exec.Command(command, args...).Run(); err != nil {
return errors.Wrap(err, "failed to delete nodes")
}
var nodeVolumes []string
for _, node := range n {
volumes, err := getVolumes(node.String())
if err != nil {
// delete nodes
if len(n) != 0 {
const command = "podman"
args := make([]string, 0, len(n)+3) // allocate once
args = append(args,
"rm",
"-f", // force the container to be delete now
"-v", // delete volumes
)
for _, node := range n {
args = append(args, node.String())
}
if err := exec.Command(command, args...).Run(); err != nil {
return errors.Wrap(err, "failed to delete nodes")
}
var nodeVolumes []string
for _, node := range n {
volumes, err := getVolumes(node.String())
if err != nil {
return err
}
nodeVolumes = append(nodeVolumes, volumes...)
}
if err := deleteVolumes(nodeVolumes); err != nil {
return err
}
nodeVolumes = append(nodeVolumes, volumes...)
}
if err := deleteVolumes(nodeVolumes); err != nil {
return err
}

return deleteNetwork(name)
}

Expand Down

0 comments on commit 5c624bf

Please sign in to comment.