mirror of
https://github.com/containers/podman.git
synced 2025-06-03 20:33:20 +08:00
Support label filters for podman pod ps.
Update the podman pod ps command to support filtering by labels. This brings the command in line with the documentation as well as the functionality by the containers equivalent podman ps. Signed-off-by: Stefano Pogliani <stefano@spogliani.net>
This commit is contained in:
@ -519,6 +519,21 @@ func (p *PodmanTestIntegration) CreatePod(name string) (*PodmanSessionIntegratio
|
||||
return session, session.ExitCode(), session.OutputToString()
|
||||
}
|
||||
|
||||
// CreatePod creates a pod with no infra container and some labels.
|
||||
// it optionally takes a pod name
|
||||
func (p *PodmanTestIntegration) CreatePodWithLabels(name string, labels map[string]string) (*PodmanSessionIntegration, int, string) {
|
||||
var podmanArgs = []string{"pod", "create", "--infra=false", "--share", ""}
|
||||
if name != "" {
|
||||
podmanArgs = append(podmanArgs, "--name", name)
|
||||
}
|
||||
for labelKey, labelValue := range labels {
|
||||
podmanArgs = append(podmanArgs, "--label", fmt.Sprintf("%s=%s", labelKey, labelValue))
|
||||
}
|
||||
session := p.Podman(podmanArgs)
|
||||
session.WaitWithDefaultTimeout()
|
||||
return session, session.ExitCode(), session.OutputToString()
|
||||
}
|
||||
|
||||
func (p *PodmanTestIntegration) RunTopContainerInPod(name, pod string) *PodmanSessionIntegration {
|
||||
var podmanArgs = []string{"run", "--pod", pod}
|
||||
if name != "" {
|
||||
|
@ -204,4 +204,27 @@ var _ = Describe("Podman ps", func() {
|
||||
Expect(session.ExitCode()).To(Equal(0))
|
||||
Expect(session.OutputToString()).To(BeEmpty())
|
||||
})
|
||||
|
||||
It("podman pod ps filter labels", func() {
|
||||
_, ec, podid1 := podmanTest.CreatePod("")
|
||||
Expect(ec).To(Equal(0))
|
||||
|
||||
_, ec, podid2 := podmanTest.CreatePodWithLabels("", map[string]string{
|
||||
"io.podman.test.label": "value1",
|
||||
"io.podman.test.key": "irrelevant-value",
|
||||
})
|
||||
Expect(ec).To(Equal(0))
|
||||
|
||||
_, ec, podid3 := podmanTest.CreatePodWithLabels("", map[string]string{
|
||||
"io.podman.test.label": "value2",
|
||||
})
|
||||
Expect(ec).To(Equal(0))
|
||||
|
||||
session := podmanTest.Podman([]string{"pod", "ps", "--no-trunc", "--filter", "label=io.podman.test.key", "--filter", "label=io.podman.test.label=value1"})
|
||||
session.WaitWithDefaultTimeout()
|
||||
Expect(session.ExitCode()).To(Equal(0))
|
||||
Expect(session.OutputToString()).To(Not(ContainSubstring(podid1)))
|
||||
Expect(session.OutputToString()).To(ContainSubstring(podid2))
|
||||
Expect(session.OutputToString()).To(Not(ContainSubstring(podid3)))
|
||||
})
|
||||
})
|
||||
|
Reference in New Issue
Block a user