mirror of
https://github.com/containers/podman.git
synced 2025-05-20 16:47:39 +08:00
Merge pull request #20958 from rhatdan/ps
Support podman ps --format '{{ .Label label }}'
This commit is contained in:
@ -189,6 +189,11 @@ func ps(cmd *cobra.Command, _ []string) error {
|
||||
if err := checkFlags(cmd); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if !listOpts.Pod {
|
||||
listOpts.Pod = strings.Contains(listOpts.Format, ".PodName")
|
||||
}
|
||||
|
||||
for _, f := range filters {
|
||||
split := strings.SplitN(f, "=", 2)
|
||||
if len(split) == 1 {
|
||||
@ -336,6 +341,11 @@ func (l psReporter) ImageID() string {
|
||||
return l.ListContainer.ImageID
|
||||
}
|
||||
|
||||
// Labels returns a map of the pod's labels
|
||||
func (l psReporter) Label(name string) string {
|
||||
return l.ListContainer.Labels[name]
|
||||
}
|
||||
|
||||
// ID returns the ID of the container
|
||||
func (l psReporter) ID() string {
|
||||
if !noTrunc {
|
||||
|
@ -199,6 +199,11 @@ func (l ListPodReporter) Labels() map[string]string {
|
||||
return l.ListPodsReport.Labels
|
||||
}
|
||||
|
||||
// Label returns a map of the pod's labels
|
||||
func (l ListPodReporter) Label(name string) string {
|
||||
return l.ListPodsReport.Labels[name]
|
||||
}
|
||||
|
||||
// Networks returns the infra container network names in string format
|
||||
func (l ListPodReporter) Networks() string {
|
||||
return strings.Join(l.ListPodsReport.Networks, ",")
|
||||
|
@ -90,7 +90,7 @@ Valid placeholders for the Go template are listed below:
|
||||
| .Networks | Show all networks connected to the container |
|
||||
| .Pid | Process ID on host system |
|
||||
| .Pod | Pod the container is associated with (SHA) |
|
||||
| .PodName | Seems to be empty no matter what |
|
||||
| .PodName | PodName of the container |
|
||||
| .Ports | Exposed ports |
|
||||
| .Restarts | Display the container restart count |
|
||||
| .RunningFor | Time elapsed since container was started |
|
||||
|
@ -194,6 +194,41 @@ EOF
|
||||
is "${#lines[@]}" "1" "storage container has been removed"
|
||||
}
|
||||
|
||||
@test "podman ps --format label" {
|
||||
rand_value=$(random_string 10)
|
||||
|
||||
run_podman run -d --label mylabel=$rand_value $IMAGE sleep inf
|
||||
cid=$output
|
||||
is "$cid" "[0-9a-f]\{64\}$"
|
||||
|
||||
run_podman ps --format '{{ .Label "mylabel" }}'
|
||||
is "$output" "$rand_value"
|
||||
|
||||
run_podman rm -t 0 -f $cid
|
||||
}
|
||||
|
||||
@test "podman pod ps --format label" {
|
||||
rand_value=$(random_string 10)
|
||||
|
||||
run_podman pod create --label mylabel=${rand_value} test
|
||||
|
||||
run_podman pod ps --format '{{ .Label "mylabel" }}'
|
||||
is "$output" "$rand_value"
|
||||
|
||||
run_podman pod rm -t 0 -f test
|
||||
}
|
||||
|
||||
@test "podman ps --format PodName" {
|
||||
rand_value=$(random_string 10)
|
||||
|
||||
run_podman run -d --pod new:${rand_value} --label mylabel=$rand_value $IMAGE sleep inf
|
||||
cid=$output
|
||||
is "$cid" "[0-9a-f]\{64\}$"
|
||||
|
||||
run_podman ps --format '{{ .PodName }}'
|
||||
is "$output" ".*$rand_value"
|
||||
|
||||
run_podman rm -t 0 -f $cid
|
||||
}
|
||||
|
||||
# vim: filetype=sh
|
||||
|
Reference in New Issue
Block a user