diff options
author | OpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com> | 2019-03-18 05:00:15 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-03-18 05:00:15 -0700 |
commit | 122d00f67fb8b47ec29f922f9cc32af13123e8f2 (patch) | |
tree | 3cb5fdb9ce284c976ab9338ee97dc66a1cb0bb47 | |
parent | 7f9fdbeafeee8616f4f40a79c1b2dfd177dbe962 (diff) | |
parent | 46b74a8ff8dea146539fa731cc5746fc5a59e186 (diff) | |
download | podman-122d00f67fb8b47ec29f922f9cc32af13123e8f2.tar.gz podman-122d00f67fb8b47ec29f922f9cc32af13123e8f2.tar.bz2 podman-122d00f67fb8b47ec29f922f9cc32af13123e8f2.zip |
Merge pull request #2683 from giuseppe/fix-pod-top
rootless: fix pod top
-rw-r--r-- | cmd/podman/main.go | 1 | ||||
-rw-r--r-- | cmd/podman/pod_top.go | 26 | ||||
-rw-r--r-- | test/e2e/rootless_test.go | 15 |
3 files changed, 42 insertions, 0 deletions
diff --git a/cmd/podman/main.go b/cmd/podman/main.go index b130f3232..ef300ef75 100644 --- a/cmd/podman/main.go +++ b/cmd/podman/main.go @@ -76,6 +76,7 @@ var cmdsNotRequiringRootless = map[*cobra.Command]bool{ _podKillCommand: true, _podStatsCommand: true, _podStopCommand: true, + _podTopCommand: true, _restartCommand: true, _rmCommand: true, _runCommand: true, diff --git a/cmd/podman/pod_top.go b/cmd/podman/pod_top.go index c9a6d8822..f65d66df6 100644 --- a/cmd/podman/pod_top.go +++ b/cmd/podman/pod_top.go @@ -9,6 +9,7 @@ import ( "github.com/containers/libpod/cmd/podman/cliconfig" "github.com/containers/libpod/libpod" + "github.com/containers/libpod/pkg/rootless" "github.com/pkg/errors" "github.com/spf13/cobra" ) @@ -53,6 +54,10 @@ func podTopCmd(c *cliconfig.PodTopValues) error { ) args := c.InputArgs + if os.Geteuid() != 0 { + rootless.SetSkipStorageSetup(true) + } + if c.ListDescriptors { descriptors, err := libpod.GetContainerPidInformationDescriptors() if err != nil { @@ -77,6 +82,27 @@ func podTopCmd(c *cliconfig.PodTopValues) error { } else { descriptors = args[1:] } + + if os.Geteuid() != 0 { + var pod *adapter.Pod + var err error + if c.Latest { + pod, err = runtime.GetLatestPod() + } else { + pod, err = runtime.LookupPod(c.InputArgs[0]) + } + if err != nil { + return errors.Wrapf(err, "unable to lookup requested container") + } + became, ret, err := runtime.JoinOrCreateRootlessPod(pod) + if err != nil { + return err + } + if became { + os.Exit(ret) + } + } + w := tabwriter.NewWriter(os.Stdout, 5, 1, 3, ' ', 0) psOutput, err := runtime.PodTop(c, descriptors) if err != nil { diff --git a/test/e2e/rootless_test.go b/test/e2e/rootless_test.go index cd771e2ba..57146bca0 100644 --- a/test/e2e/rootless_test.go +++ b/test/e2e/rootless_test.go @@ -138,6 +138,21 @@ var _ = Describe("Podman rootless", func() { cmd.WaitWithDefaultTimeout() Expect(cmd.ExitCode()).To(Equal(0)) Expect(cmd.LineInOutputContains("hello")).To(BeTrue()) + + args = []string{"pod", "top", podId} + cmd = rootlessTest.PodmanAsUser(args, 1000, 1000, "", env) + cmd.WaitWithDefaultTimeout() + Expect(cmd.ExitCode()).To(Not(Equal(0))) + + args = []string{"run", "--pod", podId, "-d", "--rootfs", mountPath, "sleep", "100"} + cmd = rootlessTest.PodmanAsUser(args, 1000, 1000, "", env) + cmd.WaitWithDefaultTimeout() + Expect(cmd.ExitCode()).To(Equal(0)) + + args = []string{"pod", "top", podId} + cmd = rootlessTest.PodmanAsUser(args, 1000, 1000, "", env) + cmd.WaitWithDefaultTimeout() + Expect(cmd.ExitCode()).To(Equal(0)) } runInRootlessContext(f) }) |