mirror of
https://github.com/containers/podman.git
synced 2025-06-24 19:42:56 +08:00
Merge pull request #7909 from zhangguanzhang/remote-ps-ns-broken
Fix podman-remote ps --ns broken
This commit is contained in:
@ -240,7 +240,7 @@ func ps(cmd *cobra.Command, args []string) error {
|
|||||||
func createPsOut() (string, string) {
|
func createPsOut() (string, string) {
|
||||||
var row string
|
var row string
|
||||||
if listOpts.Namespace {
|
if listOpts.Namespace {
|
||||||
headers := "CONTAINER ID\tNAMES\tPID\tCGROUPNS\tIPC\tMNT\tNET\tPIDN\tUSERNS\tUTS\n"
|
headers := "CONTAINER ID\tNAMES\tPID\tCGROUPNS\tIPC\tMNT\tNET\tPIDNS\tUSERNS\tUTS\n"
|
||||||
row := "{{.ID}}\t{{.Names}}\t{{.Pid}}\t{{.Namespaces.Cgroup}}\t{{.Namespaces.IPC}}\t{{.Namespaces.MNT}}\t{{.Namespaces.NET}}\t{{.Namespaces.PIDNS}}\t{{.Namespaces.User}}\t{{.Namespaces.UTS}}\n"
|
row := "{{.ID}}\t{{.Names}}\t{{.Pid}}\t{{.Namespaces.Cgroup}}\t{{.Namespaces.IPC}}\t{{.Namespaces.MNT}}\t{{.Namespaces.NET}}\t{{.Namespaces.PIDNS}}\t{{.Namespaces.User}}\t{{.Namespaces.UTS}}\n"
|
||||||
return headers, row
|
return headers, row
|
||||||
}
|
}
|
||||||
|
@ -25,7 +25,7 @@ var (
|
|||||||
// the most recent number of containers. The pod and size booleans indicate that pod information and rootfs
|
// the most recent number of containers. The pod and size booleans indicate that pod information and rootfs
|
||||||
// size information should also be included. Finally, the sync bool synchronizes the OCI runtime and
|
// size information should also be included. Finally, the sync bool synchronizes the OCI runtime and
|
||||||
// container state.
|
// container state.
|
||||||
func List(ctx context.Context, filters map[string][]string, all *bool, last *int, size, sync *bool) ([]entities.ListContainer, error) { // nolint:typecheck
|
func List(ctx context.Context, filters map[string][]string, all *bool, last *int, namespace, size, sync *bool) ([]entities.ListContainer, error) { // nolint:typecheck
|
||||||
conn, err := bindings.GetClient(ctx)
|
conn, err := bindings.GetClient(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -44,6 +44,9 @@ func List(ctx context.Context, filters map[string][]string, all *bool, last *int
|
|||||||
if sync != nil {
|
if sync != nil {
|
||||||
params.Set("sync", strconv.FormatBool(*sync))
|
params.Set("sync", strconv.FormatBool(*sync))
|
||||||
}
|
}
|
||||||
|
if namespace != nil {
|
||||||
|
params.Set("namespace", strconv.FormatBool(*namespace))
|
||||||
|
}
|
||||||
if filters != nil {
|
if filters != nil {
|
||||||
filterString, err := bindings.FiltersToString(filters)
|
filterString, err := bindings.FiltersToString(filters)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -499,7 +499,7 @@ var _ = Describe("Podman containers ", func() {
|
|||||||
Expect(err).To(BeNil())
|
Expect(err).To(BeNil())
|
||||||
_, err = bt.RunTopContainer(&name2, bindings.PFalse, nil)
|
_, err = bt.RunTopContainer(&name2, bindings.PFalse, nil)
|
||||||
Expect(err).To(BeNil())
|
Expect(err).To(BeNil())
|
||||||
containerLatestList, err := containers.List(bt.conn, nil, nil, &latestContainers, nil, nil)
|
containerLatestList, err := containers.List(bt.conn, nil, nil, &latestContainers, nil, nil, nil)
|
||||||
Expect(err).To(BeNil())
|
Expect(err).To(BeNil())
|
||||||
err = containers.Kill(bt.conn, containerLatestList[0].Names[0], "SIGTERM")
|
err = containers.Kill(bt.conn, containerLatestList[0].Names[0], "SIGTERM")
|
||||||
Expect(err).To(BeNil())
|
Expect(err).To(BeNil())
|
||||||
@ -744,7 +744,7 @@ var _ = Describe("Podman containers ", func() {
|
|||||||
// Validate list container with id filter
|
// Validate list container with id filter
|
||||||
filters := make(map[string][]string)
|
filters := make(map[string][]string)
|
||||||
filters["id"] = []string{cid}
|
filters["id"] = []string{cid}
|
||||||
c, err := containers.List(bt.conn, filters, bindings.PTrue, nil, nil, nil)
|
c, err := containers.List(bt.conn, filters, bindings.PTrue, nil, nil, nil, nil)
|
||||||
Expect(err).To(BeNil())
|
Expect(err).To(BeNil())
|
||||||
Expect(len(c)).To(Equal(1))
|
Expect(len(c)).To(Equal(1))
|
||||||
})
|
})
|
||||||
@ -758,7 +758,7 @@ var _ = Describe("Podman containers ", func() {
|
|||||||
|
|
||||||
lastNum := 1
|
lastNum := 1
|
||||||
|
|
||||||
c, err := containers.List(bt.conn, nil, bindings.PTrue, &lastNum, nil, nil)
|
c, err := containers.List(bt.conn, nil, bindings.PTrue, &lastNum, nil, nil, nil)
|
||||||
Expect(err).To(BeNil())
|
Expect(err).To(BeNil())
|
||||||
Expect(len(c)).To(Equal(1))
|
Expect(len(c)).To(Equal(1))
|
||||||
Expect(c[0].PodName).To(Equal(podName))
|
Expect(c[0].PodName).To(Equal(podName))
|
||||||
|
@ -548,7 +548,7 @@ func (ic *ContainerEngine) ContainerStart(ctx context.Context, namesOrIds []stri
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (ic *ContainerEngine) ContainerList(ctx context.Context, options entities.ContainerListOptions) ([]entities.ListContainer, error) {
|
func (ic *ContainerEngine) ContainerList(ctx context.Context, options entities.ContainerListOptions) ([]entities.ListContainer, error) {
|
||||||
return containers.List(ic.ClientCxt, options.Filters, &options.All, &options.Last, &options.Size, &options.Sync)
|
return containers.List(ic.ClientCxt, options.Filters, &options.All, &options.Last, &options.Namespace, &options.Size, &options.Sync)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ic *ContainerEngine) ContainerRun(ctx context.Context, opts entities.ContainerRunOptions) (*entities.ContainerRunReport, error) {
|
func (ic *ContainerEngine) ContainerRun(ctx context.Context, opts entities.ContainerRunOptions) (*entities.ContainerRunReport, error) {
|
||||||
|
@ -19,7 +19,7 @@ func getContainersByContext(contextWithConnection context.Context, all, ignore b
|
|||||||
return nil, errors.New("cannot lookup containers and all")
|
return nil, errors.New("cannot lookup containers and all")
|
||||||
}
|
}
|
||||||
|
|
||||||
allContainers, err := containers.List(contextWithConnection, nil, bindings.PTrue, nil, nil, bindings.PTrue)
|
allContainers, err := containers.List(contextWithConnection, nil, bindings.PTrue, nil, nil, nil, bindings.PTrue)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -134,15 +134,16 @@ func ListContainerBatch(rt *libpod.Runtime, ctr *libpod.Container, opts entities
|
|||||||
logrus.Errorf("error getting exited time for %q: %v", c.ID(), err)
|
logrus.Errorf("error getting exited time for %q: %v", c.ID(), err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pid, err = c.PID()
|
||||||
|
if err != nil {
|
||||||
|
return errors.Wrapf(err, "unable to obtain container pid")
|
||||||
|
}
|
||||||
|
|
||||||
if !opts.Size && !opts.Namespace {
|
if !opts.Size && !opts.Namespace {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
if opts.Namespace {
|
if opts.Namespace {
|
||||||
pid, err = c.PID()
|
|
||||||
if err != nil {
|
|
||||||
return errors.Wrapf(err, "unable to obtain container pid")
|
|
||||||
}
|
|
||||||
ctrPID := strconv.Itoa(pid)
|
ctrPID := strconv.Itoa(pid)
|
||||||
cgroup, _ = getNamespaceInfo(filepath.Join("/proc", ctrPID, "ns", "cgroup"))
|
cgroup, _ = getNamespaceInfo(filepath.Join("/proc", ctrPID, "ns", "cgroup"))
|
||||||
ipc, _ = getNamespaceInfo(filepath.Join("/proc", ctrPID, "ns", "ipc"))
|
ipc, _ = getNamespaceInfo(filepath.Join("/proc", ctrPID, "ns", "ipc"))
|
||||||
|
@ -225,7 +225,6 @@ var _ = Describe("Podman pod create", func() {
|
|||||||
})
|
})
|
||||||
|
|
||||||
It("podman pod container can override pod pid NS", func() {
|
It("podman pod container can override pod pid NS", func() {
|
||||||
SkipIfRemote("FIXME This should work on podman-remote")
|
|
||||||
session := podmanTest.Podman([]string{"pod", "create", "--share", "pid"})
|
session := podmanTest.Podman([]string{"pod", "create", "--share", "pid"})
|
||||||
session.WaitWithDefaultTimeout()
|
session.WaitWithDefaultTimeout()
|
||||||
Expect(session.ExitCode()).To(Equal(0))
|
Expect(session.ExitCode()).To(Equal(0))
|
||||||
@ -257,7 +256,6 @@ var _ = Describe("Podman pod create", func() {
|
|||||||
})
|
})
|
||||||
|
|
||||||
It("podman pod container can override pod not sharing pid", func() {
|
It("podman pod container can override pod not sharing pid", func() {
|
||||||
SkipIfRemote("FIXME This should work on podman-remote")
|
|
||||||
session := podmanTest.Podman([]string{"pod", "create", "--share", "net"})
|
session := podmanTest.Podman([]string{"pod", "create", "--share", "net"})
|
||||||
session.WaitWithDefaultTimeout()
|
session.WaitWithDefaultTimeout()
|
||||||
Expect(session.ExitCode()).To(Equal(0))
|
Expect(session.ExitCode()).To(Equal(0))
|
||||||
@ -283,7 +281,6 @@ var _ = Describe("Podman pod create", func() {
|
|||||||
})
|
})
|
||||||
|
|
||||||
It("podman pod container can override pod ipc NS", func() {
|
It("podman pod container can override pod ipc NS", func() {
|
||||||
SkipIfRemote("FIXME This should work on podman-remote")
|
|
||||||
session := podmanTest.Podman([]string{"pod", "create", "--share", "ipc"})
|
session := podmanTest.Podman([]string{"pod", "create", "--share", "ipc"})
|
||||||
session.WaitWithDefaultTimeout()
|
session.WaitWithDefaultTimeout()
|
||||||
Expect(session.ExitCode()).To(Equal(0))
|
Expect(session.ExitCode()).To(Equal(0))
|
||||||
|
@ -173,6 +173,18 @@ var _ = Describe("Podman ps", func() {
|
|||||||
Expect(len(result.OutputToStringArray())).Should(BeNumerically(">", 0))
|
Expect(len(result.OutputToStringArray())).Should(BeNumerically(">", 0))
|
||||||
})
|
})
|
||||||
|
|
||||||
|
It("podman ps namespace flag even for remote", func() {
|
||||||
|
session := podmanTest.RunTopContainer("test1")
|
||||||
|
session.WaitWithDefaultTimeout()
|
||||||
|
|
||||||
|
result := podmanTest.Podman([]string{"ps", "-a", "--namespace", "--format",
|
||||||
|
"{{with .Namespaces}}{{.Cgroup}}:{{.IPC}}:{{.MNT}}:{{.NET}}:{{.PIDNS}}:{{.User}}:{{.UTS}}{{end}}"})
|
||||||
|
result.WaitWithDefaultTimeout()
|
||||||
|
Expect(result.ExitCode()).To(Equal(0))
|
||||||
|
// it must contains `::` when some ns is null. If it works normally, it should be "$num1:$num2:$num3"
|
||||||
|
Expect(result.OutputToString()).To(Not(ContainSubstring(`::`)))
|
||||||
|
})
|
||||||
|
|
||||||
It("podman ps with no containers is valid json format", func() {
|
It("podman ps with no containers is valid json format", func() {
|
||||||
result := podmanTest.Podman([]string{"ps", "--format", "json"})
|
result := podmanTest.Podman([]string{"ps", "--format", "json"})
|
||||||
result.WaitWithDefaultTimeout()
|
result.WaitWithDefaultTimeout()
|
||||||
|
Reference in New Issue
Block a user