summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cmd/podman/libpodruntime/runtime.go15
-rw-r--r--cmd/podman/main.go5
-rw-r--r--cmd/podman/pod.go25
-rw-r--r--cmd/podman/pod_create.go109
-rw-r--r--cmd/podman/pod_ps.go600
-rw-r--r--cmd/podman/pod_rm.go103
-rw-r--r--cmd/podman/run.go14
-rw-r--r--cmd/podman/sigproxy.go2
-rw-r--r--cmd/podman/start.go2
-rw-r--r--completions/bash/podman142
-rw-r--r--docs/podman-pod-create.1.md60
-rw-r--r--docs/podman-pod-ps.1.md165
-rw-r--r--docs/podman-pod-rm.1.md42
-rw-r--r--docs/podman-pod.1.md21
-rw-r--r--libpod/oci.go21
-rw-r--r--libpod/runtime.go52
-rw-r--r--libpod/runtime_pod_linux.go2
-rw-r--r--pkg/rootless/rootless_linux.c6
-rw-r--r--pkg/rootless/rootless_linux.go31
-rw-r--r--pkg/rootless/rootless_unsupported.go4
-rw-r--r--pkg/spec/createconfig.go8
-rw-r--r--test/e2e/libpod_suite_test.go46
-rw-r--r--test/e2e/pod_create_test.go84
-rw-r--r--test/e2e/pod_ps_test.go227
-rw-r--r--test/e2e/pod_rm_test.go168
25 files changed, 1895 insertions, 59 deletions
diff --git a/cmd/podman/libpodruntime/runtime.go b/cmd/podman/libpodruntime/runtime.go
index b48667653..098864810 100644
--- a/cmd/podman/libpodruntime/runtime.go
+++ b/cmd/podman/libpodruntime/runtime.go
@@ -6,6 +6,7 @@ import (
"path/filepath"
"github.com/containers/storage"
+ "github.com/pkg/errors"
"github.com/projectatomic/libpod/libpod"
"github.com/projectatomic/libpod/pkg/rootless"
"github.com/urfave/cli"
@@ -23,7 +24,11 @@ func GetRuntime(c *cli.Context) (*libpod.Runtime, error) {
func GetRootlessStorageOpts() (storage.StoreOptions, error) {
var opts storage.StoreOptions
- opts.RunRoot = filepath.Join(libpod.GetRootlessRuntimeDir(), "run")
+ rootlessRuntime, err := libpod.GetRootlessRuntimeDir()
+ if err != nil {
+ return opts, err
+ }
+ opts.RunRoot = filepath.Join(rootlessRuntime, "run")
dataDir := os.Getenv("XDG_DATA_HOME")
if dataDir == "" {
@@ -31,7 +36,13 @@ func GetRootlessStorageOpts() (storage.StoreOptions, error) {
if home == "" {
return opts, fmt.Errorf("neither XDG_DATA_HOME nor HOME was set non-empty")
}
- dataDir = filepath.Join(home, ".local", "share")
+ // runc doesn't like symlinks in the rootfs path, and at least
+ // on CoreOS /home is a symlink to /var/home, so resolve any symlink.
+ resolvedHome, err := filepath.EvalSymlinks(home)
+ if err != nil {
+ return opts, errors.Wrapf(err, "cannot resolve %s", home)
+ }
+ dataDir = filepath.Join(resolvedHome, ".local", "share")
}
opts.GraphRoot = filepath.Join(dataDir, "containers", "storage")
opts.GraphDriverName = "vfs"
diff --git a/cmd/podman/main.go b/cmd/podman/main.go
index f533a8b13..3dbf196c2 100644
--- a/cmd/podman/main.go
+++ b/cmd/podman/main.go
@@ -29,13 +29,13 @@ func main() {
debug := false
cpuProfile := false
- became, err := rootless.BecomeRootInUserNS()
+ became, ret, err := rootless.BecomeRootInUserNS()
if err != nil {
logrus.Errorf(err.Error())
os.Exit(1)
}
if became {
- os.Exit(0)
+ os.Exit(ret)
}
if reexec.Init() {
@@ -71,6 +71,7 @@ func main() {
mountCommand,
pauseCommand,
psCommand,
+ podCommand,
portCommand,
pullCommand,
pushCommand,
diff --git a/cmd/podman/pod.go b/cmd/podman/pod.go
new file mode 100644
index 000000000..6cf2920a5
--- /dev/null
+++ b/cmd/podman/pod.go
@@ -0,0 +1,25 @@
+package main
+
+import (
+ "github.com/urfave/cli"
+)
+
+var (
+ podDescription = `
+ podman pod
+
+ Manage container pods.
+ Pods are a group of one or more containers sharing the same network, pid and ipc namespaces.
+`
+ podCommand = cli.Command{
+ Name: "pod",
+ Usage: "Manage pods",
+ Description: podDescription,
+ UseShortOptionHandling: true,
+ Subcommands: []cli.Command{
+ podCreateCommand,
+ podPsCommand,
+ podRmCommand,
+ },
+ }
+)
diff --git a/cmd/podman/pod_create.go b/cmd/podman/pod_create.go
new file mode 100644
index 000000000..f86faa409
--- /dev/null
+++ b/cmd/podman/pod_create.go
@@ -0,0 +1,109 @@
+package main
+
+import (
+ "fmt"
+ "os"
+
+ "github.com/pkg/errors"
+ "github.com/projectatomic/libpod/cmd/podman/libpodruntime"
+ "github.com/projectatomic/libpod/libpod"
+ "github.com/sirupsen/logrus"
+ "github.com/urfave/cli"
+)
+
+var podCreateDescription = "Creates a new empty pod. The pod ID is then" +
+ " printed to stdout. You can then start it at any time with the" +
+ " podman pod start <pod_id> command. The pod will be created with the" +
+ " initial state 'created'."
+
+var podCreateFlags = []cli.Flag{
+ cli.StringFlag{
+ Name: "cgroup-parent",
+ Usage: "Set parent cgroup for the pod",
+ },
+ cli.StringSliceFlag{
+ Name: "label-file",
+ Usage: "Read in a line delimited file of labels (default [])",
+ },
+ cli.StringSliceFlag{
+ Name: "label, l",
+ Usage: "Set metadata on pod (default [])",
+ },
+ cli.StringFlag{
+ Name: "name, n",
+ Usage: "Assign a name to the pod",
+ },
+ cli.StringFlag{
+ Name: "pod-id-file",
+ Usage: "Write the pod ID to the file",
+ },
+}
+
+var podCreateCommand = cli.Command{
+ Name: "create",
+ Usage: "create a new empty pod",
+ Description: podCreateDescription,
+ Flags: podCreateFlags,
+ Action: podCreateCmd,
+ SkipArgReorder: true,
+ UseShortOptionHandling: true,
+}
+
+func podCreateCmd(c *cli.Context) error {
+ var options []libpod.PodCreateOption
+ var err error
+
+ if err = validateFlags(c, createFlags); err != nil {
+ return err
+ }
+
+ runtime, err := libpodruntime.GetRuntime(c)
+ if err != nil {
+ return errors.Wrapf(err, "error creating libpod runtime")
+ }
+ defer runtime.Shutdown(false)
+
+ if c.IsSet("pod-id-file") {
+ if _, err = os.Stat(c.String("pod-id-file")); err == nil {
+ return errors.Errorf("pod id file exists. ensure another pod is not using it or delete %s", c.String("pod-id-file"))
+ }
+ if err = libpod.WriteFile("", c.String("pod-id-file")); err != nil {
+ return errors.Wrapf(err, "unable to write pod id file %s", c.String("pod-id-file"))
+ }
+ }
+
+ if c.IsSet("cgroup-parent") {
+ options = append(options, libpod.WithPodCgroupParent(c.String("cgroup-parent")))
+ }
+
+ labels, err := getAllLabels(c.StringSlice("label-file"), c.StringSlice("label"))
+ if err != nil {
+ return errors.Wrapf(err, "unable to process labels")
+ }
+ if len(labels) != 0 {
+ options = append(options, libpod.WithPodLabels(labels))
+ }
+
+ if c.IsSet("name") {
+ options = append(options, libpod.WithPodName(c.String("name")))
+ }
+
+ // always have containers use pod cgroups
+ options = append(options, libpod.WithPodCgroups())
+
+ pod, err := runtime.NewPod(options...)
+ if err != nil {
+ return err
+ }
+
+ if c.IsSet("pod-id-file") {
+ err = libpod.WriteFile(pod.ID(), c.String("pod-id-file"))
+ if err != nil {
+ logrus.Error(err)
+ }
+ }
+
+ fmt.Printf("%s\n", pod.ID())
+
+ return nil
+}
diff --git a/cmd/podman/pod_ps.go b/cmd/podman/pod_ps.go
new file mode 100644
index 000000000..470810901
--- /dev/null
+++ b/cmd/podman/pod_ps.go
@@ -0,0 +1,600 @@
+package main
+
+import (
+ "reflect"
+ "sort"
+ "strconv"
+ "strings"
+ "time"
+
+ "github.com/docker/go-units"
+ "github.com/pkg/errors"
+ "github.com/projectatomic/libpod/cmd/podman/batchcontainer"
+ "github.com/projectatomic/libpod/cmd/podman/formats"
+ "github.com/projectatomic/libpod/cmd/podman/libpodruntime"
+ "github.com/projectatomic/libpod/libpod"
+ "github.com/projectatomic/libpod/pkg/util"
+ "github.com/urfave/cli"
+)
+
+const (
+ STOPPED = "Stopped"
+ RUNNING = "Running"
+ PAUSED = "Paused"
+ EXITED = "Exited"
+ ERROR = "Error"
+ CREATED = "Created"
+ NUM_CTR_INFO = 10
+)
+
+var (
+ bc_opts batchcontainer.PsOptions
+)
+
+type podPsCtrInfo struct {
+ Name string `"json:name,omitempty"`
+ Id string `"json:id,omitempty"`
+ Status string `"json:status,omitempty"`
+}
+
+type podPsOptions struct {
+ NoTrunc bool
+ Format string
+ Sort string
+ Quiet bool
+ NumberOfContainers bool
+ Cgroup bool
+ NamesOfContainers bool
+ IdsOfContainers bool
+ StatusOfContainers bool
+}
+
+type podPsTemplateParams struct {
+ Created string
+ ID string
+ Name string
+ NumberOfContainers int
+ Status string
+ Cgroup string
+ UsePodCgroup bool
+ ContainerInfo string
+}
+
+// podPsJSONParams is used as a base structure for the psParams
+// If template output is requested, podPsJSONParams will be converted to
+// podPsTemplateParams.
+// podPsJSONParams will be populated by data from libpod.Container,
+// the members of the struct are the sama data types as their sources.
+type podPsJSONParams struct {
+ CreatedAt time.Time `json:"createdAt"`
+ ID string `json:"id"`
+ Name string `json:"name"`
+ NumberOfContainers int `json:"numberofcontainers"`
+ Status string `json:"status"`
+ CtrsInfo []podPsCtrInfo `json:"containerinfo,omitempty"`
+ Cgroup string `json:"cgroup,omitempty"`
+ UsePodCgroup bool `json:"podcgroup,omitempty"`
+}
+
+// Type declaration and functions for sorting the pod PS output
+type podPsSorted []podPsJSONParams
+
+func (a podPsSorted) Len() int { return len(a) }
+func (a podPsSorted) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
+
+type podPsSortedCreated struct{ podPsSorted }
+
+func (a podPsSortedCreated) Less(i, j int) bool {
+ return a.podPsSorted[i].CreatedAt.After(a.podPsSorted[j].CreatedAt)
+}
+
+type podPsSortedId struct{ podPsSorted }
+
+func (a podPsSortedId) Less(i, j int) bool { return a.podPsSorted[i].ID < a.podPsSorted[j].ID }
+
+type podPsSortedNumber struct{ podPsSorted }
+
+func (a podPsSortedNumber) Less(i, j int) bool {
+ return len(a.podPsSorted[i].CtrsInfo) < len(a.podPsSorted[j].CtrsInfo)
+}
+
+type podPsSortedName struct{ podPsSorted }
+
+func (a podPsSortedName) Less(i, j int) bool { return a.podPsSorted[i].Name < a.podPsSorted[j].Name }
+
+type podPsSortedStatus struct{ podPsSorted }
+
+func (a podPsSortedStatus) Less(i, j int) bool {
+ return a.podPsSorted[i].Status < a.podPsSorted[j].Status
+}
+
+var (
+ podPsFlags = []cli.Flag{
+ cli.BoolFlag{
+ Name: "cgroup",
+ Usage: "Print the Cgroup information of the pod",
+ },
+ cli.BoolFlag{
+ Name: "ctr-names",
+ Usage: "Display the container names",
+ },
+ cli.BoolFlag{
+ Name: "ctr-ids",
+ Usage: "Display the container UUIDs. If no-trunc is not set they will be truncated",
+ },
+ cli.BoolFlag{
+ Name: "ctr-status",
+ Usage: "Display the container status",
+ },
+ cli.StringFlag{
+ Name: "filter, f",
+ Usage: "Filter output based on conditions given",
+ },
+ cli.StringFlag{
+ Name: "format",
+ Usage: "Pretty-print pods to JSON or using a Go template",
+ },
+ cli.BoolFlag{
+ Name: "latest, l",
+ Usage: "Show the latest pod created",
+ },
+ cli.BoolFlag{
+ Name: "no-trunc",
+ Usage: "Do not truncate pod and container IDs",
+ },
+ cli.BoolFlag{
+ Name: "quiet, q",
+ Usage: "Print the numeric IDs of the pods only",
+ },
+ cli.StringFlag{
+ Name: "sort",
+ Usage: "Sort output by created, id, name, or number",
+ Value: "created",
+ },
+ }
+ podPsDescription = "List all pods on system including their names, ids and current state."
+ podPsCommand = cli.Command{
+ Name: "ps",
+ Aliases: []string{"ls", "list"},
+ Usage: "List pods",
+ Description: podPsDescription,
+ Flags: podPsFlags,
+ Action: podPsCmd,
+ UseShortOptionHandling: true,
+ }
+)
+
+func podPsCmd(c *cli.Context) error {
+ if err := validateFlags(c, podPsFlags); err != nil {
+ return err
+ }
+
+ if err := podPsCheckFlagsPassed(c); err != nil {
+ return errors.Wrapf(err, "error with flags passed")
+ }
+
+ runtime, err := libpodruntime.GetRuntime(c)
+ if err != nil {
+ return errors.Wrapf(err, "error creating libpod runtime")
+ }
+ defer runtime.Shutdown(false)
+
+ if len(c.Args()) > 0 {
+ return errors.Errorf("too many arguments, ps takes no arguments")
+ }
+
+ opts := podPsOptions{
+ NoTrunc: c.Bool("no-trunc"),
+ Quiet: c.Bool("quiet"),
+ Sort: c.String("sort"),
+ IdsOfContainers: c.Bool("ctr-ids"),
+ NamesOfContainers: c.Bool("ctr-names"),
+ StatusOfContainers: c.Bool("ctr-status"),
+ }
+
+ opts.Format = genPodPsFormat(c)
+
+ var filterFuncs []libpod.PodFilter
+ if c.String("filter") != "" {
+ filters := strings.Split(c.String("filter"), ",")
+ for _, f := range filters {
+ filterSplit := strings.Split(f, "=")
+ if len(filterSplit) < 2 {
+ return errors.Errorf("filter input must be in the form of filter=value: %s is invalid", f)
+ }
+ generatedFunc, err := generatePodFilterFuncs(filterSplit[0], filterSplit[1], runtime)
+ if err != nil {
+ return errors.Wrapf(err, "invalid filter")
+ }
+ filterFuncs = append(filterFuncs, generatedFunc)
+ }
+ }
+
+ var pods []*libpod.Pod
+ if c.IsSet("latest") {
+ pod, err := runtime.GetLatestPod()
+ if err != nil {
+ return err
+ }
+ pods = append(pods, pod)
+ } else {
+ pods, err = runtime.GetAllPods()
+ if err != nil {
+ return err
+ }
+ }
+
+ podsFiltered := make([]*libpod.Pod, 0, len(pods))
+ for _, pod := range pods {
+ include := true
+ for _, filter := range filterFuncs {
+ include = include && filter(pod)
+ }
+
+ if include {
+ podsFiltered = append(podsFiltered, pod)
+ }
+ }
+
+ return generatePodPsOutput(podsFiltered, opts, runtime)
+}
+
+// podPsCheckFlagsPassed checks if mutually exclusive flags are passed together
+func podPsCheckFlagsPassed(c *cli.Context) error {
+ // quiet, and format with Go template are mutually exclusive
+ flags := 0
+ if c.Bool("quiet") {
+ flags++
+ }
+ if c.IsSet("format") && c.String("format") != formats.JSONString {
+ flags++
+ }
+ if flags > 1 {
+ return errors.Errorf("quiet and format with Go template are mutually exclusive")
+ }
+ return nil
+}
+
+func generatePodFilterFuncs(filter, filterValue string, runtime *libpod.Runtime) (func(pod *libpod.Pod) bool, error) {
+ switch filter {
+ case "ctr-ids":
+ return func(p *libpod.Pod) bool {
+ ctrIds, err := p.AllContainersByID()
+ if err != nil {
+ return false
+ }
+ return util.StringInSlice(filterValue, ctrIds)
+ }, nil
+ case "ctr-names":
+ return func(p *libpod.Pod) bool {
+ ctrs, err := p.AllContainers()
+ if err != nil {
+ return false
+ }
+ for _, ctr := range ctrs {
+ if filterValue == ctr.Name() {
+ return true
+ }
+ }
+ return false
+ }, nil
+ case "ctr-number":
+ return func(p *libpod.Pod) bool {
+ ctrIds, err := p.AllContainersByID()
+ if err != nil {
+ return false
+ }
+
+ fVint, err2 := strconv.Atoi(filterValue)
+ if err2 != nil {
+ return false
+ }
+ return len(ctrIds) == fVint
+ }, nil
+ case "ctr-status":
+ if !util.StringInSlice(filterValue, []string{"created", "restarting", "running", "paused", "exited", "unknown"}) {
+ return nil, errors.Errorf("%s is not a valid status", filterValue)
+ }
+ return func(p *libpod.Pod) bool {
+ ctrs, err := p.AllContainers()
+ if err != nil {
+ return false
+ }
+ for _, ctr := range ctrs {
+ status, err := ctr.State()
+ if err != nil {
+ return false
+ }
+ state := status.String()
+ if status == libpod.ContainerStateConfigured {
+ state = "created"
+ }
+ if state == filterValue {
+ return true
+ }
+ }
+ return false
+ }, nil
+ case "id":
+ return func(p *libpod.Pod) bool {
+ return strings.Contains(p.ID(), filterValue)
+ }, nil
+ case "name":
+ return func(p *libpod.Pod) bool {
+ return strings.Contains(p.Name(), filterValue)
+ }, nil
+ case "status":
+ if !util.StringInSlice(filterValue, []string{"stopped", "running", "paused", "exited", "dead", "created"}) {
+ return nil, errors.Errorf("%s is not a valid pod status", filterValue)
+ }
+ return func(p *libpod.Pod) bool {
+ ctrs, err := p.AllContainers()
+ if err != nil {
+ return false
+ }
+ status, err := getPodStatus(ctrs)
+ if err != nil {
+ return false
+ }
+ if strings.ToLower(status) == filterValue {
+ return true
+ }
+ return false
+ }, nil
+ }
+ return nil, errors.Errorf("%s is an invalid filter", filter)
+}
+
+// generate the template based on conditions given
+func genPodPsFormat(c *cli.Context) string {
+ format := ""
+ if c.String("format") != "" {
+ // "\t" from the command line is not being recognized as a tab
+ // replacing the string "\t" to a tab character if the user passes in "\t"
+ format = strings.Replace(c.String("format"), `\t`, "\t", -1)
+ } else if c.Bool("quiet") {
+ format = formats.IDString
+ } else {
+ format = "table {{.ID}}\t{{.Name}}\t{{.Status}}\t{{.Created}}"
+ if c.Bool("cgroup") {
+ format += "\t{{.Cgroup}}\t{{.UsePodCgroup}}"
+ }
+ if c.Bool("ctr-names") || c.Bool("ctr-ids") || c.Bool("ctr-status") {
+ format += "\t{{.ContainerInfo}}"
+ } else {
+ format += "\t{{.NumberOfContainers}}"
+ }
+ }
+ return format
+}
+
+func podPsToGeneric(templParams []podPsTemplateParams, JSONParams []podPsJSONParams) (genericParams []interface{}) {
+ if len(templParams) > 0 {
+ for _, v := range templParams {
+ genericParams = append(genericParams, interface{}(v))
+ }
+ return
+ }
+ for _, v := range JSONParams {
+ genericParams = append(genericParams, interface{}(v))
+ }
+ return
+}
+
+// generate the accurate header based on template given
+func (p *podPsTemplateParams) podHeaderMap() map[string]string {
+ v := reflect.Indirect(reflect.ValueOf(p))
+ values := make(map[string]string)
+
+ for i := 0; i < v.NumField(); i++ {
+ key := v.Type().Field(i).Name
+ value := key
+ if value == "ID" {
+ value = "Pod" + value
+ }
+ values[key] = strings.ToUpper(splitCamelCase(value))
+ }
+ return values
+}
+
+func sortPodPsOutput(sortBy string, psOutput podPsSorted) (podPsSorted, error) {
+ switch sortBy {
+ case "created":
+ sort.Sort(podPsSortedCreated{psOutput})
+ case "id":
+ sort.Sort(podPsSortedId{psOutput})
+ case "name":
+ sort.Sort(podPsSortedName{psOutput})
+ case "number":
+ sort.Sort(podPsSortedNumber{psOutput})
+ case "status":
+ sort.Sort(podPsSortedStatus{psOutput})
+ default:
+ return nil, errors.Errorf("invalid option for --sort, options are: id, names, or number")
+ }
+ return psOutput, nil
+}
+
+// getPodTemplateOutput returns the modified container information
+func getPodTemplateOutput(psParams []podPsJSONParams, opts podPsOptions) ([]podPsTemplateParams, error) {
+ var (
+ psOutput []podPsTemplateParams
+ )
+
+ for _, psParam := range psParams {
+ podID := psParam.ID
+ var ctrStr string
+
+ truncated := ""
+ if !opts.NoTrunc {
+ podID = shortID(podID)
+ if len(psParam.CtrsInfo) > NUM_CTR_INFO {
+ psParam.CtrsInfo = psParam.CtrsInfo[:NUM_CTR_INFO]
+ truncated = "..."
+ }
+ }
+ for _, ctrInfo := range psParam.CtrsInfo {
+ ctrStr += "[ "
+ if opts.IdsOfContainers {
+ if opts.NoTrunc {
+ ctrStr += ctrInfo.Id
+ } else {
+ ctrStr += shortID(ctrInfo.Id)
+ }
+ }
+ if opts.NamesOfContainers {
+ ctrStr += ctrInfo.Name + " "
+ }
+ if opts.StatusOfContainers {
+ ctrStr += ctrInfo.Status + " "
+ }
+ ctrStr += "] "
+ }
+ ctrStr += truncated
+ params := podPsTemplateParams{
+ Created: units.HumanDuration(time.Since(psParam.CreatedAt)) + " ago",
+ ID: podID,
+ Name: psParam.Name,
+ Status: psParam.Status,
+ NumberOfContainers: psParam.NumberOfContainers,
+ UsePodCgroup: psParam.UsePodCgroup,
+ Cgroup: psParam.Cgroup,
+ ContainerInfo: ctrStr,
+ }
+
+ psOutput = append(psOutput, params)
+ }
+
+ return psOutput, nil
+}
+
+func getPodStatus(ctrs []*libpod.Container) (string, error) {
+ ctrNum := len(ctrs)
+ if ctrNum == 0 {
+ return CREATED, nil
+ }
+ statuses := map[string]int{
+ STOPPED: 0,
+ RUNNING: 0,
+ PAUSED: 0,
+ CREATED: 0,
+ ERROR: 0,
+ }
+ for _, ctr := range ctrs {
+ state, err := ctr.State()
+ if err != nil {
+ return "", err
+ }
+ switch state {
+ case libpod.ContainerStateStopped:
+ statuses[STOPPED]++
+ case libpod.ContainerStateRunning:
+ statuses[RUNNING]++
+ case libpod.ContainerStatePaused:
+ statuses[PAUSED]++
+ case libpod.ContainerStateCreated, libpod.ContainerStateConfigured:
+ statuses[CREATED]++
+ default:
+ statuses[ERROR]++
+ }
+ }
+
+ if statuses[RUNNING] > 0 {
+ return RUNNING, nil
+ } else if statuses[PAUSED] == ctrNum {
+ return PAUSED, nil
+ } else if statuses[STOPPED] == ctrNum {
+ return EXITED, nil
+ } else if statuses[STOPPED] > 0 {
+ return STOPPED, nil
+ } else if statuses[ERROR] > 0 {
+ return ERROR, nil
+ } else {
+ return CREATED, nil
+ }
+}
+
+// getAndSortPodJSONOutput returns the container info in its raw, sorted form
+func getAndSortPodJSONParams(pods []*libpod.Pod, opts podPsOptions, runtime *libpod.Runtime) ([]podPsJSONParams, error) {
+ var (
+ psOutput []podPsJSONParams
+ )
+
+ for _, pod := range pods {
+ ctrs, err := pod.AllContainers()
+ ctrsInfo := make([]podPsCtrInfo, 0)
+ if err != nil {
+ return nil, err
+ }
+ ctrNum := len(ctrs)
+ status, err := getPodStatus(ctrs)
+ if err != nil {
+ return nil, err
+ }
+
+ for _, ctr := range ctrs {
+ batchInfo, err := batchcontainer.BatchContainerOp(ctr, bc_opts)
+ if err != nil {
+ return nil, err
+ }
+ var status string
+ switch batchInfo.ConState {
+ case libpod.ContainerStateStopped:
+ status = EXITED
+ case libpod.ContainerStateRunning:
+ status = RUNNING
+ case libpod.ContainerStatePaused:
+ status = PAUSED
+ case libpod.ContainerStateCreated, libpod.ContainerStateConfigured:
+ status = CREATED
+ default:
+ status = ERROR
+ }
+ ctrsInfo = append(ctrsInfo, podPsCtrInfo{
+ Name: batchInfo.ConConfig.Name,
+ Id: ctr.ID(),
+ Status: status,
+ })
+ }
+ params := podPsJSONParams{
+ CreatedAt: pod.CreatedTime(),
+ ID: pod.ID(),
+ Name: pod.Name(),
+ Status: status,
+ Cgroup: pod.CgroupParent(),
+ UsePodCgroup: pod.UsePodCgroup(),
+ NumberOfContainers: ctrNum,
+ CtrsInfo: ctrsInfo,
+ }
+
+ psOutput = append(psOutput, params)
+ }
+ return sortPodPsOutput(opts.Sort, psOutput)
+}
+
+func generatePodPsOutput(pods []*libpod.Pod, opts podPsOptions, runtime *libpod.Runtime) error {
+ if len(pods) == 0 && opts.Format != formats.JSONString {
+ return nil
+ }
+ psOutput, err := getAndSortPodJSONParams(pods, opts, runtime)
+ if err != nil {
+ return err
+ }
+ var out formats.Writer
+
+ switch opts.Format {
+ case formats.JSONString:
+ if err != nil {
+ return errors.Wrapf(err, "unable to create JSON for output")
+ }
+ out = formats.JSONStructArray{Output: podPsToGeneric([]podPsTemplateParams{}, psOutput)}
+ default:
+ psOutput, err := getPodTemplateOutput(psOutput, opts)
+ if err != nil {
+ return errors.Wrapf(err, "unable to create output")
+ }
+ out = formats.StdoutTemplateArray{Output: podPsToGeneric(psOutput, []podPsJSONParams{}), Template: opts.Format, Fields: psOutput[0].podHeaderMap()}
+ }
+
+ return formats.Writer(out).Out()
+}
diff --git a/cmd/podman/pod_rm.go b/cmd/podman/pod_rm.go
new file mode 100644
index 000000000..8cc46761e
--- /dev/null
+++ b/cmd/podman/pod_rm.go
@@ -0,0 +1,103 @@
+package main
+
+import (
+ "fmt"
+ "os"
+
+ "github.com/pkg/errors"
+ "github.com/projectatomic/libpod/cmd/podman/libpodruntime"
+ "github.com/projectatomic/libpod/libpod"
+ "github.com/urfave/cli"
+)
+
+var (
+ podRmFlags = []cli.Flag{
+ cli.BoolFlag{
+ Name: "force, f",
+ Usage: "Force removal of a running pod by first stopping all containers, then removing all containers in the pod. The default is false",
+ },
+ cli.BoolFlag{
+ Name: "all, a",
+ Usage: "Remove all pods",
+ },
+ LatestFlag,
+ }
+ podRmDescription = "Remove one or more pods"
+ podRmCommand = cli.Command{
+ Name: "rm",
+ Usage: fmt.Sprintf(`podman rm will remove one or more pods from the host. The pod name or ID can be used.
+ A pod with containers will not be removed without --force.
+ If --force is specified, all containers will be stopped, then removed.`),
+ Description: podRmDescription,
+ Flags: podRmFlags,
+ Action: podRmCmd,
+ ArgsUsage: "[POD ...]",
+ UseShortOptionHandling: true,
+ }
+)
+
+// saveCmd saves the image to either docker-archive or oci
+func podRmCmd(c *cli.Context) error {
+ ctx := getContext()
+ if err := validateFlags(c, rmFlags); err != nil {
+ return err
+ }
+
+ if c.Bool("latest") && c.Bool("all") {
+ return errors.Errorf("--all and --latest cannot be used together")
+ }
+
+ runtime, err := libpodruntime.GetRuntime(c)
+ if err != nil {
+ return errors.Wrapf(err, "could not get runtime")
+ }
+ defer runtime.Shutdown(false)
+
+ args := c.Args()
+
+ if len(args) == 0 && !c.Bool("all") && !c.Bool("latest") {
+ return errors.Errorf("specify one or more pods to remove")
+ }
+
+ var delPods []*libpod.Pod
+ var lastError error
+ if c.IsSet("all") {
+ delPods, err = runtime.GetAllPods()
+ if err != nil {
+ return errors.Wrapf(err, "unable to get pod list")
+ }
+ } else if c.IsSet("latest") {
+ delPod, err := runtime.GetLatestPod()
+ if err != nil {
+ return errors.Wrapf(err, "unable to get latest pod")
+ }
+ delPods = append(delPods, delPod)
+ } else {
+ for _, i := range args {
+ pod, err := runtime.LookupPod(i)
+ if err != nil {
+ fmt.Fprintln(os.Stderr, err)
+ if lastError != nil {
+ fmt.Fprintln(os.Stderr, lastError)
+ }
+ lastError = errors.Wrapf(err, "unable to find pods %s", i)
+ continue
+ }
+ delPods = append(delPods, pod)
+ }
+ }
+ force := c.IsSet("force")
+
+ for _, pod := range delPods {
+ err = runtime.RemovePod(ctx, pod, force, force)
+ if err != nil {
+ if lastError != nil {
+ fmt.Fprintln(os.Stderr, lastError)
+ }
+ lastError = errors.Wrapf(err, "failed to delete pod %v", pod.ID())
+ } else {
+ fmt.Println(pod.ID())
+ }
+ }
+ return lastError
+}
diff --git a/cmd/podman/run.go b/cmd/podman/run.go
index 2964605f6..b126c9e73 100644
--- a/cmd/podman/run.go
+++ b/cmd/podman/run.go
@@ -172,6 +172,10 @@ func runCmd(c *cli.Context) error {
if c.IsSet("attach") || c.IsSet("a") {
outputStream = nil
errorStream = nil
+ if !c.Bool("interactive") {
+ inputStream = nil
+ }
+
inputStream = nil
attachTo := c.StringSlice("attach")
@@ -187,13 +191,7 @@ func runCmd(c *cli.Context) error {
return errors.Wrapf(libpod.ErrInvalidArg, "invalid stream %q for --attach - must be one of stdin, stdout, or stderr", stream)
}
}
-
- // If --interactive is set, restore stdin
- if c.Bool("interactive") {
- inputStream = os.Stdin
- }
}
-
if err := startAttachCtr(ctr, outputStream, errorStream, inputStream, c.String("detach-keys"), c.BoolT("sig-proxy"), true); err != nil {
// This means the command did not exist
exitCode = 127
@@ -203,7 +201,7 @@ func runCmd(c *cli.Context) error {
return err
}
- if ecode, err := ctr.ExitCode(); err != nil {
+ if ecode, err := ctr.Wait(); err != nil {
if errors.Cause(err) == libpod.ErrNoSuchCtr {
// The container may have been removed
// Go looking for an exit file
@@ -213,8 +211,6 @@ func runCmd(c *cli.Context) error {
} else {
exitCode = ctrExitCode
}
- } else {
- logrus.Errorf("Unable to get exit code of container %s: %q", ctr.ID(), err)
}
} else {
exitCode = int(ecode)
diff --git a/cmd/podman/sigproxy.go b/cmd/podman/sigproxy.go
index fd1415dc6..388e23439 100644
--- a/cmd/podman/sigproxy.go
+++ b/cmd/podman/sigproxy.go
@@ -25,6 +25,8 @@ func ProxySignals(ctr *libpod.Container) {
if err := ctr.Kill(uint(s.(syscall.Signal))); err != nil {
logrus.Errorf("Error forwarding signal %d to container %s: %v", s, ctr.ID(), err)
+ signal.StopCatch(sigBuffer)
+ syscall.Kill(syscall.Getpid(), s.(syscall.Signal))
}
}
}()
diff --git a/cmd/podman/start.go b/cmd/podman/start.go
index e917d9198..3dde306d7 100644
--- a/cmd/podman/start.go
+++ b/cmd/podman/start.go
@@ -114,7 +114,7 @@ func startCmd(c *cli.Context) error {
return errors.Wrapf(err, "unable to start container %s", ctr.ID())
}
- if ecode, err := ctr.ExitCode(); err != nil {
+ if ecode, err := ctr.Wait(); err != nil {
logrus.Errorf("unable to get exit code of container %s: %q", ctr.ID(), err)
} else {
exitCode = int(ecode)
diff --git a/completions/bash/podman b/completions/bash/podman
index c07987a86..b01a30aaa 100644
--- a/completions/bash/podman
+++ b/completions/bash/podman
@@ -31,6 +31,29 @@ __podman_containers() {
__podman_q ps --format "$format" "$@"
}
+
+# __podman_pods returns a list of pods. Additional options to
+# `podman pod ps` may be specified in order to filter the list, e.g.
+# `__podman_containers --filter status=running`
+# By default, only names are returned.
+# Set PODMAN_COMPLETION_SHOW_CONTAINER_IDS=yes to also complete IDs.
+# An optional first option `--id|--name` may be used to limit the
+# output to the IDs or names of matching items. This setting takes
+# precedence over the environment setting.
+__podman_pods() {
+ local format
+ if [ "$1" = "--id" ] ; then
+ format='{{.ID}}'
+ shift
+ elif [ "$1" = "--name" ] ; then
+ format='{{.Names}}'
+ shift
+ else
+ format='{{.Names}}'
+ fi
+ __podman_q pod ps --format "$format" "$@"
+}
+
# __podman_complete_containers applies completion of containers based on the current
# value of `$cur` or the value of the optional first option `--cur`, if given.
# Additional filters may be appended, see `__podman_containers`.
@@ -43,6 +66,23 @@ __podman_complete_containers() {
COMPREPLY=( $(compgen -W "$(__podman_containers "$@")" -- "$current") )
}
+# __podman_complete_pods applies completion of pods based on the current
+# value of `$cur` or the value of the optional first option `--cur`, if given.
+# Additional filters may be appended, see `__podman_pods`.
+__podman_complete_pods() {
+ local current="$cur"
+ if [ "$1" = "--cur" ] ; then
+ current="$2"
+ shift 2
+ fi
+ COMPREPLY=( $(compgen -W "$(__podman_pods "$@")" -- "$current") )
+}
+
+__podman_complete_pod_names() {
+ local names=( $(__podman_q pod ps --format={{.Name}}) )
+ COMPREPLY=( $(compgen -W "${names[*]}" -- "$cur") )
+}
+
__podman_complete_containers_all() {
__podman_complete_containers "$@" --all
}
@@ -1662,10 +1702,12 @@ _podman_container_run() {
esac
}
+
_podman_create() {
_podman_container_run
}
+
_podman_run() {
_podman_container_run
}
@@ -2013,6 +2055,105 @@ _podman_logout() {
_complete_ "$options_with_args" "$boolean_options"
}
+_podman_pod_create() {
+ local options_with_args="
+ --cgroup-parent
+ --podidfile
+ --label-file
+ --label
+ -l
+ --name
+ "
+
+ local boolean_options="
+ "
+ _complete_ "$options_with_args" "$boolean_options"
+}
+
+__podman_pod_ps() {
+ local options_with_args="
+ -f
+ --filter
+ --format
+ --sort
+ "
+
+ local boolean_options="
+ --cgroup
+ --ctr-ids
+ --ctr-names
+ --ctr-status
+ -q
+ --quiet
+ --no-trunc
+ --labels
+ -l
+ --latest
+ "
+ _complete_ "$options_with_args" "$boolean_options"
+}
+
+_podman_pod_ls() {
+ __podman_pod_ps
+}
+
+_podman_pod_list() {
+ __podman_pod_ps
+}
+
+_podman_pod_ps() {
+ __podman_pod_ps
+}
+
+_podman_pod_rm() {
+ local options_with_args="
+ "
+
+ local boolean_options="
+ -a
+ --all
+ -f
+ --force
+ --latest
+ -l
+ "
+ _complete_ "$options_with_args" "$boolean_options"
+ case "$cur" in
+ -*)
+ COMPREPLY=($(compgen -W "$boolean_options $options_with_args" -- "$cur"))
+ ;;
+ *)
+ __podman_complete_pod_names
+ ;;
+ esac
+}
+
+_podman_pod() {
+ local boolean_options="
+ --help
+ -h
+ "
+ subcommands="
+ create
+ ps
+ rm
+ "
+ local aliases="
+ list
+ ls
+ "
+ __podman_subcommands "$subcommands $aliases" && return
+
+ case "$cur" in
+ -*)
+ COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
+ ;;
+ *)
+ COMPREPLY=( $( compgen -W "$subcommands" -- "$cur" ) )
+ ;;
+ esac
+}
+
_podman_podman() {
local options_with_args="
--config -c
@@ -2049,6 +2190,7 @@ _podman_podman() {
logs
mount
pause
+ pod
port
ps
pull
diff --git a/docs/podman-pod-create.1.md b/docs/podman-pod-create.1.md
new file mode 100644
index 000000000..495c6934a
--- /dev/null
+++ b/docs/podman-pod-create.1.md
@@ -0,0 +1,60 @@
+% podman-pod-create "1"
+
+## NAME
+podman\-pod\-create - Create a new pod
+
+## SYNOPSIS
+**podman pod create** [*options*]
+
+## DESCRIPTION
+
+Creates an empty pod, or unit of multiple containers, and prepares it to have
+containers added to it. The pod id is printed to STDOUT. You can then use
+**podman create --pod <pod_id|pod_name> ...** to add containers to the pod, and
+**podman pod start <pod_id|pod_name>** to start the pod.
+
+## OPTIONS
+
+**--cgroup-parent**=*true*|*false*
+
+Path to cgroups under which the cgroup for the pod will be created. If the path is not absolute, the path is considered to be relative to the cgroups path of the init process. Cgroups will be created if they do not already exist.
+
+**--podidfile**=""
+
+Write the pod ID to the file
+
+**--help**
+
+Print usage statement
+
+**-l**, **--label**=[]
+
+Add metadata to a pod (e.g., --label com.example.key=value)
+
+**--label-file**=[]
+
+Read in a line delimited file of labels
+
+**-n**, **--name**=""
+
+Assign a name to the pod
+
+The operator can identify a pod in three ways:
+UUID long identifier (“f78375b1c487e03c9438c729345e54db9d20cfa2ac1fc3494b6eb60872e74778”)
+UUID short identifier (“f78375b1c487”)
+Name (“jonah”)
+
+podman generates a UUID for each pod, and if a name is not assigned
+to the container with **--name** then a random string name will be generated
+for it. The name is useful any place you need to identify a pod.
+
+## EXAMPLES
+
+
+# podman pod create --name test
+
+## SEE ALSO
+podman-pod(1)
+
+## HISTORY
+July 2018, Originally compiled by Peter Hunt <pehunt@redhat.com>
diff --git a/docs/podman-pod-ps.1.md b/docs/podman-pod-ps.1.md
new file mode 100644
index 000000000..1fdbe2935
--- /dev/null
+++ b/docs/podman-pod-ps.1.md
@@ -0,0 +1,165 @@
+% podman-pod-ps "1"
+
+## NAME
+podman\-pod\-ps - Prints out information about pods
+
+## SYNOPSIS
+**podman pod ps** [*options*]
+
+## DESCRIPTION
+**podman pod ps** lists the pods on the system.
+By default it lists:
+
+ * pod id
+ * pod name
+ * number of containers attached to pod
+ * status of pod as defined by the following table
+
+| **Status** | **Description** |
+| ------------ | ------------------------------------------------|
+| Created | No containers running nor stopped |
+| Running | at least one container is running |
+| Stopped | At least one container stopped and none running |
+| Exited | All containers stopped in pod |
+| Dead | Error retrieving state |
+
+
+## OPTIONS
+
+**--ctr-names**
+
+Includes the container names in the container info field
+
+**--ctr-ids**
+
+Includes the container IDs in the container info field
+
+**--ctr-status**
+
+Includes the container statuses in the container info field
+
+**--latest, -l**
+
+Show the latest pod created (all states)
+
+**--no-trunc**
+
+Display the extended information
+
+**--quiet, -q**
+
+Print the numeric IDs of the pods only
+
+**--format**
+
+Pretty-print containers to JSON or using a Go template
+
+Valid placeholders for the Go template are listed below:
+
+| **Placeholder** | **Description** |
+| ------------------- | ----------------------------------------------------------------------------------------------- |
+| .ID | Container ID |
+| .Name | Name of pod |
+| .Status | Status of pod |
+| .Labels | All the labels assigned to the pod |
+| .ContainerInfo | Show the names, ids and/or statuses of containers (only shows 9 unless no-trunc is specified) |
+| .NumberOfContainers | Show the number of containers attached to pod |
+| .Cgroup | Cgroup path of pod |
+| .UsePodCgroup | Whether containers use the Cgroup of the pod |
+
+**--sort**
+
+Sort by created, ID, name, status, or number of containers
+
+Default: created
+
+**--filter, -f**
+
+Filter output based on conditions given
+
+Valid filters are listed below:
+
+| **Filter** | **Description** |
+| --------------- | ------------------------------------------------------------------- |
+| id | [ID] Pod's ID |
+| name | [Name] Pod's name |
+| label | [Key] or [Key=Value] Label assigned to a container |
+| ctr-names | Container name within the pod |
+| ctr-ids | Container ID within the pod |
+| ctr-status | Container status within the pod |
+| ctr-number | Number of containers in the pod |
+
+**--help**, **-h**
+
+Print usage statement
+
+## EXAMPLES
+
+```
+sudo podman pod ps
+POD ID NAME STATUS NUMBER OF CONTAINERS
+00dfd6fa02c0 jolly_goldstine Running 1
+f4df8692e116 nifty_torvalds Created 2
+```
+
+```
+sudo podman pod ps --ctr-names
+POD ID NAME STATUS CONTAINER INFO
+00dfd6fa02c0 jolly_goldstine Running [ loving_archimedes ]
+f4df8692e116 nifty_torvalds Created [ thirsty_hawking ] [ wizardly_golick ]
+```
+
+```
+podman pod ps --ctr-status --ctr-names --ctr-ids
+POD ID NAME STATUS CONTAINER INFO
+00dfd6fa02c0 jolly_goldstine Running [ ba465ab0a3a4 loving_archimedes Running ]
+f4df8692e116 nifty_torvalds Created [ 331693bff40a thirsty_hawking Created ] [ 8e428daeb89e wizardly_golick Created ]
+```
+
+```
+sudo podman pod ps --format "{{.ID}} {{.ContainerInfo}} {{.Cgroup}}" --ctr-names
+00dfd6fa02c0 [ loving_archimedes ] /libpod_parent
+f4df8692e116 [ thirsty_hawking ] [ wizardly_golick ] /libpod_parent
+```
+
+```
+sudo podman pod ps --cgroup
+POD ID NAME STATUS NUMBER OF CONTAINERS CGROUP USE POD CGROUP
+00dfd6fa02c0 jolly_goldstine Running 1 /libpod_parent true
+f4df8692e116 nifty_torvalds Created 2 /libpod_parent true
+```
+
+```
+podman pod ps --sort id --filter ctr-number=2
+POD ID NAME STATUS NUMBER OF CONTAINERS
+f4df8692e116 nifty_torvalds Created 2
+```
+
+```
+sudo podman pod ps --ctr-ids
+POD ID NAME STATUS CONTAINER INFO
+00dfd6fa02c0 jolly_goldstine Running [ ba465ab0a3a4 ]
+f4df8692e116 nifty_torvalds Created [ 331693bff40a ] [ 8e428daeb89e ]
+```
+
+```
+sudo podman pod ps --no-trunc --ctr-ids
+POD ID NAME STATUS CONTAINER INFO
+00dfd6fa02c0a2daaedfdf8fcecd06f22ad114d46d167d71777224735f701866 jolly_goldstine Running [ ba465ab0a3a4e15e3539a1e79c32d1213a02b0989371e274f98e0f1ae9de7050 ]
+f4df8692e116a3e6d1d62572644ed36ca475d933808cc3c93435c45aa139314b nifty_torvalds Created [ 331693bff40a0ef2f05a3aba73ce49e3243108911927fff04d1f7fc44dda8022 ] [ 8e428daeb89e69b71e7916a13accfb87d122889442b5c05c2d99cf94a3230e9d ]
+```
+
+```
+podman pod ps --ctr-names
+POD ID NAME STATUS CONTAINER INFO
+314f4da82d74 hi Created [ jovial_jackson ] [ hopeful_archimedes ] [ vibrant_ptolemy ] [ heuristic_jennings ] [ keen_raman ] [ hopeful_newton ] [ mystifying_bose ] [ silly_lalande ] [ serene_lichterman ] ...
+```
+
+## pod ps
+Print a list of pods
+
+## SEE ALSO
+podman-pod(1)
+
+## HISTORY
+July 2018, Originally compiled by Peter Hunt <pehunt@redhat.com>
diff --git a/docs/podman-pod-rm.1.md b/docs/podman-pod-rm.1.md
new file mode 100644
index 000000000..3b571ee9a
--- /dev/null
+++ b/docs/podman-pod-rm.1.md
@@ -0,0 +1,42 @@
+% podman-pod-rm "1"
+
+## NAME
+podman\-pod\-rm - Remove one or more pods
+
+## SYNOPSIS
+**podman pod rm** [*options*] *pod*
+
+## DESCRIPTION
+**podman pod rm** will remove one or more pods from the host. The pod name or ID can be used. The \-f option stops all containers and then removes them before removing the pod. Without the \-f option, a pod cannot be removed if it has associated containers.
+
+## OPTIONS
+
+**--all, a**
+
+Remove all pods. Can be used in conjunction with \-f as well.
+
+**--latest, -l**
+
+Instead of providing the pod name or ID, use the last created pod.
+
+**--force, f**
+
+Stop running containers and delete all stopped containers before removal of pod.
+
+## EXAMPLE
+
+podman pod rm mywebserverpod
+
+podman pod rm mywebserverpod myflaskserverpod 860a4b23
+
+podman pod rm -f 860a4b23
+
+podman pod rm -f -a
+
+podman pod rm -fa
+
+## SEE ALSO
+podman-pod(1)
+
+## HISTORY
+July 2018, Originally compiled by Peter Hunt <pehunt@redhat.com>
diff --git a/docs/podman-pod.1.md b/docs/podman-pod.1.md
new file mode 100644
index 000000000..511a5841f
--- /dev/null
+++ b/docs/podman-pod.1.md
@@ -0,0 +1,21 @@
+% podman-pod "1"
+
+## NAME
+podman\-pod - Simple management tool for groups of containers, called pods.
+
+## SYNOPSIS
+**podman pod** *subcommand*
+
+# DESCRIPTION
+podman pod is a set of subcommands that manage pods, or groups of containers.
+
+## SUBCOMMANDS
+
+| Subcommand | Description |
+| ------------------------------------------------- | ------------------------------------------------------------------------------ |
+| [podman-pod-create(1)](podman-pod-create.1.md) | Create a new pod. |
+| [podman-pod-ps(1)](podman-pod-ps.1.md) | Prints out information about pods. |
+| [podman-pod-rm(1)](podman-pod-rm.1.md) | Remove one or more pods. |
+
+## HISTORY
+July 2018, Originally compiled by Peter Hunt <pehunt@redhat.com>
diff --git a/libpod/oci.go b/libpod/oci.go
index 612935aed..c0478b3b6 100644
--- a/libpod/oci.go
+++ b/libpod/oci.go
@@ -180,6 +180,11 @@ func waitPidsStop(pids []int, timeout time.Duration) error {
func (r *OCIRuntime) createOCIContainer(ctr *Container, cgroupParent string) (err error) {
var stderrBuf bytes.Buffer
+ runtimeDir, err := GetRootlessRuntimeDir()
+ if err != nil {
+ return err
+ }
+
parentPipe, childPipe, err := newPipe()
if err != nil {
return errors.Wrapf(err, "error creating socket pair")
@@ -253,7 +258,7 @@ func (r *OCIRuntime) createOCIContainer(ctr *Container, cgroupParent string) (er
// 0, 1 and 2 are stdin, stdout and stderr
cmd.Env = append(r.conmonEnv, fmt.Sprintf("_OCI_SYNCPIPE=%d", 3))
cmd.Env = append(cmd.Env, fmt.Sprintf("_OCI_STARTPIPE=%d", 4))
- cmd.Env = append(cmd.Env, fmt.Sprintf("XDG_RUNTIME_DIR=%s", GetRootlessRuntimeDir()))
+ cmd.Env = append(cmd.Env, fmt.Sprintf("XDG_RUNTIME_DIR=%s", runtimeDir))
if notify, ok := os.LookupEnv("NOTIFY_SOCKET"); ok {
cmd.Env = append(cmd.Env, fmt.Sprintf("NOTIFY_SOCKET=%s", notify))
}
@@ -362,11 +367,16 @@ func (r *OCIRuntime) createOCIContainer(ctr *Container, cgroupParent string) (er
func (r *OCIRuntime) updateContainerStatus(ctr *Container) error {
state := new(spec.State)
+ runtimeDir, err := GetRootlessRuntimeDir()
+ if err != nil {
+ return err
+ }
+
// Store old state so we know if we were already stopped
oldState := ctr.state.State
cmd := exec.Command(r.path, "state", ctr.ID())
- cmd.Env = append(cmd.Env, fmt.Sprintf("XDG_RUNTIME_DIR=%s", GetRootlessRuntimeDir()))
+ cmd.Env = append(cmd.Env, fmt.Sprintf("XDG_RUNTIME_DIR=%s", runtimeDir))
out, err := cmd.CombinedOutput()
if err != nil {
@@ -556,6 +566,11 @@ func (r *OCIRuntime) execContainer(c *Container, cmd, capAdd, env []string, tty
return nil, errors.Wrapf(ErrEmptyID, "must provide a session ID for exec")
}
+ runtimeDir, err := GetRootlessRuntimeDir()
+ if err != nil {
+ return nil, err
+ }
+
args := []string{}
// TODO - should we maintain separate logpaths for exec sessions?
@@ -597,7 +612,7 @@ func (r *OCIRuntime) execContainer(c *Container, cmd, capAdd, env []string, tty
execCmd.Stdout = os.Stdout
execCmd.Stderr = os.Stderr
execCmd.Stdin = os.Stdin
- execCmd.Env = append(execCmd.Env, fmt.Sprintf("XDG_RUNTIME_DIR=%s", GetRootlessRuntimeDir()))
+ execCmd.Env = append(execCmd.Env, fmt.Sprintf("XDG_RUNTIME_DIR=%s", runtimeDir))
return execCmd, nil
}
diff --git a/libpod/runtime.go b/libpod/runtime.go
index 9ba6acb78..a551c9134 100644
--- a/libpod/runtime.go
+++ b/libpod/runtime.go
@@ -1,7 +1,6 @@
package libpod
import (
- "bytes"
"fmt"
"io/ioutil"
"os"
@@ -170,7 +169,7 @@ var (
CgroupManager: CgroupfsCgroupsManager,
HooksDir: hooks.DefaultDir,
StaticDir: filepath.Join(storage.DefaultStoreOptions.GraphRoot, "libpod"),
- TmpDir: getDefaultTmpDir(),
+ TmpDir: "",
MaxLogSize: -1,
NoPivotRoot: false,
CNIConfigDir: "/etc/cni/net.d/",
@@ -179,7 +178,7 @@ var (
)
// GetRootlessRuntimeDir returns the runtime directory when running as non root
-func GetRootlessRuntimeDir() string {
+func GetRootlessRuntimeDir() (string, error) {
runtimeDir := os.Getenv("XDG_RUNTIME_DIR")
uid := fmt.Sprintf("%d", rootless.GetRootlessUID())
if runtimeDir == "" {
@@ -199,18 +198,29 @@ func GetRootlessRuntimeDir() string {
}
}
if runtimeDir == "" {
- runtimeDir = filepath.Join(os.Getenv("HOME"), "rundir")
+ home := os.Getenv("HOME")
+ if home == "" {
+ return "", fmt.Errorf("neither XDG_RUNTIME_DIR nor HOME was set non-empty")
+ }
+ resolvedHome, err := filepath.EvalSymlinks(home)
+ if err != nil {
+ return "", errors.Wrapf(err, "cannot resolve %s", home)
+ }
+ runtimeDir = filepath.Join(resolvedHome, "rundir")
}
- return runtimeDir
+ return runtimeDir, nil
}
-func getDefaultTmpDir() string {
+func getDefaultTmpDir() (string, error) {
if !rootless.IsRootless() {
- return "/var/run/libpod"
+ return "/var/run/libpod", nil
}
- rootlessRuntimeDir := GetRootlessRuntimeDir()
- return filepath.Join(rootlessRuntimeDir, "libpod", "tmp")
+ rootlessRuntimeDir, err := GetRootlessRuntimeDir()
+ if err != nil {
+ return "", err
+ }
+ return filepath.Join(rootlessRuntimeDir, "libpod", "tmp"), nil
}
// NewRuntime creates a new container runtime
@@ -220,7 +230,12 @@ func NewRuntime(options ...RuntimeOption) (runtime *Runtime, err error) {
runtime.config = new(RuntimeConfig)
// Copy the default configuration
+ tmpDir, err := getDefaultTmpDir()
+ if err != nil {
+ return nil, err
+ }
deepcopier.Copy(defaultRuntimeConfig).To(runtime.config)
+ runtime.config.TmpDir = tmpDir
configPath := ConfigPath
foundConfig := true
@@ -230,9 +245,14 @@ func NewRuntime(options ...RuntimeOption) (runtime *Runtime, err error) {
foundConfig = false
}
+ runtimeDir, err := GetRootlessRuntimeDir()
+ if err != nil {
+ return nil, err
+ }
+
// containers/image uses XDG_RUNTIME_DIR to locate the auth file.
// So make sure the env variable is set.
- err = os.Setenv("XDG_RUNTIME_DIR", GetRootlessRuntimeDir())
+ err = os.Setenv("XDG_RUNTIME_DIR", runtimeDir)
if err != nil {
return nil, errors.Wrapf(err, "cannot set XDG_RUNTIME_DIR")
}
@@ -675,18 +695,6 @@ func (r *Runtime) generateName() (string, error) {
// The code should never reach here.
}
-// SaveDefaultConfig saves a copy of the default config at the given path
-func SaveDefaultConfig(path string) error {
- var w bytes.Buffer
- e := toml.NewEncoder(&w)
-
- if err := e.Encode(&defaultRuntimeConfig); err != nil {
- return err
- }
-
- return ioutil.WriteFile(path, w.Bytes(), 0644)
-}
-
// ImageRuntime returns the imageruntime for image resolution
func (r *Runtime) ImageRuntime() *image.Runtime {
return r.imageRuntime
diff --git a/libpod/runtime_pod_linux.go b/libpod/runtime_pod_linux.go
index 35d095ba3..25340abdb 100644
--- a/libpod/runtime_pod_linux.go
+++ b/libpod/runtime_pod_linux.go
@@ -74,7 +74,7 @@ func (r *Runtime) NewPod(options ...PodCreateOption) (*Pod, error) {
return nil, errors.Wrapf(err, "error adding pod to state")
}
- return nil, ErrNotImplemented
+ return pod, nil
}
func (r *Runtime) removePod(ctx context.Context, p *Pod, removeCtrs, force bool) error {
diff --git a/pkg/rootless/rootless_linux.c b/pkg/rootless/rootless_linux.c
index 0c6b86161..465feeb57 100644
--- a/pkg/rootless/rootless_linux.c
+++ b/pkg/rootless/rootless_linux.c
@@ -105,16 +105,16 @@ reexec_in_user_namespace(int ready)
ret = read (ready, &b, 1) < 0;
while (ret < 0 && errno == EINTR);
if (ret < 0)
- _exit (1);
+ _exit (EXIT_FAILURE);
close (ready);
if (setresgid (0, 0, 0) < 0 ||
setresuid (0, 0, 0) < 0)
- _exit (1);
+ _exit (EXIT_FAILURE);
execvp (argv[0], argv);
- _exit (1);
+ _exit (EXIT_FAILURE);
}
int
diff --git a/pkg/rootless/rootless_linux.go b/pkg/rootless/rootless_linux.go
index 55a55bbc6..6089ad73a 100644
--- a/pkg/rootless/rootless_linux.go
+++ b/pkg/rootless/rootless_linux.go
@@ -67,14 +67,16 @@ func tryMappingTool(tool string, pid int, hostID int, mappings []idtools.IDMap)
return cmd.Run()
}
-// BecomeRootInUserNS re-exec podman in a new userNS
-func BecomeRootInUserNS() (bool, error) {
-
+// BecomeRootInUserNS re-exec podman in a new userNS. It returns whether podman was re-executed
+// into a new user namespace and the return code from the re-executed podman process.
+// If podman was re-executed the caller needs to propagate the error code returned by the child
+// process.
+func BecomeRootInUserNS() (bool, int, error) {
if os.Getuid() == 0 || os.Getenv("_LIBPOD_USERNS_CONFIGURED") != "" {
if os.Getenv("_LIBPOD_USERNS_CONFIGURED") == "init" {
- return false, runInUser()
+ return false, 0, runInUser()
}
- return false, nil
+ return false, 0, nil
}
runtime.LockOSThread()
@@ -82,7 +84,7 @@ func BecomeRootInUserNS() (bool, error) {
r, w, err := os.Pipe()
if err != nil {
- return false, err
+ return false, -1, err
}
defer r.Close()
defer w.Close()
@@ -90,13 +92,13 @@ func BecomeRootInUserNS() (bool, error) {
pidC := C.reexec_in_user_namespace(C.int(r.Fd()))
pid := int(pidC)
if pid < 0 {
- return false, errors.Errorf("cannot re-exec process")
+ return false, -1, errors.Errorf("cannot re-exec process")
}
setgroups := fmt.Sprintf("/proc/%d/setgroups", pid)
err = ioutil.WriteFile(setgroups, []byte("deny\n"), 0666)
if err != nil {
- return false, errors.Wrapf(err, "cannot write setgroups file")
+ return false, -1, errors.Wrapf(err, "cannot write setgroups file")
}
var uids, gids []idtools.IDMap
@@ -115,7 +117,7 @@ func BecomeRootInUserNS() (bool, error) {
uidMap := fmt.Sprintf("/proc/%d/uid_map", pid)
err = ioutil.WriteFile(uidMap, []byte(fmt.Sprintf("%d %d 1\n", 0, os.Getuid())), 0666)
if err != nil {
- return false, errors.Wrapf(err, "cannot write uid_map")
+ return false, -1, errors.Wrapf(err, "cannot write uid_map")
}
}
@@ -127,13 +129,13 @@ func BecomeRootInUserNS() (bool, error) {
gidMap := fmt.Sprintf("/proc/%d/gid_map", pid)
err = ioutil.WriteFile(gidMap, []byte(fmt.Sprintf("%d %d 1\n", 0, os.Getgid())), 0666)
if err != nil {
- return false, errors.Wrapf(err, "cannot write gid_map")
+ return false, -1, errors.Wrapf(err, "cannot write gid_map")
}
}
_, err = w.Write([]byte("1"))
if err != nil {
- return false, errors.Wrapf(err, "write to sync pipe")
+ return false, -1, errors.Wrapf(err, "write to sync pipe")
}
c := make(chan os.Signal, 1)
@@ -150,9 +152,10 @@ func BecomeRootInUserNS() (bool, error) {
}
}()
- if C.reexec_in_user_namespace_wait(pidC) < 0 {
- return false, errors.Wrapf(err, "error waiting for the re-exec process")
+ ret := C.reexec_in_user_namespace_wait(pidC)
+ if ret < 0 {
+ return false, -1, errors.Wrapf(err, "error waiting for the re-exec process")
}
- return true, nil
+ return true, int(ret), nil
}
diff --git a/pkg/rootless/rootless_unsupported.go b/pkg/rootless/rootless_unsupported.go
index a6efa73f5..b1f075045 100644
--- a/pkg/rootless/rootless_unsupported.go
+++ b/pkg/rootless/rootless_unsupported.go
@@ -13,8 +13,8 @@ func IsRootless() bool {
// BecomeRootInUserNS is a stub function that always returns false and an
// error on unsupported OS's
-func BecomeRootInUserNS() (bool, error) {
- return false, errors.New("this function is not supported on this os")
+func BecomeRootInUserNS() (bool, int, error) {
+ return false, -1, errors.New("this function is not supported on this os")
}
// GetRootlessUID returns the UID of the user in the parent userNS
diff --git a/pkg/spec/createconfig.go b/pkg/spec/createconfig.go
index 7dfb9588c..57416732d 100644
--- a/pkg/spec/createconfig.go
+++ b/pkg/spec/createconfig.go
@@ -318,6 +318,14 @@ func (c *CreateConfig) GetContainerCreateOptions(runtime *libpod.Runtime) ([]lib
logrus.Debugf("appending name %s", c.Name)
options = append(options, libpod.WithName(c.Name))
}
+ if c.Pod != "" {
+ logrus.Debugf("adding container to pod %s", c.Pod)
+ pod, err := runtime.LookupPod(c.Pod)
+ if err != nil {
+ return nil, errors.Wrapf(err, "unable to add container to pod %s", c.Pod)
+ }
+ options = append(options, runtime.WithPod(pod))
+ }
if len(c.PortBindings) > 0 {
portBindings, err = c.CreatePortBindings()
diff --git a/test/e2e/libpod_suite_test.go b/test/e2e/libpod_suite_test.go
index 448dbfc04..6ec995bfc 100644
--- a/test/e2e/libpod_suite_test.go
+++ b/test/e2e/libpod_suite_test.go
@@ -224,6 +224,17 @@ func (p *PodmanTest) Cleanup() {
}
}
+// CleanupPod cleans up the temporary store
+func (p *PodmanTest) CleanupPod() {
+ // Remove all containers
+ session := p.Podman([]string{"pod", "rm", "-fa"})
+ session.Wait(90)
+ // Nuke tempdir
+ if err := os.RemoveAll(p.TempDir); err != nil {
+ fmt.Printf("%q\n", err)
+ }
+}
+
// GrepString takes session output and behaves like grep. it returns a bool
// if successful and an array of strings on positive matches
func (s *PodmanSession) GrepString(term string) (bool, []string) {
@@ -459,6 +470,15 @@ func (p *PodmanTest) RunTopContainer(name string) *PodmanSession {
return p.Podman(podmanArgs)
}
+func (p *PodmanTest) RunTopContainerInPod(name, pod string) *PodmanSession {
+ var podmanArgs = []string{"run", "--pod", pod}
+ if name != "" {
+ podmanArgs = append(podmanArgs, "--name", name)
+ }
+ podmanArgs = append(podmanArgs, "-d", ALPINE, "top")
+ return p.Podman(podmanArgs)
+}
+
//RunLsContainer runs a simple container in the background that
// simply runs ls. If the name passed != "", it will have a name
func (p *PodmanTest) RunLsContainer(name string) (*PodmanSession, int, string) {
@@ -472,6 +492,17 @@ func (p *PodmanTest) RunLsContainer(name string) (*PodmanSession, int, string) {
return session, session.ExitCode(), session.OutputToString()
}
+func (p *PodmanTest) RunLsContainerInPod(name, pod string) (*PodmanSession, int, string) {
+ var podmanArgs = []string{"run", "--pod", pod}
+ if name != "" {
+ podmanArgs = append(podmanArgs, "--name", name)
+ }
+ podmanArgs = append(podmanArgs, "-d", ALPINE, "ls")
+ session := p.Podman(podmanArgs)
+ session.WaitWithDefaultTimeout()
+ return session, session.ExitCode(), session.OutputToString()
+}
+
//NumberOfContainersRunning returns an int of how many
// containers are currently running.
func (p *PodmanTest) NumberOfContainersRunning() int {
@@ -502,6 +533,21 @@ func (p *PodmanTest) NumberOfContainers() int {
return len(containers)
}
+// NumberOfPods returns an int of how many
+// pods are currently defined.
+func (p *PodmanTest) NumberOfPods() int {
+ var pods []string
+ ps := p.Podman([]string{"pod", "ps", "-q"})
+ ps.WaitWithDefaultTimeout()
+ Expect(ps.ExitCode()).To(Equal(0))
+ for _, i := range ps.OutputToStringArray() {
+ if i != "" {
+ pods = append(pods, i)
+ }
+ }
+ return len(pods)
+}
+
// NumberOfRunningContainers returns an int of how many containers are currently
// running
func (p *PodmanTest) NumberOfRunningContainers() int {
diff --git a/test/e2e/pod_create_test.go b/test/e2e/pod_create_test.go
new file mode 100644
index 000000000..fa420675f
--- /dev/null
+++ b/test/e2e/pod_create_test.go
@@ -0,0 +1,84 @@
+package integration
+
+import (
+ "os"
+
+ . "github.com/onsi/ginkgo"
+ . "github.com/onsi/gomega"
+)
+
+var _ = Describe("Podman pod create", func() {
+ var (
+ tempdir string
+ err error
+ podmanTest PodmanTest
+ )
+
+ BeforeEach(func() {
+ tempdir, err = CreateTempDirInTempDir()
+ if err != nil {
+ os.Exit(1)
+ }
+ podmanTest = PodmanCreate(tempdir)
+ podmanTest.RestoreAllArtifacts()
+ })
+
+ AfterEach(func() {
+ podmanTest.CleanupPod()
+ })
+
+ It("podman create pod", func() {
+ session := podmanTest.Podman([]string{"pod", "create"})
+ session.WaitWithDefaultTimeout()
+ cid := session.OutputToString()
+ Expect(session.ExitCode()).To(Equal(0))
+
+ check := podmanTest.Podman([]string{"pod", "ps", "-q", "--no-trunc"})
+ check.WaitWithDefaultTimeout()
+ match, _ := check.GrepString(cid)
+ Expect(match).To(BeTrue())
+ Expect(len(check.OutputToStringArray())).To(Equal(1))
+ })
+
+ It("podman create pod with name", func() {
+ name := "test"
+ session := podmanTest.Podman([]string{"pod", "create", "--name", name})
+ session.WaitWithDefaultTimeout()
+ Expect(session.ExitCode()).To(Equal(0))
+
+ check := podmanTest.Podman([]string{"pod", "ps", "--no-trunc"})
+ check.WaitWithDefaultTimeout()
+ match, _ := check.GrepString(name)
+ Expect(match).To(BeTrue())
+ })
+
+ It("podman create pod with doubled name", func() {
+ name := "test"
+ session := podmanTest.Podman([]string{"pod", "create", "--name", name})
+ session.WaitWithDefaultTimeout()
+ Expect(session.ExitCode()).To(Equal(0))
+
+ session = podmanTest.Podman([]string{"pod", "create", "--name", name})
+ session.WaitWithDefaultTimeout()
+ Expect(session.ExitCode()).To(Not(Equal(1)))
+
+ check := podmanTest.Podman([]string{"pod", "ps", "-q"})
+ check.WaitWithDefaultTimeout()
+ Expect(len(check.OutputToStringArray())).To(Equal(1))
+ })
+
+ It("podman create pod with same name as ctr", func() {
+ name := "test"
+ session := podmanTest.Podman([]string{"create", "--name", name, ALPINE, "ls"})
+ session.WaitWithDefaultTimeout()
+ Expect(session.ExitCode()).To(Equal(0))
+
+ session = podmanTest.Podman([]string{"pod", "create", "--name", name})
+ session.WaitWithDefaultTimeout()
+ Expect(session.ExitCode()).To(Not(Equal(1)))
+
+ check := podmanTest.Podman([]string{"pod", "ps", "-q"})
+ check.WaitWithDefaultTimeout()
+ Expect(len(check.OutputToStringArray())).To(Equal(1))
+ })
+})
diff --git a/test/e2e/pod_ps_test.go b/test/e2e/pod_ps_test.go
new file mode 100644
index 000000000..4ab13f119
--- /dev/null
+++ b/test/e2e/pod_ps_test.go
@@ -0,0 +1,227 @@
+package integration
+
+import (
+ "fmt"
+ "os"
+ "sort"
+
+ . "github.com/onsi/ginkgo"
+ . "github.com/onsi/gomega"
+)
+
+var _ = Describe("Podman ps", func() {
+ var (
+ tempdir string
+ err error
+ podmanTest PodmanTest
+ )
+
+ BeforeEach(func() {
+ tempdir, err = CreateTempDirInTempDir()
+ if err != nil {
+ os.Exit(1)
+ }
+ podmanTest = PodmanCreate(tempdir)
+ podmanTest.RestoreAllArtifacts()
+ })
+
+ AfterEach(func() {
+ podmanTest.CleanupPod()
+
+ })
+
+ It("podman pod ps no pods", func() {
+ session := podmanTest.Podman([]string{"pod", "ps"})
+ session.WaitWithDefaultTimeout()
+ Expect(session.ExitCode()).To(Equal(0))
+ })
+
+ It("podman pod ps default", func() {
+ session := podmanTest.Podman([]string{"pod", "create"})
+ session.WaitWithDefaultTimeout()
+ Expect(session.ExitCode()).To(Equal(0))
+
+ podid := session.OutputToString()
+ session = podmanTest.RunTopContainerInPod("", podid)
+ session.WaitWithDefaultTimeout()
+ Expect(session.ExitCode()).To(Equal(0))
+
+ result := podmanTest.Podman([]string{"pod", "ps"})
+ result.WaitWithDefaultTimeout()
+ Expect(result.ExitCode()).To(Equal(0))
+ Expect(len(result.OutputToStringArray())).Should(BeNumerically(">", 0))
+ })
+
+ It("podman pod ps quiet flag", func() {
+ session := podmanTest.Podman([]string{"pod", "create"})
+ session.WaitWithDefaultTimeout()
+ Expect(session.ExitCode()).To(Equal(0))
+
+ podid := session.OutputToString()
+ _, ec, _ := podmanTest.RunLsContainerInPod("", podid)
+ Expect(ec).To(Equal(0))
+
+ result := podmanTest.Podman([]string{"pod", "ps", "-q"})
+ result.WaitWithDefaultTimeout()
+ Expect(result.ExitCode()).To(Equal(0))
+ Expect(len(result.OutputToStringArray())).Should(BeNumerically(">", 0))
+ Expect(podid).To(ContainSubstring(result.OutputToStringArray()[0]))
+ })
+
+ It("podman pod ps no-trunc", func() {
+ session := podmanTest.Podman([]string{"pod", "create"})
+ session.WaitWithDefaultTimeout()
+ Expect(session.ExitCode()).To(Equal(0))
+
+ podid := session.OutputToString()
+ _, ec, _ := podmanTest.RunLsContainerInPod("", podid)
+ Expect(ec).To(Equal(0))
+
+ result := podmanTest.Podman([]string{"pod", "ps", "-q", "--no-trunc"})
+ result.WaitWithDefaultTimeout()
+ Expect(result.ExitCode()).To(Equal(0))
+ Expect(len(result.OutputToStringArray())).Should(BeNumerically(">", 0))
+ Expect(podid).To(Equal(result.OutputToStringArray()[0]))
+ })
+
+ It("podman pod ps latest", func() {
+ session := podmanTest.Podman([]string{"pod", "create"})
+ session.WaitWithDefaultTimeout()
+ Expect(session.ExitCode()).To(Equal(0))
+
+ podid1 := session.OutputToString()
+
+ session = podmanTest.Podman([]string{"pod", "create"})
+ session.WaitWithDefaultTimeout()
+ Expect(session.ExitCode()).To(Equal(0))
+
+ podid2 := session.OutputToString()
+
+ result := podmanTest.Podman([]string{"pod", "ps", "-q", "--no-trunc", "--latest"})
+ result.WaitWithDefaultTimeout()
+ Expect(result.ExitCode()).To(Equal(0))
+ Expect(result.OutputToString()).To(ContainSubstring(podid2))
+ Expect(result.OutputToString()).To(Not(ContainSubstring(podid1)))
+ })
+ It("podman pod ps id filter flag", func() {
+ session := podmanTest.Podman([]string{"pod", "create"})
+ session.WaitWithDefaultTimeout()
+ Expect(session.ExitCode()).To(Equal(0))
+
+ result := podmanTest.Podman([]string{"pod", "ps", "--filter", fmt.Sprintf("id=%s", session.OutputToString())})
+ result.WaitWithDefaultTimeout()
+ Expect(result.ExitCode()).To(Equal(0))
+ })
+
+ It("podman pod ps mutually exclusive flags", func() {
+ session := podmanTest.Podman([]string{"pod", "ps", "-q", "--format", "{{.ID}}"})
+ session.WaitWithDefaultTimeout()
+ Expect(session.ExitCode()).To(Not(Equal(0)))
+
+ })
+
+ It("podman pod ps --sort by name", func() {
+ session := podmanTest.Podman([]string{"pod", "create"})
+ session.WaitWithDefaultTimeout()
+ Expect(session.ExitCode()).To(Equal(0))
+
+ session = podmanTest.Podman([]string{"pod", "create"})
+ session.WaitWithDefaultTimeout()
+ Expect(session.ExitCode()).To(Equal(0))
+
+ session = podmanTest.Podman([]string{"pod", "create"})
+ session.WaitWithDefaultTimeout()
+ Expect(session.ExitCode()).To(Equal(0))
+
+ session = podmanTest.Podman([]string{"pod", "ps", "--sort=name", "--format", "{{.Name}}"})
+
+ session.WaitWithDefaultTimeout()
+ Expect(session.ExitCode()).To(Equal(0))
+
+ sortedArr := session.OutputToStringArray()
+
+ Expect(sort.SliceIsSorted(sortedArr, func(i, j int) bool { return sortedArr[i] < sortedArr[j] })).To(BeTrue())
+ })
+
+ It("podman pod ps --ctr-names", func() {
+ session := podmanTest.Podman([]string{"pod", "create"})
+ session.WaitWithDefaultTimeout()
+ Expect(session.ExitCode()).To(Equal(0))
+ podid := session.OutputToString()
+
+ session = podmanTest.RunTopContainerInPod("test1", podid)
+ session.WaitWithDefaultTimeout()
+ Expect(session.ExitCode()).To(Equal(0))
+
+ _, ec, _ := podmanTest.RunLsContainerInPod("test2", podid)
+ Expect(ec).To(Equal(0))
+
+ session = podmanTest.Podman([]string{"pod", "ps", "--format={{.ContainerInfo}}", "--ctr-names"})
+ session.WaitWithDefaultTimeout()
+ Expect(session.ExitCode()).To(Equal(0))
+ Expect(session.OutputToString()).To(ContainSubstring("test1"))
+ Expect(session.OutputToString()).To(ContainSubstring("test2"))
+ })
+
+ It("podman pod ps filter ctr attributes", func() {
+ session := podmanTest.Podman([]string{"pod", "create"})
+ session.WaitWithDefaultTimeout()
+ Expect(session.ExitCode()).To(Equal(0))
+ podid1 := session.OutputToString()
+
+ session = podmanTest.RunTopContainerInPod("test1", podid1)
+ session.WaitWithDefaultTimeout()
+ Expect(session.ExitCode()).To(Equal(0))
+
+ session = podmanTest.Podman([]string{"pod", "create"})
+ session.WaitWithDefaultTimeout()
+ Expect(session.ExitCode()).To(Equal(0))
+ podid2 := session.OutputToString()
+
+ _, ec, cid := podmanTest.RunLsContainerInPod("test2", podid2)
+ Expect(ec).To(Equal(0))
+
+ session = podmanTest.Podman([]string{"pod", "ps", "-q", "--no-trunc", "--filter", "ctr-names=test1"})
+ session.WaitWithDefaultTimeout()
+ Expect(session.ExitCode()).To(Equal(0))
+ Expect(session.OutputToString()).To(ContainSubstring(podid1))
+ Expect(session.OutputToString()).To(Not(ContainSubstring(podid2)))
+
+ session = podmanTest.Podman([]string{"pod", "ps", "-q", "--no-trunc", "--filter", fmt.Sprintf("ctr-ids=%s", cid)})
+ session.WaitWithDefaultTimeout()
+ Expect(session.ExitCode()).To(Equal(0))
+ Expect(session.OutputToString()).To(ContainSubstring(podid2))
+ Expect(session.OutputToString()).To(Not(ContainSubstring(podid1)))
+
+ session = podmanTest.Podman([]string{"pod", "create"})
+ session.WaitWithDefaultTimeout()
+ Expect(session.ExitCode()).To(Equal(0))
+ podid3 := session.OutputToString()
+
+ session = podmanTest.Podman([]string{"pod", "ps", "-q", "--no-trunc", "--filter", "ctr-number=1"})
+ session.WaitWithDefaultTimeout()
+ Expect(session.ExitCode()).To(Equal(0))
+ Expect(session.OutputToString()).To(ContainSubstring(podid1))
+ Expect(session.OutputToString()).To(ContainSubstring(podid2))
+ Expect(session.OutputToString()).To(Not(ContainSubstring(podid3)))
+
+ session = podmanTest.Podman([]string{"pod", "ps", "-q", "--no-trunc", "--filter", "ctr-status=running"})
+ session.WaitWithDefaultTimeout()
+ Expect(session.ExitCode()).To(Equal(0))
+ Expect(session.OutputToString()).To(ContainSubstring(podid1))
+ Expect(session.OutputToString()).To(Not(ContainSubstring(podid2)))
+ Expect(session.OutputToString()).To(Not(ContainSubstring(podid3)))
+
+ session = podmanTest.Podman([]string{"pod", "ps", "-q", "--no-trunc", "--filter", "ctr-status=exited"})
+ session.WaitWithDefaultTimeout()
+ Expect(session.ExitCode()).To(Equal(0))
+ Expect(session.OutputToString()).To(ContainSubstring(podid2))
+ Expect(session.OutputToString()).To(Not(ContainSubstring(podid1)))
+ Expect(session.OutputToString()).To(Not(ContainSubstring(podid3)))
+
+ session = podmanTest.Podman([]string{"pod", "ps", "-q", "--no-trunc", "--filter", "ctr-status=created"})
+ session.WaitWithDefaultTimeout()
+ Expect(session.ExitCode()).To(Equal(0))
+ Expect(session.OutputToString()).To(BeEmpty())
+ })
+})
diff --git a/test/e2e/pod_rm_test.go b/test/e2e/pod_rm_test.go
new file mode 100644
index 000000000..4ebf2f340
--- /dev/null
+++ b/test/e2e/pod_rm_test.go
@@ -0,0 +1,168 @@
+package integration
+
+import (
+ "os"
+
+ . "github.com/onsi/ginkgo"
+ . "github.com/onsi/gomega"
+)
+
+var _ = Describe("Podman pod rm", func() {
+ var (
+ tempdir string
+ err error
+ podmanTest PodmanTest
+ )
+
+ BeforeEach(func() {
+ tempdir, err = CreateTempDirInTempDir()
+ if err != nil {
+ os.Exit(1)
+ }
+ podmanTest = PodmanCreate(tempdir)
+ podmanTest.RestoreAllArtifacts()
+ })
+
+ AfterEach(func() {
+ podmanTest.CleanupPod()
+
+ })
+
+ It("podman pod rm empty pod", func() {
+ session := podmanTest.Podman([]string{"pod", "create"})
+ session.WaitWithDefaultTimeout()
+ podid := session.OutputToString()
+
+ result := podmanTest.Podman([]string{"pod", "rm", podid})
+ result.WaitWithDefaultTimeout()
+ Expect(result.ExitCode()).To(Equal(0))
+ })
+
+ It("podman pod rm latest pod", func() {
+ session := podmanTest.Podman([]string{"pod", "create"})
+ session.WaitWithDefaultTimeout()
+ podid := session.OutputToString()
+
+ session = podmanTest.Podman([]string{"pod", "create"})
+ session.WaitWithDefaultTimeout()
+ podid2 := session.OutputToString()
+
+ result := podmanTest.Podman([]string{"pod", "rm", "--latest"})
+ result.WaitWithDefaultTimeout()
+ Expect(result.ExitCode()).To(Equal(0))
+
+ result = podmanTest.Podman([]string{"pod", "ps", "-q", "--no-trunc"})
+ result.WaitWithDefaultTimeout()
+ Expect(result.ExitCode()).To(Equal(0))
+ Expect(result.OutputToString()).To(ContainSubstring(podid))
+ Expect(result.OutputToString()).To(Not(ContainSubstring(podid2)))
+ })
+
+ It("podman pod rm doesn't remove a pod with a container", func() {
+ session := podmanTest.Podman([]string{"pod", "create"})
+ session.WaitWithDefaultTimeout()
+
+ podid := session.OutputToString()
+
+ session = podmanTest.Podman([]string{"create", "--pod", podid, ALPINE, "ls"})
+ session.WaitWithDefaultTimeout()
+ Expect(session.ExitCode()).To(Equal(0))
+
+ result := podmanTest.Podman([]string{"pod", "rm", podid})
+ result.WaitWithDefaultTimeout()
+ Expect(result.ExitCode()).To(Equal(125))
+
+ result = podmanTest.Podman([]string{"ps", "-qa"})
+ result.WaitWithDefaultTimeout()
+ Expect(len(result.OutputToStringArray())).To(Equal(1))
+ })
+
+ It("podman pod rm -f does remove a running container", func() {
+ session := podmanTest.Podman([]string{"pod", "create"})
+ session.WaitWithDefaultTimeout()
+
+ podid := session.OutputToString()
+
+ session = podmanTest.Podman([]string{"run", "-d", "--pod", podid, ALPINE, "top"})
+ session.WaitWithDefaultTimeout()
+ Expect(session.ExitCode()).To(Equal(0))
+
+ result := podmanTest.Podman([]string{"pod", "rm", "-f", podid})
+ result.WaitWithDefaultTimeout()
+ Expect(result.ExitCode()).To(Equal(0))
+
+ result = podmanTest.Podman([]string{"ps", "-q"})
+ result.WaitWithDefaultTimeout()
+ Expect(result.OutputToString()).To(BeEmpty())
+ })
+
+ It("podman pod rm -a doesn't remove a running container", func() {
+ session := podmanTest.Podman([]string{"pod", "create"})
+ session.WaitWithDefaultTimeout()
+
+ podid1 := session.OutputToString()
+
+ session = podmanTest.Podman([]string{"pod", "create"})
+ session.WaitWithDefaultTimeout()
+
+ session = podmanTest.Podman([]string{"run", "-d", "--pod", podid1, ALPINE, "top"})
+ session.WaitWithDefaultTimeout()
+ Expect(session.ExitCode()).To(Equal(0))
+
+ result := podmanTest.Podman([]string{"pod", "rm", "-a"})
+ result.WaitWithDefaultTimeout()
+ Expect(result.ExitCode()).To(Not(Equal(0)))
+
+ result = podmanTest.Podman([]string{"ps", "-q"})
+ result.WaitWithDefaultTimeout()
+ Expect(len(result.OutputToStringArray())).To(Equal(1))
+
+ // one pod should have been deleted
+ result = podmanTest.Podman([]string{"pod", "ps", "-q"})
+ result.WaitWithDefaultTimeout()
+ Expect(len(result.OutputToStringArray())).To(Equal(1))
+ })
+
+ It("podman pod rm -fa removes everything", func() {
+ session := podmanTest.Podman([]string{"pod", "create"})
+ session.WaitWithDefaultTimeout()
+
+ podid1 := session.OutputToString()
+
+ session = podmanTest.Podman([]string{"pod", "create"})
+ session.WaitWithDefaultTimeout()
+
+ podid2 := session.OutputToString()
+
+ session = podmanTest.Podman([]string{"pod", "create"})
+ session.WaitWithDefaultTimeout()
+
+ session = podmanTest.Podman([]string{"run", "-d", "--pod", podid1, ALPINE, "top"})
+ session.WaitWithDefaultTimeout()
+ Expect(session.ExitCode()).To(Equal(0))
+
+ session = podmanTest.Podman([]string{"create", "-d", "--pod", podid1, ALPINE, "ls"})
+ session.WaitWithDefaultTimeout()
+ Expect(session.ExitCode()).To(Equal(0))
+
+ session = podmanTest.Podman([]string{"run", "-d", "--pod", podid2, ALPINE, "ls"})
+ session.WaitWithDefaultTimeout()
+ Expect(session.ExitCode()).To(Equal(0))
+
+ session = podmanTest.Podman([]string{"run", "-d", "--pod", podid2, nginx})
+ session.WaitWithDefaultTimeout()
+
+ result := podmanTest.Podman([]string{"pod", "rm", "-fa"})
+ result.WaitWithDefaultTimeout()
+ Expect(result.ExitCode()).To(Equal(0))
+
+ result = podmanTest.Podman([]string{"ps", "-q"})
+ result.WaitWithDefaultTimeout()
+ Expect(result.OutputToString()).To(BeEmpty())
+
+ // one pod should have been deleted
+ result = podmanTest.Podman([]string{"pod", "ps", "-q"})
+ result.WaitWithDefaultTimeout()
+ Expect(result.OutputToString()).To(BeEmpty())
+ })
+})