summaryrefslogtreecommitdiff
path: root/cmd/podman/volumes
diff options
context:
space:
mode:
authorDaniel J Walsh <dwalsh@redhat.com>2021-09-30 14:43:39 -0400
committerDaniel J Walsh <dwalsh@redhat.com>2021-10-04 07:07:56 -0400
commit21c9dc3c406bb486c44c4a27e5b0497bab1cd40d (patch)
tree56793ffd885f835fa54013e9914844ff9ba20d92 /cmd/podman/volumes
parent36821d302e3787a42d6eefdbd0bdbb6d9da261fb (diff)
downloadpodman-21c9dc3c406bb486c44c4a27e5b0497bab1cd40d.tar.gz
podman-21c9dc3c406bb486c44c4a27e5b0497bab1cd40d.tar.bz2
podman-21c9dc3c406bb486c44c4a27e5b0497bab1cd40d.zip
Add --time out for podman * rm -f commands
Add --time flag to podman container rm Add --time flag to podman pod rm Add --time flag to podman volume rm Add --time flag to podman network rm Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
Diffstat (limited to 'cmd/podman/volumes')
-rw-r--r--cmd/podman/volumes/rm.go13
-rw-r--r--cmd/podman/volumes/volume.go2
2 files changed, 14 insertions, 1 deletions
diff --git a/cmd/podman/volumes/rm.go b/cmd/podman/volumes/rm.go
index 9ba4a30a1..fd5df20b7 100644
--- a/cmd/podman/volumes/rm.go
+++ b/cmd/podman/volumes/rm.go
@@ -5,6 +5,7 @@ import (
"fmt"
"strings"
+ "github.com/containers/common/pkg/completion"
"github.com/containers/podman/v3/cmd/podman/common"
"github.com/containers/podman/v3/cmd/podman/registry"
"github.com/containers/podman/v3/cmd/podman/utils"
@@ -32,7 +33,8 @@ var (
)
var (
- rmOptions = entities.VolumeRmOptions{}
+ rmOptions = entities.VolumeRmOptions{}
+ stopTimeout uint
)
func init() {
@@ -43,6 +45,9 @@ func init() {
flags := rmCommand.Flags()
flags.BoolVarP(&rmOptions.All, "all", "a", false, "Remove all volumes")
flags.BoolVarP(&rmOptions.Force, "force", "f", false, "Remove a volume by force, even if it is being used by a container")
+ timeFlagName := "time"
+ flags.UintVarP(&stopTimeout, timeFlagName, "t", containerConfig.Engine.StopTimeout, "Seconds to wait for running containers to stop before killing the container")
+ _ = rmCommand.RegisterFlagCompletionFunc(timeFlagName, completion.AutocompleteNone)
}
func rm(cmd *cobra.Command, args []string) error {
@@ -52,6 +57,12 @@ func rm(cmd *cobra.Command, args []string) error {
if (len(args) > 0 && rmOptions.All) || (len(args) < 1 && !rmOptions.All) {
return errors.New("choose either one or more volumes or all")
}
+ if cmd.Flag("time").Changed {
+ if !rmOptions.Force {
+ return errors.New("--force option must be specified to use the --time option")
+ }
+ rmOptions.Timeout = &stopTimeout
+ }
responses, err := registry.ContainerEngine().VolumeRm(context.Background(), args, rmOptions)
if err != nil {
setExitCode(err)
diff --git a/cmd/podman/volumes/volume.go b/cmd/podman/volumes/volume.go
index f42a6d81a..2f06abd4e 100644
--- a/cmd/podman/volumes/volume.go
+++ b/cmd/podman/volumes/volume.go
@@ -3,6 +3,7 @@ package volumes
import (
"github.com/containers/podman/v3/cmd/podman/registry"
"github.com/containers/podman/v3/cmd/podman/validate"
+ "github.com/containers/podman/v3/pkg/util"
"github.com/spf13/cobra"
)
@@ -17,6 +18,7 @@ var (
Long: "Volumes are created in and can be shared between containers",
RunE: validate.SubCommandExists,
}
+ containerConfig = util.DefaultContainerConfig()
)
func init() {