Allow partial name match for service ls --filter
This fix tries to address the issue raised in 24270 where it was not possible to have a partial name match when list services with name filter. This fix updates swarmkit and allows prefix search when name is provided as the filter for listing services. An additional integration test is added to cover the changes. This fix fixes 24270. Note: A separate pull request will be opened on swarmkit. Signed-off-by: Yong Tang <yong.tang.github@outlook.com>
This commit is contained in:
parent
e6a97db2c9
commit
1d600ebcb5
2 changed files with 45 additions and 3 deletions
|
@ -55,9 +55,9 @@ func newListServicesFilters(filter filters.Args) (*swarmapi.ListServicesRequest_
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return &swarmapi.ListServicesRequest_Filters{
|
return &swarmapi.ListServicesRequest_Filters{
|
||||||
Names: filter.Get("name"),
|
NamePrefixes: filter.Get("name"),
|
||||||
IDPrefixes: filter.Get("id"),
|
IDPrefixes: filter.Get("id"),
|
||||||
Labels: runconfigopts.ConvertKVStringsToMap(filter.Get("label")),
|
Labels: runconfigopts.ConvertKVStringsToMap(filter.Get("label")),
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -169,3 +169,45 @@ func (s *DockerSwarmSuite) TestSwarmNodeListHostname(c *check.C) {
|
||||||
c.Assert(err, checker.IsNil)
|
c.Assert(err, checker.IsNil)
|
||||||
c.Assert(strings.Split(out, "\n")[0], checker.Contains, "HOSTNAME")
|
c.Assert(strings.Split(out, "\n")[0], checker.Contains, "HOSTNAME")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Test case for #24270
|
||||||
|
func (s *DockerSwarmSuite) TestSwarmServiceListFilter(c *check.C) {
|
||||||
|
d := s.AddDaemon(c, true, true)
|
||||||
|
|
||||||
|
name1 := "redis-cluster-md5"
|
||||||
|
name2 := "redis-cluster"
|
||||||
|
name3 := "other-cluster"
|
||||||
|
out, err := d.Cmd("service", "create", "--name", name1, "busybox", "top")
|
||||||
|
c.Assert(err, checker.IsNil)
|
||||||
|
c.Assert(strings.TrimSpace(out), checker.Not(checker.Equals), "")
|
||||||
|
|
||||||
|
out, err = d.Cmd("service", "create", "--name", name2, "busybox", "top")
|
||||||
|
c.Assert(err, checker.IsNil)
|
||||||
|
c.Assert(strings.TrimSpace(out), checker.Not(checker.Equals), "")
|
||||||
|
|
||||||
|
out, err = d.Cmd("service", "create", "--name", name3, "busybox", "top")
|
||||||
|
c.Assert(err, checker.IsNil)
|
||||||
|
c.Assert(strings.TrimSpace(out), checker.Not(checker.Equals), "")
|
||||||
|
|
||||||
|
filter1 := "name=redis-cluster-md5"
|
||||||
|
filter2 := "name=redis-cluster"
|
||||||
|
|
||||||
|
// We search checker.Contains with `name+" "` to prevent prefix only.
|
||||||
|
out, err = d.Cmd("service", "ls", "--filter", filter1)
|
||||||
|
c.Assert(err, checker.IsNil)
|
||||||
|
c.Assert(out, checker.Contains, name1+" ")
|
||||||
|
c.Assert(out, checker.Not(checker.Contains), name2+" ")
|
||||||
|
c.Assert(out, checker.Not(checker.Contains), name3+" ")
|
||||||
|
|
||||||
|
out, err = d.Cmd("service", "ls", "--filter", filter2)
|
||||||
|
c.Assert(err, checker.IsNil)
|
||||||
|
c.Assert(out, checker.Contains, name1+" ")
|
||||||
|
c.Assert(out, checker.Contains, name2+" ")
|
||||||
|
c.Assert(out, checker.Not(checker.Contains), name3+" ")
|
||||||
|
|
||||||
|
out, err = d.Cmd("service", "ls")
|
||||||
|
c.Assert(err, checker.IsNil)
|
||||||
|
c.Assert(out, checker.Contains, name1+" ")
|
||||||
|
c.Assert(out, checker.Contains, name2+" ")
|
||||||
|
c.Assert(out, checker.Contains, name3+" ")
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue