summaryrefslogtreecommitdiff
path: root/cmd/podman/pod_kill.go
diff options
context:
space:
mode:
Diffstat (limited to 'cmd/podman/pod_kill.go')
-rw-r--r--cmd/podman/pod_kill.go52
1 files changed, 22 insertions, 30 deletions
diff --git a/cmd/podman/pod_kill.go b/cmd/podman/pod_kill.go
index febc820cd..aaaae0f7d 100644
--- a/cmd/podman/pod_kill.go
+++ b/cmd/podman/pod_kill.go
@@ -5,7 +5,7 @@ import (
"syscall"
"github.com/containers/libpod/cmd/podman/cliconfig"
- "github.com/containers/libpod/cmd/podman/libpodruntime"
+ "github.com/containers/libpod/pkg/adapter"
"github.com/docker/docker/pkg/signal"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
@@ -24,7 +24,12 @@ var (
podKillCommand.GlobalFlags = MainGlobalOpts
return podKillCmd(&podKillCommand)
},
- Example: "[POD_NAME_OR_ID]",
+ Args: func(cmd *cobra.Command, args []string) error {
+ return checkAllAndLatest(cmd, args, false)
+ },
+ Example: `podman pod kill podID
+ podman pod kill --signal TERM mywebserver
+ podman pod kill --latest`,
}
)
@@ -35,15 +40,12 @@ func init() {
flags.BoolVarP(&podKillCommand.All, "all", "a", false, "Kill all containers in all pods")
flags.BoolVarP(&podKillCommand.Latest, "latest", "l", false, "Act on the latest pod podman is aware of")
flags.StringVarP(&podKillCommand.Signal, "signal", "s", "KILL", "Signal to send to the containers in the pod")
+ markFlagHiddenForRemoteClient("latest", flags)
}
// podKillCmd kills one or more pods with a signal
func podKillCmd(c *cliconfig.PodKillValues) error {
- if err := checkMutuallyExclusiveFlags(&c.PodmanCommand); err != nil {
- return err
- }
-
- runtime, err := libpodruntime.GetRuntime(&c.PodmanCommand)
+ runtime, err := adapter.GetRuntime(&c.PodmanCommand)
if err != nil {
return errors.Wrapf(err, "could not get runtime")
}
@@ -61,30 +63,20 @@ func podKillCmd(c *cliconfig.PodKillValues) error {
killSignal = uint(sysSignal)
}
- // getPodsFromContext returns an error when a requested pod
- // isn't found. The only fatal error scenerio is when there are no pods
- // in which case the following loop will be skipped.
- pods, lastError := getPodsFromContext(&c.PodmanCommand, runtime)
+ podKillIds, podKillErrors := runtime.KillPods(getContext(), c, killSignal)
+ for _, p := range podKillIds {
+ fmt.Println(p)
+ }
+ if len(podKillErrors) == 0 {
+ return nil
+ }
+ // Grab the last error
+ lastError := podKillErrors[len(podKillErrors)-1]
+ // Remove the last error from the error slice
+ podKillErrors = podKillErrors[:len(podKillErrors)-1]
- for _, pod := range pods {
- ctr_errs, err := pod.Kill(killSignal)
- if ctr_errs != nil {
- for ctr, err := range ctr_errs {
- if lastError != nil {
- logrus.Errorf("%q", lastError)
- }
- lastError = errors.Wrapf(err, "unable to kill container %q in pod %q", ctr, pod.ID())
- }
- continue
- }
- if err != nil {
- if lastError != nil {
- logrus.Errorf("%q", lastError)
- }
- lastError = errors.Wrapf(err, "unable to kill pod %q", pod.ID())
- continue
- }
- fmt.Println(pod.ID())
+ for _, err := range podKillErrors {
+ logrus.Errorf("%q", err)
}
return lastError
}