mirror of
https://github.com/containers/podman.git
synced 2025-12-05 21:32:22 +08:00
rootless: fix pod top
we need to join the namespace of the target pod. Closes: https://github.com/containers/libpod/issues/2682 Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
This commit is contained in:
@@ -75,6 +75,7 @@ var cmdsNotRequiringRootless = map[*cobra.Command]bool{
|
|||||||
_podKillCommand: true,
|
_podKillCommand: true,
|
||||||
_podStatsCommand: true,
|
_podStatsCommand: true,
|
||||||
_podStopCommand: true,
|
_podStopCommand: true,
|
||||||
|
_podTopCommand: true,
|
||||||
_restartCommand: true,
|
_restartCommand: true,
|
||||||
_rmCommand: true,
|
_rmCommand: true,
|
||||||
_runCommand: true,
|
_runCommand: true,
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import (
|
|||||||
|
|
||||||
"github.com/containers/libpod/cmd/podman/cliconfig"
|
"github.com/containers/libpod/cmd/podman/cliconfig"
|
||||||
"github.com/containers/libpod/libpod"
|
"github.com/containers/libpod/libpod"
|
||||||
|
"github.com/containers/libpod/pkg/rootless"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
@@ -53,6 +54,10 @@ func podTopCmd(c *cliconfig.PodTopValues) error {
|
|||||||
)
|
)
|
||||||
args := c.InputArgs
|
args := c.InputArgs
|
||||||
|
|
||||||
|
if os.Geteuid() != 0 {
|
||||||
|
rootless.SetSkipStorageSetup(true)
|
||||||
|
}
|
||||||
|
|
||||||
if c.ListDescriptors {
|
if c.ListDescriptors {
|
||||||
descriptors, err := libpod.GetContainerPidInformationDescriptors()
|
descriptors, err := libpod.GetContainerPidInformationDescriptors()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -77,6 +82,27 @@ func podTopCmd(c *cliconfig.PodTopValues) error {
|
|||||||
} else {
|
} else {
|
||||||
descriptors = args[1:]
|
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)
|
w := tabwriter.NewWriter(os.Stdout, 5, 1, 3, ' ', 0)
|
||||||
psOutput, err := runtime.PodTop(c, descriptors)
|
psOutput, err := runtime.PodTop(c, descriptors)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -138,6 +138,21 @@ var _ = Describe("Podman rootless", func() {
|
|||||||
cmd.WaitWithDefaultTimeout()
|
cmd.WaitWithDefaultTimeout()
|
||||||
Expect(cmd.ExitCode()).To(Equal(0))
|
Expect(cmd.ExitCode()).To(Equal(0))
|
||||||
Expect(cmd.LineInOutputContains("hello")).To(BeTrue())
|
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)
|
runInRootlessContext(f)
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user