Support podman ps --format '{{ .Label label }}'

Also Support for podman pod ps  --format '{{ .Label label }}'

Finally fix support for --format '{{ .Podname }}'
   When user specifies .Podname this implies --pod was passed.

Fixes: https://github.com/containers/podman/issues/20957

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
This commit is contained in:
Daniel J Walsh
2023-12-09 07:44:26 -05:00
parent a5c8bb25cc
commit f51ff77644
4 changed files with 51 additions and 1 deletions

View File

@ -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 {

View File

@ -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, ",")