summaryrefslogtreecommitdiff
path: root/cmd/podman
diff options
context:
space:
mode:
authorOpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com>2020-09-30 11:33:19 +0000
committerGitHub <noreply@github.com>2020-09-30 11:33:19 +0000
commit08d036cbd4225a9802fb8dc7c4da7b53ded3896a (patch)
treeb38e8fa39f94589bfdaf90444d3dfe1dce4b41e8 /cmd/podman
parent19f080f1af884c1e36f55dc81cd51b0ac91a868a (diff)
parent22474095abe39c14c902650b08002c0bc89e7e6a (diff)
downloadpodman-08d036cbd4225a9802fb8dc7c4da7b53ded3896a.tar.gz
podman-08d036cbd4225a9802fb8dc7c4da7b53ded3896a.tar.bz2
podman-08d036cbd4225a9802fb8dc7c4da7b53ded3896a.zip
Merge pull request #7825 from rhatdan/exitcode
Fix handling of remove of bogus volumes, networks and Pods
Diffstat (limited to 'cmd/podman')
-rw-r--r--cmd/podman/containers/rm.go4
-rw-r--r--cmd/podman/networks/rm.go19
-rw-r--r--cmd/podman/pods/rm.go15
-rw-r--r--cmd/podman/volumes/rm.go18
4 files changed, 54 insertions, 2 deletions
diff --git a/cmd/podman/containers/rm.go b/cmd/podman/containers/rm.go
index 8d0c7920f..f8f12234d 100644
--- a/cmd/podman/containers/rm.go
+++ b/cmd/podman/containers/rm.go
@@ -105,7 +105,7 @@ func removeContainers(namesOrIDs []string, rmOptions entities.RmOptions, setExit
}
responses, err := registry.ContainerEngine().ContainerRm(context.Background(), namesOrIDs, rmOptions)
if err != nil {
- if setExit && len(namesOrIDs) < 2 {
+ if setExit {
setExitCode(err)
}
return err
@@ -132,7 +132,7 @@ func setExitCode(err error) {
switch {
case cause == define.ErrNoSuchCtr:
registry.SetExitCode(1)
- case strings.Contains(cause.Error(), define.ErrNoSuchImage.Error()):
+ case strings.Contains(cause.Error(), define.ErrNoSuchCtr.Error()):
registry.SetExitCode(1)
case cause == define.ErrCtrStateInvalid:
registry.SetExitCode(2)
diff --git a/cmd/podman/networks/rm.go b/cmd/podman/networks/rm.go
index ac49993b7..86aad43cb 100644
--- a/cmd/podman/networks/rm.go
+++ b/cmd/podman/networks/rm.go
@@ -2,10 +2,13 @@ package network
import (
"fmt"
+ "strings"
"github.com/containers/podman/v2/cmd/podman/registry"
"github.com/containers/podman/v2/cmd/podman/utils"
+ "github.com/containers/podman/v2/libpod/define"
"github.com/containers/podman/v2/pkg/domain/entities"
+ "github.com/pkg/errors"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
)
@@ -47,14 +50,30 @@ func networkRm(cmd *cobra.Command, args []string) error {
responses, err := registry.ContainerEngine().NetworkRm(registry.Context(), args, networkRmOptions)
if err != nil {
+ setExitCode(err)
return err
}
for _, r := range responses {
if r.Err == nil {
fmt.Println(r.Name)
} else {
+ setExitCode(r.Err)
errs = append(errs, r.Err)
}
}
return errs.PrintErrors()
}
+
+func setExitCode(err error) {
+ cause := errors.Cause(err)
+ switch {
+ case cause == define.ErrNoSuchNetwork:
+ registry.SetExitCode(1)
+ case strings.Contains(cause.Error(), define.ErrNoSuchNetwork.Error()):
+ registry.SetExitCode(1)
+ case cause == define.ErrNetworkInUse:
+ registry.SetExitCode(2)
+ case strings.Contains(cause.Error(), define.ErrNetworkInUse.Error()):
+ registry.SetExitCode(2)
+ }
+}
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)
+ }
+}
diff --git a/cmd/podman/volumes/rm.go b/cmd/podman/volumes/rm.go
index 5b23eb5e6..4c960d4d5 100644
--- a/cmd/podman/volumes/rm.go
+++ b/cmd/podman/volumes/rm.go
@@ -3,9 +3,11 @@ package volumes
import (
"context"
"fmt"
+ "strings"
"github.com/containers/podman/v2/cmd/podman/registry"
"github.com/containers/podman/v2/cmd/podman/utils"
+ "github.com/containers/podman/v2/libpod/define"
"github.com/containers/podman/v2/pkg/domain/entities"
"github.com/pkg/errors"
"github.com/spf13/cobra"
@@ -51,14 +53,30 @@ func rm(cmd *cobra.Command, args []string) error {
}
responses, err := registry.ContainerEngine().VolumeRm(context.Background(), args, rmOptions)
if err != nil {
+ setExitCode(err)
return err
}
for _, r := range responses {
if r.Err == nil {
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.ErrNoSuchVolume:
+ registry.SetExitCode(1)
+ case strings.Contains(cause.Error(), define.ErrNoSuchVolume.Error()):
+ registry.SetExitCode(1)
+ case cause == define.ErrVolumeBeingUsed:
+ registry.SetExitCode(2)
+ case strings.Contains(cause.Error(), define.ErrVolumeBeingUsed.Error()):
+ registry.SetExitCode(2)
+ }
+}