summaryrefslogtreecommitdiff
path: root/cmd/podman
diff options
context:
space:
mode:
authorKarthik Elango <kelango@redhat.com>2022-06-28 15:31:20 -0400
committerMatthew Heon <matthew.heon@pm.me>2022-07-26 13:25:36 -0400
commit6d84a9952f1e5be1a187bcc6d9bbc2532331cfc8 (patch)
tree4219ba61a3cf8920dcde4fa1fe715ddd319932ab /cmd/podman
parenta78be890ee0098c6a6809b562c4806da8fe344b5 (diff)
downloadpodman-6d84a9952f1e5be1a187bcc6d9bbc2532331cfc8.tar.gz
podman-6d84a9952f1e5be1a187bcc6d9bbc2532331cfc8.tar.bz2
podman-6d84a9952f1e5be1a187bcc6d9bbc2532331cfc8.zip
Podman stop --filter flag
Filter flag is added for podman stop and podman --remote stop. Filtering logic is implemented in getContainersAndInputByContext(). Start filtering can be manipulated to use this logic as well to limit redundancy. Signed-off-by: Karthik Elango <kelango@redhat.com>
Diffstat (limited to 'cmd/podman')
-rw-r--r--cmd/podman/containers/stop.go17
-rw-r--r--cmd/podman/validate/args.go7
2 files changed, 22 insertions, 2 deletions
diff --git a/cmd/podman/containers/stop.go b/cmd/podman/containers/stop.go
index 2ddd169a1..261f441c3 100644
--- a/cmd/podman/containers/stop.go
+++ b/cmd/podman/containers/stop.go
@@ -49,7 +49,9 @@ var (
)
var (
- stopOptions = entities.StopOptions{}
+ stopOptions = entities.StopOptions{
+ Filters: make(map[string][]string),
+ }
stopTimeout uint
)
@@ -67,6 +69,10 @@ func stopFlags(cmd *cobra.Command) {
flags.UintVarP(&stopTimeout, timeFlagName, "t", containerConfig.Engine.StopTimeout, "Seconds to wait for stop before killing the container")
_ = cmd.RegisterFlagCompletionFunc(timeFlagName, completion.AutocompleteNone)
+ filterFlagName := "filter"
+ flags.StringSliceVarP(&filters, filterFlagName, "f", []string{}, "Filter output based on conditions given")
+ _ = cmd.RegisterFlagCompletionFunc(filterFlagName, common.AutocompletePsFilters)
+
if registry.IsRemote() {
_ = flags.MarkHidden("cidfile")
_ = flags.MarkHidden("ignore")
@@ -97,7 +103,6 @@ func stop(cmd *cobra.Command, args []string) error {
if cmd.Flag("time").Changed {
stopOptions.Timeout = &stopTimeout
}
-
for _, cidFile := range cidFiles {
content, err := ioutil.ReadFile(cidFile)
if err != nil {
@@ -107,6 +112,14 @@ func stop(cmd *cobra.Command, args []string) error {
args = append(args, id)
}
+ for _, f := range filters {
+ split := strings.SplitN(f, "=", 2)
+ if len(split) < 2 {
+ return fmt.Errorf("invalid filter %q", f)
+ }
+ stopOptions.Filters[split[0]] = append(stopOptions.Filters[split[0]], split[1])
+ }
+
responses, err := registry.ContainerEngine().ContainerStop(context.Background(), args, stopOptions)
if err != nil {
return err
diff --git a/cmd/podman/validate/args.go b/cmd/podman/validate/args.go
index 39eedca64..6d212665d 100644
--- a/cmd/podman/validate/args.go
+++ b/cmd/podman/validate/args.go
@@ -86,6 +86,13 @@ func CheckAllLatestAndIDFile(c *cobra.Command, args []string, ignoreArgLen bool,
specifiedIDFile = true
}
+ if c.Flags().Changed("filter") {
+ if argLen > 0 {
+ return errors.New("--filter takes no arguments")
+ }
+ return nil
+ }
+
if specifiedIDFile && (specifiedAll || specifiedLatest) {
return fmt.Errorf("--all, --latest, and --%s cannot be used together", idFileFlag)
} else if specifiedAll && specifiedLatest {