File tree Expand file tree Collapse file tree 4 files changed +51
-1
lines changed Expand file tree Collapse file tree 4 files changed +51
-1
lines changed Original file line number Diff line number Diff line change @@ -189,6 +189,11 @@ func ps(cmd *cobra.Command, _ []string) error {
189
189
if err := checkFlags (cmd ); err != nil {
190
190
return err
191
191
}
192
+
193
+ if ! listOpts .Pod {
194
+ listOpts .Pod = strings .Contains (listOpts .Format , ".PodName" )
195
+ }
196
+
192
197
for _ , f := range filters {
193
198
split := strings .SplitN (f , "=" , 2 )
194
199
if len (split ) == 1 {
@@ -336,6 +341,11 @@ func (l psReporter) ImageID() string {
336
341
return l .ListContainer .ImageID
337
342
}
338
343
344
+ // Labels returns a map of the pod's labels
345
+ func (l psReporter ) Label (name string ) string {
346
+ return l .ListContainer .Labels [name ]
347
+ }
348
+
339
349
// ID returns the ID of the container
340
350
func (l psReporter ) ID () string {
341
351
if ! noTrunc {
Original file line number Diff line number Diff line change @@ -199,6 +199,11 @@ func (l ListPodReporter) Labels() map[string]string {
199
199
return l .ListPodsReport .Labels
200
200
}
201
201
202
+ // Label returns a map of the pod's labels
203
+ func (l ListPodReporter ) Label (name string ) string {
204
+ return l .ListPodsReport .Labels [name ]
205
+ }
206
+
202
207
// Networks returns the infra container network names in string format
203
208
func (l ListPodReporter ) Networks () string {
204
209
return strings .Join (l .ListPodsReport .Networks , "," )
Original file line number Diff line number Diff line change @@ -90,7 +90,7 @@ Valid placeholders for the Go template are listed below:
90
90
| .Networks | Show all networks connected to the container |
91
91
| .Pid | Process ID on host system |
92
92
| .Pod | Pod the container is associated with (SHA) |
93
- | .PodName | Seems to be empty no matter what |
93
+ | .PodName | PodName of the container |
94
94
| .Ports | Exposed ports |
95
95
| .Restarts | Display the container restart count |
96
96
| .RunningFor | Time elapsed since container was started |
Original file line number Diff line number Diff line change 194
194
is " ${# lines[@]} " " 1" " storage container has been removed"
195
195
}
196
196
197
+ @test " podman ps --format label" {
198
+ rand_value=$( random_string 10)
197
199
200
+ run_podman run -d --label mylabel=$rand_value $IMAGE sleep inf
201
+ cid=$output
202
+ is " $cid " " [0-9a-f]\{64\}$"
203
+
204
+ run_podman ps --format ' {{ .Label "mylabel" }}'
205
+ is " $output " " $rand_value "
206
+
207
+ run_podman rm -t 0 -f $cid
208
+ }
209
+
210
+ @test " podman pod ps --format label" {
211
+ rand_value=$( random_string 10)
212
+
213
+ run_podman pod create --label mylabel=${rand_value} test
214
+
215
+ run_podman pod ps --format ' {{ .Label "mylabel" }}'
216
+ is " $output " " $rand_value "
217
+
218
+ run_podman pod rm -t 0 -f test
219
+ }
220
+
221
+ @test " podman ps --format PodName" {
222
+ rand_value=$( random_string 10)
223
+
224
+ run_podman run -d --pod new:${rand_value} --label mylabel=$rand_value $IMAGE sleep inf
225
+ cid=$output
226
+ is " $cid " " [0-9a-f]\{64\}$"
227
+
228
+ run_podman ps --format ' {{ .PodName }}'
229
+ is " $output " " .*$rand_value "
230
+
231
+ run_podman rm -t 0 -f $cid
232
+ }
198
233
199
234
# vim: filetype=sh
You can’t perform that action at this time.
0 commit comments