mirror of
https://github.com/containers/podman.git
synced 2025-06-20 17:13:43 +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.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"
|
||||
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()
|
||||
if cfg.Engine.Namespace != "" {
|
||||
if c.Flag("storage").Changed && listOpts.Storage {
|
||||
return errors.New("--namespace and --storage flags can not both be set")
|
||||
if c.Flag("storage").Changed && listOpts.External {
|
||||
return errors.New("--namespace and --external flags can not both be set")
|
||||
}
|
||||
listOpts.Storage = false
|
||||
listOpts.External = false
|
||||
}
|
||||
|
||||
return nil
|
||||
|
@ -140,6 +140,10 @@ func removeContainers(namesOrIDs []string, rmOptions entities.RmOptions, setExit
|
||||
}
|
||||
|
||||
func setExitCode(err error) {
|
||||
// If error is set to no such container, do not reset
|
||||
if registry.GetExitCode() == 1 {
|
||||
return
|
||||
}
|
||||
cause := errors.Cause(err)
|
||||
switch {
|
||||
case cause == define.ErrNoSuchCtr:
|
||||
|
@ -73,7 +73,7 @@ func RemoveContainer(w http.ResponseWriter, r *http.Request) {
|
||||
utils.InternalServerError(w, err)
|
||||
return
|
||||
}
|
||||
if report[0].Err != nil {
|
||||
if len(report) > 0 && report[0].Err != nil {
|
||||
utils.InternalServerError(w, report[0].Err)
|
||||
return
|
||||
}
|
||||
|
@ -12,7 +12,6 @@ import (
|
||||
"github.com/containers/podman/v2/pkg/api/handlers/utils"
|
||||
"github.com/containers/podman/v2/pkg/domain/entities"
|
||||
"github.com/containers/podman/v2/pkg/domain/infra/abi"
|
||||
"github.com/containers/podman/v2/pkg/ps"
|
||||
"github.com/gorilla/schema"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/sirupsen/logrus"
|
||||
@ -63,6 +62,7 @@ func ListContainers(w http.ResponseWriter, r *http.Request) {
|
||||
decoder := r.Context().Value("decoder").(*schema.Decoder)
|
||||
query := struct {
|
||||
All bool `schema:"all"`
|
||||
External bool `schema:"external"`
|
||||
Filters map[string][]string `schema:"filters"`
|
||||
Last int `schema:"last"` // alias for limit
|
||||
Limit int `schema:"limit"`
|
||||
@ -90,17 +90,22 @@ func ListContainers(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
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{
|
||||
All: query.All,
|
||||
External: query.External,
|
||||
Filters: query.Filters,
|
||||
Last: limit,
|
||||
Size: query.Size,
|
||||
Sort: "",
|
||||
Namespace: query.Namespace,
|
||||
// Always return Pod, should not be part of the API.
|
||||
// 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 {
|
||||
utils.InternalServerError(w, err)
|
||||
return
|
||||
|
@ -48,6 +48,11 @@ func (s *APIServer) registerContainersHandlers(r *mux.Router) error {
|
||||
// default: false
|
||||
// description: Return all containers. By default, only running containers are shown
|
||||
// - in: query
|
||||
// name: external
|
||||
// type: boolean
|
||||
// default: false
|
||||
// description: Return containers in storage not controlled by Podman
|
||||
// - in: query
|
||||
// name: limit
|
||||
// description: Return this number of most recently created containers, including non-running ones.
|
||||
// type: integer
|
||||
|
@ -106,6 +106,7 @@ type MountedContainerPathsOptions struct{}
|
||||
// ListOptions are optional options for listing containers
|
||||
type ListOptions struct {
|
||||
All *bool
|
||||
External *bool
|
||||
Filters map[string][]string
|
||||
Last *int
|
||||
Namespace *bool
|
||||
|
@ -103,6 +103,22 @@ func (o *ListOptions) GetAll() bool {
|
||||
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
|
||||
func (o *ListOptions) WithFilters(value map[string][]string) *ListOptions {
|
||||
v := value
|
||||
|
@ -297,8 +297,8 @@ type ContainerListOptions struct {
|
||||
Pod bool
|
||||
Quiet bool
|
||||
Size bool
|
||||
External bool
|
||||
Sort string
|
||||
Storage bool
|
||||
Sync bool
|
||||
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) {
|
||||
// TODO there is no endpoint for container eviction. Need to discuss
|
||||
options := new(containers.RemoveOptions).WithForce(opts.Force).WithVolumes(opts.Volumes).WithIgnore(opts.Ignore)
|
||||
|
||||
if opts.All {
|
||||
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
|
||||
reports := make([]*entities.RmReport, 0, len(ctrs))
|
||||
options := new(containers.RemoveOptions).WithForce(opts.Force).WithVolumes(opts.Volumes)
|
||||
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{
|
||||
Id: name,
|
||||
Err: containers.Remove(ic.ClientCtx, name, options),
|
||||
})
|
||||
}
|
||||
|
||||
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) {
|
||||
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)
|
||||
}
|
||||
|
||||
|
@ -69,7 +69,7 @@ func GetContainerLists(runtime *libpod.Runtime, options entities.ContainerListOp
|
||||
pss = append(pss, listCon)
|
||||
}
|
||||
|
||||
if options.All && options.Storage {
|
||||
if options.All && options.External {
|
||||
externCons, err := runtime.StorageContainers()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -396,11 +396,14 @@ var _ = Describe("Podman ps", func() {
|
||||
session.WaitWithDefaultTimeout()
|
||||
Expect(session.ExitCode()).To(Equal(0))
|
||||
|
||||
session = podmanTest.Podman([]string{"ps", "--pod", "--no-trunc"})
|
||||
|
||||
session = podmanTest.Podman([]string{"ps", "--no-trunc"})
|
||||
session.WaitWithDefaultTimeout()
|
||||
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))
|
||||
})
|
||||
|
||||
|
@ -132,7 +132,7 @@ var _ = Describe("Podman rm", func() {
|
||||
|
||||
latest := "-l"
|
||||
if IsRemote() {
|
||||
latest = "test1"
|
||||
latest = cid
|
||||
}
|
||||
result := podmanTest.Podman([]string{"rm", latest})
|
||||
result.WaitWithDefaultTimeout()
|
||||
|
@ -82,11 +82,10 @@ load helpers
|
||||
run_podman rm -a
|
||||
}
|
||||
|
||||
@test "podman ps -a --storage" {
|
||||
skip_if_remote "ps --storage does not work over remote"
|
||||
@test "podman ps -a --external" {
|
||||
|
||||
# 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"
|
||||
|
||||
# Force a buildah timeout; this leaves a buildah container behind
|
||||
@ -98,18 +97,18 @@ EOF
|
||||
run_podman ps -a
|
||||
is "${#lines[@]}" "1" "podman ps -a does not see buildah container"
|
||||
|
||||
run_podman ps --storage -a
|
||||
is "${#lines[@]}" "2" "podman ps -a --storage sees buildah container"
|
||||
run_podman ps --external -a
|
||||
is "${#lines[@]}" "2" "podman ps -a --external sees buildah container"
|
||||
is "${lines[1]}" \
|
||||
"[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}"
|
||||
|
||||
# 'rm -a' should be a NOP
|
||||
run_podman rm -a
|
||||
run_podman ps --storage -a
|
||||
is "${#lines[@]}" "2" "podman ps -a --storage sees buildah container"
|
||||
run_podman ps --external -a
|
||||
is "${#lines[@]}" "2" "podman ps -a --external sees buildah container"
|
||||
|
||||
# We can't rm it without -f, but podman should issue a helpful message
|
||||
run_podman 2 rm "$cid"
|
||||
@ -118,7 +117,7 @@ EOF
|
||||
# With -f, we can remove it.
|
||||
run_podman rm -f "$cid"
|
||||
|
||||
run_podman ps --storage -a
|
||||
run_podman ps --external -a
|
||||
is "${#lines[@]}" "1" "storage container has been removed"
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user