summaryrefslogtreecommitdiff
path: root/cmd/podman/pods
diff options
context:
space:
mode:
authorDaniel J Walsh <dwalsh@redhat.com>2020-09-29 10:05:53 -0400
committerDaniel J Walsh <dwalsh@redhat.com>2020-09-29 15:52:43 -0400
commit22474095abe39c14c902650b08002c0bc89e7e6a (patch)
treee601964f926bf5e6b6684d4dae796d7282974f56 /cmd/podman/pods
parent12f173f4732d50a85bf4875807597d2fd0e92cc0 (diff)
downloadpodman-22474095abe39c14c902650b08002c0bc89e7e6a.tar.gz
podman-22474095abe39c14c902650b08002c0bc89e7e6a.tar.bz2
podman-22474095abe39c14c902650b08002c0bc89e7e6a.zip
Fix handling of remove of bogus volumes, networks and Pods
In podman containers rm and podman images rm, the commands exit with error code 1 if the object does not exists. This PR implements similar functionality to volumes, networks, and Pods. Similarly if volumes or Networks are in use by other containers, and return exit code 2. Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
Diffstat (limited to 'cmd/podman/pods')
-rw-r--r--cmd/podman/pods/rm.go15
1 files changed, 15 insertions, 0 deletions
diff --git a/cmd/podman/pods/rm.go b/cmd/podman/pods/rm.go
index 0bb35e1ca..2975db3e8 100644
--- a/cmd/podman/pods/rm.go
+++ b/cmd/podman/pods/rm.go
@@ -3,12 +3,15 @@ package pods
import (
"context"
"fmt"
+ "strings"
"github.com/containers/podman/v2/cmd/podman/common"
"github.com/containers/podman/v2/cmd/podman/registry"
"github.com/containers/podman/v2/cmd/podman/utils"
"github.com/containers/podman/v2/cmd/podman/validate"
+ "github.com/containers/podman/v2/libpod/define"
"github.com/containers/podman/v2/pkg/domain/entities"
+ "github.com/pkg/errors"
"github.com/spf13/cobra"
)
@@ -73,6 +76,7 @@ func removePods(namesOrIDs []string, rmOptions entities.PodRmOptions, printIDs b
responses, err := registry.ContainerEngine().PodRm(context.Background(), namesOrIDs, rmOptions)
if err != nil {
+ setExitCode(err)
return err
}
@@ -83,8 +87,19 @@ func removePods(namesOrIDs []string, rmOptions entities.PodRmOptions, printIDs b
fmt.Println(r.Id)
}
} else {
+ setExitCode(r.Err)
errs = append(errs, r.Err)
}
}
return errs.PrintErrors()
}
+
+func setExitCode(err error) {
+ cause := errors.Cause(err)
+ switch {
+ case cause == define.ErrNoSuchPod:
+ registry.SetExitCode(1)
+ case strings.Contains(cause.Error(), define.ErrNoSuchPod.Error()):
+ registry.SetExitCode(1)
+ }
+}