зеркало из https://github.com/microsoft/docker.git
Merge pull request #25628 from cpuguy83/carry_21567_filter_vol_by_label
Carry 21567 filter vol by label
This commit is contained in:
Коммит
be045ee2da
|
@ -21,6 +21,7 @@ var acceptedVolumeFilterTags = map[string]bool{
|
|||
"dangling": true,
|
||||
"name": true,
|
||||
"driver": true,
|
||||
"label": true,
|
||||
}
|
||||
|
||||
var acceptedPsFilterTags = map[string]bool{
|
||||
|
@ -587,6 +588,15 @@ func (daemon *Daemon) filterVolumes(vols []volume.Volume, filter filters.Args) (
|
|||
continue
|
||||
}
|
||||
}
|
||||
if filter.Include("label") {
|
||||
v, ok := vol.(volume.LabeledVolume)
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
if !filter.MatchKVList("label", v.Labels()) {
|
||||
continue
|
||||
}
|
||||
}
|
||||
retVols = append(retVols, vol)
|
||||
}
|
||||
danglingOnly := false
|
||||
|
|
|
@ -344,3 +344,33 @@ func (s *DockerSuite) TestVolumeCliCreateLabelMultiple(c *check.C) {
|
|||
c.Assert(strings.TrimSpace(out), check.Equals, v)
|
||||
}
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestVolumeCliLsFilterLabels(c *check.C) {
|
||||
testVol1 := "testvolcreatelabel-1"
|
||||
out, _, err := dockerCmdWithError("volume", "create", "--label", "foo=bar1", "--name", testVol1)
|
||||
c.Assert(err, check.IsNil)
|
||||
|
||||
testVol2 := "testvolcreatelabel-2"
|
||||
out, _, err = dockerCmdWithError("volume", "create", "--label", "foo=bar2", "--name", testVol2)
|
||||
c.Assert(err, check.IsNil)
|
||||
|
||||
out, _ = dockerCmd(c, "volume", "ls", "--filter", "label=foo")
|
||||
|
||||
// filter with label=key
|
||||
c.Assert(out, checker.Contains, "testvolcreatelabel-1\n", check.Commentf("expected volume 'testvolcreatelabel-1' in output"))
|
||||
c.Assert(out, checker.Contains, "testvolcreatelabel-2\n", check.Commentf("expected volume 'testvolcreatelabel-2' in output"))
|
||||
|
||||
out, _ = dockerCmd(c, "volume", "ls", "--filter", "label=foo=bar1")
|
||||
|
||||
// filter with label=key=value
|
||||
c.Assert(out, checker.Contains, "testvolcreatelabel-1\n", check.Commentf("expected volume 'testvolcreatelabel-1' in output"))
|
||||
c.Assert(out, check.Not(checker.Contains), "testvolcreatelabel-2\n", check.Commentf("expected volume 'testvolcreatelabel-2 in output"))
|
||||
|
||||
out, _ = dockerCmd(c, "volume", "ls", "--filter", "label=non-exist")
|
||||
outArr := strings.Split(strings.TrimSpace(out), "\n")
|
||||
c.Assert(len(outArr), check.Equals, 1, check.Commentf("\n%s", out))
|
||||
|
||||
out, _ = dockerCmd(c, "volume", "ls", "--filter", "label=foo=non-exist")
|
||||
outArr = strings.Split(strings.TrimSpace(out), "\n")
|
||||
c.Assert(len(outArr), check.Equals, 1, check.Commentf("\n%s", out))
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче