mirror of
https://github.com/containers/podman.git
synced 2025-06-21 01:19:15 +08:00
Merge pull request #9095 from rhatdan/ps
podman-remote ps --external --pod --sort do not work.
This commit is contained in:
@ -78,7 +78,7 @@ func listFlagSet(cmd *cobra.Command) {
|
|||||||
flags := cmd.Flags()
|
flags := cmd.Flags()
|
||||||
|
|
||||||
flags.BoolVarP(&listOpts.All, "all", "a", false, "Show all the containers, default is only running containers")
|
flags.BoolVarP(&listOpts.All, "all", "a", false, "Show all the containers, default is only running containers")
|
||||||
flags.BoolVar(&listOpts.Storage, "external", false, "Show containers in storage not controlled by Podman")
|
flags.BoolVar(&listOpts.External, "external", false, "Show containers in storage not controlled by Podman")
|
||||||
|
|
||||||
filterFlagName := "filter"
|
filterFlagName := "filter"
|
||||||
flags.StringSliceVarP(&filters, filterFlagName, "f", []string{}, "Filter output based on conditions given")
|
flags.StringSliceVarP(&filters, filterFlagName, "f", []string{}, "Filter output based on conditions given")
|
||||||
@ -132,10 +132,10 @@ func checkFlags(c *cobra.Command) error {
|
|||||||
}
|
}
|
||||||
cfg := registry.PodmanConfig()
|
cfg := registry.PodmanConfig()
|
||||||
if cfg.Engine.Namespace != "" {
|
if cfg.Engine.Namespace != "" {
|
||||||
if c.Flag("storage").Changed && listOpts.Storage {
|
if c.Flag("storage").Changed && listOpts.External {
|
||||||
return errors.New("--namespace and --storage flags can not both be set")
|
return errors.New("--namespace and --external flags can not both be set")
|
||||||
}
|
}
|
||||||
listOpts.Storage = false
|
listOpts.External = false
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
@ -140,6 +140,10 @@ func removeContainers(namesOrIDs []string, rmOptions entities.RmOptions, setExit
|
|||||||
}
|
}
|
||||||
|
|
||||||
func setExitCode(err error) {
|
func setExitCode(err error) {
|
||||||
|
// If error is set to no such container, do not reset
|
||||||
|
if registry.GetExitCode() == 1 {
|
||||||
|
return
|
||||||
|
}
|
||||||
cause := errors.Cause(err)
|
cause := errors.Cause(err)
|
||||||
switch {
|
switch {
|
||||||
case cause == define.ErrNoSuchCtr:
|
case cause == define.ErrNoSuchCtr:
|
||||||
|
@ -73,7 +73,7 @@ func RemoveContainer(w http.ResponseWriter, r *http.Request) {
|
|||||||
utils.InternalServerError(w, err)
|
utils.InternalServerError(w, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if report[0].Err != nil {
|
if len(report) > 0 && report[0].Err != nil {
|
||||||
utils.InternalServerError(w, report[0].Err)
|
utils.InternalServerError(w, report[0].Err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -12,7 +12,6 @@ import (
|
|||||||
"github.com/containers/podman/v2/pkg/api/handlers/utils"
|
"github.com/containers/podman/v2/pkg/api/handlers/utils"
|
||||||
"github.com/containers/podman/v2/pkg/domain/entities"
|
"github.com/containers/podman/v2/pkg/domain/entities"
|
||||||
"github.com/containers/podman/v2/pkg/domain/infra/abi"
|
"github.com/containers/podman/v2/pkg/domain/infra/abi"
|
||||||
"github.com/containers/podman/v2/pkg/ps"
|
|
||||||
"github.com/gorilla/schema"
|
"github.com/gorilla/schema"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
@ -63,6 +62,7 @@ func ListContainers(w http.ResponseWriter, r *http.Request) {
|
|||||||
decoder := r.Context().Value("decoder").(*schema.Decoder)
|
decoder := r.Context().Value("decoder").(*schema.Decoder)
|
||||||
query := struct {
|
query := struct {
|
||||||
All bool `schema:"all"`
|
All bool `schema:"all"`
|
||||||
|
External bool `schema:"external"`
|
||||||
Filters map[string][]string `schema:"filters"`
|
Filters map[string][]string `schema:"filters"`
|
||||||
Last int `schema:"last"` // alias for limit
|
Last int `schema:"last"` // alias for limit
|
||||||
Limit int `schema:"limit"`
|
Limit int `schema:"limit"`
|
||||||
@ -90,17 +90,22 @@ func ListContainers(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
runtime := r.Context().Value("runtime").(*libpod.Runtime)
|
runtime := r.Context().Value("runtime").(*libpod.Runtime)
|
||||||
|
// Now use the ABI implementation to prevent us from having duplicate
|
||||||
|
// code.
|
||||||
|
containerEngine := abi.ContainerEngine{Libpod: runtime}
|
||||||
opts := entities.ContainerListOptions{
|
opts := entities.ContainerListOptions{
|
||||||
All: query.All,
|
All: query.All,
|
||||||
|
External: query.External,
|
||||||
Filters: query.Filters,
|
Filters: query.Filters,
|
||||||
Last: limit,
|
Last: limit,
|
||||||
Size: query.Size,
|
|
||||||
Sort: "",
|
|
||||||
Namespace: query.Namespace,
|
Namespace: query.Namespace,
|
||||||
Pod: true,
|
// Always return Pod, should not be part of the API.
|
||||||
Sync: query.Sync,
|
// https://github.com/containers/podman/pull/7223
|
||||||
|
Pod: true,
|
||||||
|
Size: query.Size,
|
||||||
|
Sync: query.Sync,
|
||||||
}
|
}
|
||||||
pss, err := ps.GetContainerLists(runtime, opts)
|
pss, err := containerEngine.ContainerList(r.Context(), opts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
utils.InternalServerError(w, err)
|
utils.InternalServerError(w, err)
|
||||||
return
|
return
|
||||||
|
@ -48,6 +48,11 @@ func (s *APIServer) registerContainersHandlers(r *mux.Router) error {
|
|||||||
// default: false
|
// default: false
|
||||||
// description: Return all containers. By default, only running containers are shown
|
// description: Return all containers. By default, only running containers are shown
|
||||||
// - in: query
|
// - in: query
|
||||||
|
// name: external
|
||||||
|
// type: boolean
|
||||||
|
// default: false
|
||||||
|
// description: Return containers in storage not controlled by Podman
|
||||||
|
// - in: query
|
||||||
// name: limit
|
// name: limit
|
||||||
// description: Return this number of most recently created containers, including non-running ones.
|
// description: Return this number of most recently created containers, including non-running ones.
|
||||||
// type: integer
|
// type: integer
|
||||||
|
@ -106,6 +106,7 @@ type MountedContainerPathsOptions struct{}
|
|||||||
// ListOptions are optional options for listing containers
|
// ListOptions are optional options for listing containers
|
||||||
type ListOptions struct {
|
type ListOptions struct {
|
||||||
All *bool
|
All *bool
|
||||||
|
External *bool
|
||||||
Filters map[string][]string
|
Filters map[string][]string
|
||||||
Last *int
|
Last *int
|
||||||
Namespace *bool
|
Namespace *bool
|
||||||
|
@ -103,6 +103,22 @@ func (o *ListOptions) GetAll() bool {
|
|||||||
return *o.All
|
return *o.All
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// WithExternal
|
||||||
|
func (o *ListOptions) WithExternal(value bool) *ListOptions {
|
||||||
|
v := &value
|
||||||
|
o.External = v
|
||||||
|
return o
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetExternal
|
||||||
|
func (o *ListOptions) GetExternal() bool {
|
||||||
|
var external bool
|
||||||
|
if o.External == nil {
|
||||||
|
return external
|
||||||
|
}
|
||||||
|
return *o.External
|
||||||
|
}
|
||||||
|
|
||||||
// WithFilters
|
// WithFilters
|
||||||
func (o *ListOptions) WithFilters(value map[string][]string) *ListOptions {
|
func (o *ListOptions) WithFilters(value map[string][]string) *ListOptions {
|
||||||
v := value
|
v := value
|
||||||
|
@ -297,8 +297,8 @@ type ContainerListOptions struct {
|
|||||||
Pod bool
|
Pod bool
|
||||||
Quiet bool
|
Quiet bool
|
||||||
Size bool
|
Size bool
|
||||||
|
External bool
|
||||||
Sort string
|
Sort string
|
||||||
Storage bool
|
|
||||||
Sync bool
|
Sync bool
|
||||||
Watch uint
|
Watch uint
|
||||||
}
|
}
|
||||||
|
@ -173,19 +173,32 @@ func (ic *ContainerEngine) ContainerRestart(ctx context.Context, namesOrIds []st
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (ic *ContainerEngine) ContainerRm(ctx context.Context, namesOrIds []string, opts entities.RmOptions) ([]*entities.RmReport, error) {
|
func (ic *ContainerEngine) ContainerRm(ctx context.Context, namesOrIds []string, opts entities.RmOptions) ([]*entities.RmReport, error) {
|
||||||
ctrs, err := getContainersByContext(ic.ClientCtx, opts.All, opts.Ignore, namesOrIds)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
// TODO there is no endpoint for container eviction. Need to discuss
|
// TODO there is no endpoint for container eviction. Need to discuss
|
||||||
reports := make([]*entities.RmReport, 0, len(ctrs))
|
options := new(containers.RemoveOptions).WithForce(opts.Force).WithVolumes(opts.Volumes).WithIgnore(opts.Ignore)
|
||||||
options := new(containers.RemoveOptions).WithForce(opts.Force).WithVolumes(opts.Volumes)
|
|
||||||
for _, c := range ctrs {
|
if opts.All {
|
||||||
|
ctrs, err := getContainersByContext(ic.ClientCtx, opts.All, opts.Ignore, namesOrIds)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
reports := make([]*entities.RmReport, 0, len(ctrs))
|
||||||
|
for _, c := range ctrs {
|
||||||
|
reports = append(reports, &entities.RmReport{
|
||||||
|
Id: c.ID,
|
||||||
|
Err: containers.Remove(ic.ClientCtx, c.ID, options),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
return reports, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
reports := make([]*entities.RmReport, 0, len(namesOrIds))
|
||||||
|
for _, name := range namesOrIds {
|
||||||
reports = append(reports, &entities.RmReport{
|
reports = append(reports, &entities.RmReport{
|
||||||
Id: c.ID,
|
Id: name,
|
||||||
Err: containers.Remove(ic.ClientCtx, c.ID, options),
|
Err: containers.Remove(ic.ClientCtx, name, options),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
return reports, nil
|
return reports, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -601,7 +614,7 @@ func (ic *ContainerEngine) ContainerStart(ctx context.Context, namesOrIds []stri
|
|||||||
|
|
||||||
func (ic *ContainerEngine) ContainerList(ctx context.Context, opts entities.ContainerListOptions) ([]entities.ListContainer, error) {
|
func (ic *ContainerEngine) ContainerList(ctx context.Context, opts entities.ContainerListOptions) ([]entities.ListContainer, error) {
|
||||||
options := new(containers.ListOptions).WithFilters(opts.Filters).WithAll(opts.All).WithLast(opts.Last)
|
options := new(containers.ListOptions).WithFilters(opts.Filters).WithAll(opts.All).WithLast(opts.Last)
|
||||||
options.WithNamespace(opts.Namespace).WithSize(opts.Size).WithSync(opts.Sync)
|
options.WithNamespace(opts.Namespace).WithSize(opts.Size).WithSync(opts.Sync).WithExternal(opts.External)
|
||||||
return containers.List(ic.ClientCtx, options)
|
return containers.List(ic.ClientCtx, options)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -69,7 +69,7 @@ func GetContainerLists(runtime *libpod.Runtime, options entities.ContainerListOp
|
|||||||
pss = append(pss, listCon)
|
pss = append(pss, listCon)
|
||||||
}
|
}
|
||||||
|
|
||||||
if options.All && options.Storage {
|
if options.All && options.External {
|
||||||
externCons, err := runtime.StorageContainers()
|
externCons, err := runtime.StorageContainers()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -396,11 +396,14 @@ var _ = Describe("Podman ps", func() {
|
|||||||
session.WaitWithDefaultTimeout()
|
session.WaitWithDefaultTimeout()
|
||||||
Expect(session.ExitCode()).To(Equal(0))
|
Expect(session.ExitCode()).To(Equal(0))
|
||||||
|
|
||||||
session = podmanTest.Podman([]string{"ps", "--pod", "--no-trunc"})
|
session = podmanTest.Podman([]string{"ps", "--no-trunc"})
|
||||||
|
|
||||||
session.WaitWithDefaultTimeout()
|
session.WaitWithDefaultTimeout()
|
||||||
Expect(session.ExitCode()).To(Equal(0))
|
Expect(session.ExitCode()).To(Equal(0))
|
||||||
|
Expect(session.OutputToString()).To(Not(ContainSubstring(podid)))
|
||||||
|
|
||||||
|
session = podmanTest.Podman([]string{"ps", "--pod", "--no-trunc"})
|
||||||
|
session.WaitWithDefaultTimeout()
|
||||||
|
Expect(session.ExitCode()).To(Equal(0))
|
||||||
Expect(session.OutputToString()).To(ContainSubstring(podid))
|
Expect(session.OutputToString()).To(ContainSubstring(podid))
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -132,7 +132,7 @@ var _ = Describe("Podman rm", func() {
|
|||||||
|
|
||||||
latest := "-l"
|
latest := "-l"
|
||||||
if IsRemote() {
|
if IsRemote() {
|
||||||
latest = "test1"
|
latest = cid
|
||||||
}
|
}
|
||||||
result := podmanTest.Podman([]string{"rm", latest})
|
result := podmanTest.Podman([]string{"rm", latest})
|
||||||
result.WaitWithDefaultTimeout()
|
result.WaitWithDefaultTimeout()
|
||||||
|
@ -82,11 +82,10 @@ load helpers
|
|||||||
run_podman rm -a
|
run_podman rm -a
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "podman ps -a --storage" {
|
@test "podman ps -a --external" {
|
||||||
skip_if_remote "ps --storage does not work over remote"
|
|
||||||
|
|
||||||
# Setup: ensure that we have no hidden storage containers
|
# Setup: ensure that we have no hidden storage containers
|
||||||
run_podman ps --storage -a
|
run_podman ps --external -a
|
||||||
is "${#lines[@]}" "1" "setup check: no storage containers at start of test"
|
is "${#lines[@]}" "1" "setup check: no storage containers at start of test"
|
||||||
|
|
||||||
# Force a buildah timeout; this leaves a buildah container behind
|
# Force a buildah timeout; this leaves a buildah container behind
|
||||||
@ -98,18 +97,18 @@ EOF
|
|||||||
run_podman ps -a
|
run_podman ps -a
|
||||||
is "${#lines[@]}" "1" "podman ps -a does not see buildah container"
|
is "${#lines[@]}" "1" "podman ps -a does not see buildah container"
|
||||||
|
|
||||||
run_podman ps --storage -a
|
run_podman ps --external -a
|
||||||
is "${#lines[@]}" "2" "podman ps -a --storage sees buildah container"
|
is "${#lines[@]}" "2" "podman ps -a --external sees buildah container"
|
||||||
is "${lines[1]}" \
|
is "${lines[1]}" \
|
||||||
"[0-9a-f]\{12\} \+$IMAGE *buildah .* seconds ago .* storage .* ${PODMAN_TEST_IMAGE_NAME}-working-container" \
|
"[0-9a-f]\{12\} \+$IMAGE *buildah .* seconds ago .* storage .* ${PODMAN_TEST_IMAGE_NAME}-working-container" \
|
||||||
"podman ps --storage"
|
"podman ps --external"
|
||||||
|
|
||||||
cid="${lines[1]:0:12}"
|
cid="${lines[1]:0:12}"
|
||||||
|
|
||||||
# 'rm -a' should be a NOP
|
# 'rm -a' should be a NOP
|
||||||
run_podman rm -a
|
run_podman rm -a
|
||||||
run_podman ps --storage -a
|
run_podman ps --external -a
|
||||||
is "${#lines[@]}" "2" "podman ps -a --storage sees buildah container"
|
is "${#lines[@]}" "2" "podman ps -a --external sees buildah container"
|
||||||
|
|
||||||
# We can't rm it without -f, but podman should issue a helpful message
|
# We can't rm it without -f, but podman should issue a helpful message
|
||||||
run_podman 2 rm "$cid"
|
run_podman 2 rm "$cid"
|
||||||
@ -118,7 +117,7 @@ EOF
|
|||||||
# With -f, we can remove it.
|
# With -f, we can remove it.
|
||||||
run_podman rm -f "$cid"
|
run_podman rm -f "$cid"
|
||||||
|
|
||||||
run_podman ps --storage -a
|
run_podman ps --external -a
|
||||||
is "${#lines[@]}" "1" "storage container has been removed"
|
is "${#lines[@]}" "1" "storage container has been removed"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user