mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Merge pull request #14388 from runcom/14316-fix-events-filters
Fix combined image events filters
This commit is contained in:
commit
2cd417df73
2 changed files with 30 additions and 2 deletions
|
@ -410,6 +410,9 @@ func (s *Server) getEvents(version version.Version, w http.ResponseWriter, r *ht
|
||||||
}
|
}
|
||||||
|
|
||||||
isFiltered := func(field string, filter []string) bool {
|
isFiltered := func(field string, filter []string) bool {
|
||||||
|
if len(field) == 0 {
|
||||||
|
return false
|
||||||
|
}
|
||||||
if len(filter) == 0 {
|
if len(filter) == 0 {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
@ -448,8 +451,8 @@ func (s *Server) getEvents(version version.Version, w http.ResponseWriter, r *ht
|
||||||
ef["container"][i] = getContainerId(cn)
|
ef["container"][i] = getContainerId(cn)
|
||||||
}
|
}
|
||||||
|
|
||||||
if isFiltered(ev.Status, ef["event"]) || isFiltered(ev.From, ef["image"]) ||
|
if isFiltered(ev.Status, ef["event"]) || (isFiltered(ev.ID, ef["image"]) &&
|
||||||
isFiltered(ev.ID, ef["container"]) {
|
isFiltered(ev.From, ef["image"])) || isFiltered(ev.ID, ef["container"]) {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -783,3 +783,28 @@ func (s *DockerSuite) TestEventsDefaultEmpty(c *check.C) {
|
||||||
out, _ := dockerCmd(c, "events", fmt.Sprintf("--until=%d", daemonTime(c).Unix()))
|
out, _ := dockerCmd(c, "events", fmt.Sprintf("--until=%d", daemonTime(c).Unix()))
|
||||||
c.Assert(strings.TrimSpace(out), check.Equals, "")
|
c.Assert(strings.TrimSpace(out), check.Equals, "")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// #14316
|
||||||
|
func (s *DockerRegistrySuite) TestEventsImageFilterPush(c *check.C) {
|
||||||
|
testRequires(c, Network)
|
||||||
|
since := daemonTime(c).Unix()
|
||||||
|
repoName := fmt.Sprintf("%v/dockercli/testf", privateRegistryURL)
|
||||||
|
|
||||||
|
runCmd := exec.Command(dockerBinary, "run", "-d", "busybox", "top")
|
||||||
|
out, _, err := runCommandWithOutput(runCmd)
|
||||||
|
c.Assert(err, check.IsNil)
|
||||||
|
cID := strings.TrimSpace(out)
|
||||||
|
c.Assert(waitRun(cID), check.IsNil)
|
||||||
|
|
||||||
|
dockerCmd(c, "commit", cID, repoName)
|
||||||
|
dockerCmd(c, "stop", cID)
|
||||||
|
dockerCmd(c, "push", repoName)
|
||||||
|
|
||||||
|
cmd := exec.Command(dockerBinary, "events", "--since=0", "-f", "image="+repoName, "-f", "event=push", "--until="+strconv.Itoa(int(since)))
|
||||||
|
out, _, err = runCommandWithOutput(cmd)
|
||||||
|
c.Assert(err, check.IsNil)
|
||||||
|
|
||||||
|
if !strings.Contains(out, repoName+": push\n") {
|
||||||
|
c.Fatalf("Missing 'push' log event for image %s\n%s", repoName, out)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue