Filter events

This commit is contained in:
Sergey Ponomarev 2021-02-04 09:22:57 +02:00
parent cfa43f809e
commit d98ce102b1
1 changed files with 6 additions and 9 deletions

View File

@ -78,18 +78,15 @@ func (cm *Docker) Wait() struct{} { return <-cm.closed }
func (cm *Docker) watchEvents() {
log.Info("docker event listener starting")
events := make(chan *api.APIEvents)
cm.client.AddEventListener(events)
opts := api.EventsOptions{Filters: map[string][]string{
"type": {"container"},
"event": {"create", "start", "health_status", "pause", "unpause", "stop", "die", "destroy"},
},
}
cm.client.AddEventListenerWithOptions(opts, events)
for e := range events {
if e.Type != "container" {
continue
}
actionName := e.Action
// fast skip all exec_* events: exec_create, exec_start, exec_die
if strings.HasPrefix(actionName, "exec_") {
continue
}
// Action may have additional param i.e. "health_status: healthy"
// We need to strip to have only action name
sepIdx := strings.Index(actionName, ": ")