mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Allow partial name match for node ls
, and node tasks
This fix is an extension to last commit to expand the partial filter to node and task searches. Additional integration tests have been added to cover the changes. This fix fixes 24270. This fix fixes 24112. 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
1d600ebcb5
commit
e734fa58ea
2 changed files with 50 additions and 8 deletions
|
@ -21,9 +21,9 @@ func newListNodesFilters(filter filters.Args) (*swarmapi.ListNodesRequest_Filter
|
|||
return nil, err
|
||||
}
|
||||
f := &swarmapi.ListNodesRequest_Filters{
|
||||
Names: filter.Get("name"),
|
||||
IDPrefixes: filter.Get("id"),
|
||||
Labels: runconfigopts.ConvertKVStringsToMap(filter.Get("label")),
|
||||
NamePrefixes: filter.Get("name"),
|
||||
IDPrefixes: filter.Get("id"),
|
||||
Labels: runconfigopts.ConvertKVStringsToMap(filter.Get("label")),
|
||||
}
|
||||
|
||||
for _, r := range filter.Get("role") {
|
||||
|
@ -79,11 +79,11 @@ func newListTasksFilters(filter filters.Args, transformFunc func(filters.Args) e
|
|||
}
|
||||
}
|
||||
f := &swarmapi.ListTasksRequest_Filters{
|
||||
Names: filter.Get("name"),
|
||||
IDPrefixes: filter.Get("id"),
|
||||
Labels: runconfigopts.ConvertKVStringsToMap(filter.Get("label")),
|
||||
ServiceIDs: filter.Get("service"),
|
||||
NodeIDs: filter.Get("node"),
|
||||
NamePrefixes: filter.Get("name"),
|
||||
IDPrefixes: filter.Get("id"),
|
||||
Labels: runconfigopts.ConvertKVStringsToMap(filter.Get("label")),
|
||||
ServiceIDs: filter.Get("service"),
|
||||
NodeIDs: filter.Get("node"),
|
||||
}
|
||||
|
||||
for _, s := range filter.Get("desired-state") {
|
||||
|
|
|
@ -211,3 +211,45 @@ func (s *DockerSwarmSuite) TestSwarmServiceListFilter(c *check.C) {
|
|||
c.Assert(out, checker.Contains, name2+" ")
|
||||
c.Assert(out, checker.Contains, name3+" ")
|
||||
}
|
||||
|
||||
func (s *DockerSwarmSuite) TestSwarmNodeListFilter(c *check.C) {
|
||||
d := s.AddDaemon(c, true, true)
|
||||
|
||||
out, err := d.Cmd("node", "inspect", "--format", "{{ .Description.Hostname }}", "self")
|
||||
c.Assert(err, checker.IsNil)
|
||||
c.Assert(strings.TrimSpace(out), checker.Not(checker.Equals), "")
|
||||
name := strings.TrimSpace(out)
|
||||
|
||||
filter := "name=" + name[:4]
|
||||
|
||||
out, err = d.Cmd("node", "ls", "--filter", filter)
|
||||
c.Assert(err, checker.IsNil)
|
||||
c.Assert(out, checker.Contains, name)
|
||||
|
||||
out, err = d.Cmd("node", "ls", "--filter", "name=none")
|
||||
c.Assert(err, checker.IsNil)
|
||||
c.Assert(out, checker.Not(checker.Contains), name)
|
||||
}
|
||||
|
||||
func (s *DockerSwarmSuite) TestSwarmNodeTaskListFilter(c *check.C) {
|
||||
d := s.AddDaemon(c, true, true)
|
||||
|
||||
name := "redis-cluster-md5"
|
||||
out, err := d.Cmd("service", "create", "--name", name, "--replicas=3", "busybox", "top")
|
||||
c.Assert(err, checker.IsNil)
|
||||
c.Assert(strings.TrimSpace(out), checker.Not(checker.Equals), "")
|
||||
|
||||
filter := "name=redis-cluster"
|
||||
|
||||
out, err = d.Cmd("node", "tasks", "--filter", filter, "self")
|
||||
c.Assert(err, checker.IsNil)
|
||||
c.Assert(out, checker.Contains, name+".1")
|
||||
c.Assert(out, checker.Contains, name+".2")
|
||||
c.Assert(out, checker.Contains, name+".3")
|
||||
|
||||
out, err = d.Cmd("node", "tasks", "--filter", "name=none", "self")
|
||||
c.Assert(err, checker.IsNil)
|
||||
c.Assert(out, checker.Not(checker.Contains), name+".1")
|
||||
c.Assert(out, checker.Not(checker.Contains), name+".2")
|
||||
c.Assert(out, checker.Not(checker.Contains), name+".3")
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue