From 5c624bf83b8815d608a3700dacb57d066c6d8d3e Mon Sep 17 00:00:00 2001 From: Antonio Ojea Date: Sat, 22 Aug 2020 22:22:04 +0200 Subject: [PATCH] fix podman delete network --- .../internal/providers/podman/network.go | 4 +- .../internal/providers/podman/provider.go | 49 +++++++++---------- 2 files changed, 26 insertions(+), 27 deletions(-) diff --git a/pkg/cluster/internal/providers/podman/network.go b/pkg/cluster/internal/providers/podman/network.go index 99c62cc5d7..451c38f36c 100644 --- a/pkg/cluster/internal/providers/podman/network.go +++ b/pkg/cluster/internal/providers/podman/network.go @@ -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() } diff --git a/pkg/cluster/internal/providers/podman/provider.go b/pkg/cluster/internal/providers/podman/provider.go index 7df7fa9929..d5024e04ea 100644 --- a/pkg/cluster/internal/providers/podman/provider.go +++ b/pkg/cluster/internal/providers/podman/provider.go @@ -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) }