diff options
-rw-r--r-- | Makefile | 10 | ||||
-rw-r--r-- | cmd/podman/ps.go | 5 | ||||
-rw-r--r-- | cmd/podman/shared/container.go | 33 | ||||
-rw-r--r-- | libpod/runtime_ctr.go | 2 | ||||
-rw-r--r-- | test/e2e/ps_test.go | 22 | ||||
-rw-r--r-- | test/system/130-kill.bats | 17 |
6 files changed, 74 insertions, 15 deletions
@@ -447,12 +447,22 @@ install.systemd: install ${SELINUXOPT} -m 644 contrib/varlink/podman.conf ${DESTDIR}${TMPFILESDIR}/podman.conf uninstall: + # Remove manpages for i in $(filter %.1,$(MANPAGES_DEST)); do \ rm -f $(DESTDIR)$(MANDIR)/man1/$$(basename $${i}); \ done; \ for i in $(filter %.5,$(MANPAGES_DEST)); do \ rm -f $(DESTDIR)$(MANDIR)/man5/$$(basename $${i}); \ done + # Remove podman and remote bin + rm -f $(DESTDIR)$(BINDIR)/podman + rm -f $(DESTDIR)$(BINDIR)/podman-remote + # Remove related config files + rm -f ${DESTDIR}${ETCDIR}/cni/net.d/87-podman-bridge.conflist + rm -f ${DESTDIR}${TMPFILESDIR}/podman.conf + rm -f ${DESTDIR}${SYSTEMDDIR}/io.podman.socket + rm -f ${DESTDIR}${USERSYSTEMDDIR}/io.podman.socket + rm -f ${DESTDIR}${SYSTEMDDIR}/io.podman.service .PHONY: .gitvalidation .gitvalidation: .gopathok diff --git a/cmd/podman/ps.go b/cmd/podman/ps.go index 4ac779430..d2c5e19e2 100644 --- a/cmd/podman/ps.go +++ b/cmd/podman/ps.go @@ -31,6 +31,7 @@ const ( hsize = "SIZE" hinfra = "IS INFRA" //nolint hpod = "POD" + hpodname = "POD NAME" nspid = "PID" nscgroup = "CGROUPNS" nsipc = "IPC" @@ -355,7 +356,7 @@ func psDisplay(c *cliconfig.PsValues, runtime *adapter.LocalRuntime) error { fmt.Fprintf(w, "%s\t%s\t%s\t%s\t%s\t%s\t%s", hid, himage, hcommand, hcreated, hstatus, hports, hnames) // User wants pod info if opts.Pod { - fmt.Fprintf(w, "\t%s", hpod) + fmt.Fprintf(w, "\t%s\t%s", hpod, hpodname) } //User wants size info if opts.Size { @@ -374,7 +375,7 @@ func psDisplay(c *cliconfig.PsValues, runtime *adapter.LocalRuntime) error { fmt.Fprintf(w, "\n%s\t%s\t%s\t%s\t%s\t%s\t%s", container.ID, container.Image, container.Command, container.Created, container.Status, container.Ports, container.Names) // User wants pod info if opts.Pod { - fmt.Fprintf(w, "\t%s", container.Pod) + fmt.Fprintf(w, "\t%s\t%s", container.Pod, container.PodName) } //User wants size info if opts.Size { diff --git a/cmd/podman/shared/container.go b/cmd/podman/shared/container.go index 4f2002992..5f8df2e10 100644 --- a/cmd/podman/shared/container.go +++ b/cmd/podman/shared/container.go @@ -76,6 +76,7 @@ type PsContainerOutput struct { Pid int Size *ContainerSize Pod string + PodName string CreatedAt time.Time ExitedAt time.Time StartedAt time.Time @@ -112,7 +113,7 @@ type ContainerSize struct { // NewBatchContainer runs a batch process under one lock to get container information and only // be called in PBatch. -func NewBatchContainer(ctr *libpod.Container, opts PsOptions) (PsContainerOutput, error) { +func NewBatchContainer(r *libpod.Runtime, ctr *libpod.Container, opts PsOptions) (PsContainerOutput, error) { var ( conState define.ContainerStatus command string @@ -204,11 +205,11 @@ func NewBatchContainer(ctr *libpod.Container, opts PsOptions) (PsContainerOutput _, imageName := ctr.Image() cid := ctr.ID() - pod := ctr.PodID() + podID := ctr.PodID() if !opts.NoTrunc { cid = cid[0:cidTruncLength] - if len(pod) > podTruncLength { - pod = pod[0:podTruncLength] + if len(podID) > podTruncLength { + podID = podID[0:podTruncLength] } if len(command) > cmdTruncLength { command = command[0:cmdTruncLength] + "..." @@ -231,13 +232,29 @@ func NewBatchContainer(ctr *libpod.Container, opts PsOptions) (PsContainerOutput pso.State = conState pso.Pid = pid pso.Size = size - pso.Pod = pod pso.ExitedAt = exitedAt pso.CreatedAt = ctr.CreatedTime() pso.StartedAt = startedAt pso.Labels = ctr.Labels() pso.Mounts = strings.Join(ctr.UserVolumes(), " ") + // Add pod name and pod ID if requested by user. + // No need to look up the pod if its ID is empty. + if opts.Pod && len(podID) > 0 { + // The pod name is not in the container definition + // so we need to retrieve it using the pod ID. + var podName string + pod, err := r.LookupPod(podID) + if err != nil { + logrus.Errorf("unable to lookup pod for container %s", ctr.ID()) + } else { + podName = pod.Name() + } + + pso.Pod = podID + pso.PodName = podName + } + if opts.Namespace { pso.Cgroup = ns.Cgroup pso.IPC = ns.IPC @@ -462,13 +479,13 @@ func GetPsContainerOutput(r *libpod.Runtime, opts PsOptions, filters []string, m outputContainers = []*libpod.Container{latestCtr} } - pss := PBatch(outputContainers, maxWorkers, opts) + pss := PBatch(r, outputContainers, maxWorkers, opts) return pss, nil } // PBatch performs batch operations on a container in parallel. It spawns the // number of workers relative to the number of parallel operations desired. -func PBatch(containers []*libpod.Container, workers int, opts PsOptions) []PsContainerOutput { +func PBatch(r *libpod.Runtime, containers []*libpod.Container, workers int, opts PsOptions) []PsContainerOutput { var wg sync.WaitGroup psResults := []PsContainerOutput{} @@ -492,7 +509,7 @@ func PBatch(containers []*libpod.Container, workers int, opts PsOptions) []PsCon j := j wg.Add(1) f := func() (PsContainerOutput, error) { - return NewBatchContainer(j, opts) + return NewBatchContainer(r, j, opts) } jobs <- workerInput{ parallelFunc: f, diff --git a/libpod/runtime_ctr.go b/libpod/runtime_ctr.go index 3cf70f417..51efc5996 100644 --- a/libpod/runtime_ctr.go +++ b/libpod/runtime_ctr.go @@ -768,7 +768,7 @@ func (r *Runtime) GetContainers(filters ...ContainerFilter) ([]*Container, error return nil, define.ErrRuntimeStopped } - ctrs, err := r.state.AllContainers() + ctrs, err := r.GetAllContainers() if err != nil { return nil, err } diff --git a/test/e2e/ps_test.go b/test/e2e/ps_test.go index 362c7aabb..12bfdfe41 100644 --- a/test/e2e/ps_test.go +++ b/test/e2e/ps_test.go @@ -306,7 +306,29 @@ var _ = Describe("Podman ps", func() { Expect(session.ExitCode()).To(Equal(0)) Expect(session.OutputToString()).To(ContainSubstring(podid)) + }) + + It("podman --pod with a non-empty pod name", func() { + SkipIfRemote() + + podName := "testPodName" + _, ec, podid := podmanTest.CreatePod(podName) + Expect(ec).To(Equal(0)) + + session := podmanTest.RunTopContainerInPod("", podName) + session.WaitWithDefaultTimeout() + Expect(session.ExitCode()).To(Equal(0)) + + // "--no-trunc" must be given. If not it will trunc the pod ID + // in the output and you will have to trunc it in the test too. + session = podmanTest.Podman([]string{"ps", "--pod", "--no-trunc"}) + + session.WaitWithDefaultTimeout() + Expect(session.ExitCode()).To(Equal(0)) + output := session.OutputToString() + Expect(output).To(ContainSubstring(podid)) + Expect(output).To(ContainSubstring(podName)) }) It("podman ps test with port range", func() { diff --git a/test/system/130-kill.bats b/test/system/130-kill.bats index af3409b9b..aae7f114f 100644 --- a/test/system/130-kill.bats +++ b/test/system/130-kill.bats @@ -16,10 +16,19 @@ load helpers # and confirm that signals are received. We can't use run_podman here. local fifo=${PODMAN_TMPDIR}/podman-kill-fifo.$(random_string 10) mkfifo $fifo - $PODMAN logs -f $cid >$fifo & + $PODMAN logs -f $cid >$fifo </dev/null & podman_log_pid=$! + + # Open the FIFO for reading, and keep it open. This prevents a race + # condition in which the container can exit (e.g. if for some reason + # it doesn't handle the signal) and we (this test) try to read from + # the FIFO. Since there wouldn't be an active writer, the open() + # would hang forever. With this exec we keep the FD open, allowing + # 'read -t' to time out and report a useful error. + exec 5<$fifo + # First container emits READY when ready; wait for it. - read -t 10 ready <$fifo + read -t 10 -u 5 ready is "$ready" "READY" "first log message from container" # Helper function: send the given signal, verify that it's received. @@ -28,7 +37,7 @@ load helpers local signum=${2:-$1} # e.g. if signal=HUP, we expect to see '1' run_podman kill -s $signal $cid - read -t 10 actual <$fifo + read -t 10 -u 5 actual || die "Timed out: no ACK for kill -s $signal" is "$actual" "got: $signum" "Signal $signal handled by container" } @@ -46,7 +55,7 @@ load helpers # Done. Tell the container to stop, and wait for final DONE run_podman exec $cid touch /stop - read -t 5 done <$fifo + read -t 5 -u 5 done || die "Timed out waiting for DONE from container" is "$done" "DONE" "final log message from container" # Clean up |