|
6 | 6 | "os" |
7 | 7 | "os/exec" |
8 | 8 | "os/signal" |
9 | | - "slices" |
10 | 9 | "strings" |
11 | 10 | "sync" |
12 | 11 | "syscall" |
@@ -250,7 +249,14 @@ func (g *generator) generateFromEvents() { |
250 | 249 | break |
251 | 250 | } |
252 | 251 | if !watching { |
253 | | - err := client.AddEventListener(eventChan) |
| 252 | + options := docker.EventsOptions{ |
| 253 | + Filters: map[string][]string{ |
| 254 | + "event": {"start", "stop", "die", "health_status", "connect", "disconnect"}, |
| 255 | + "type": {"container", "network"}, |
| 256 | + }, |
| 257 | + } |
| 258 | + |
| 259 | + err := client.AddEventListenerWithOptions(options, eventChan) |
254 | 260 | if err != nil && err != docker.ErrListenerAlreadyExists { |
255 | 261 | log.Printf("Error registering docker event listener: %s", err) |
256 | 262 | time.Sleep(10 * time.Second) |
@@ -283,23 +289,10 @@ func (g *generator) generateFromEvents() { |
283 | 289 | break |
284 | 290 | } |
285 | 291 |
|
286 | | - watchedEvent := false |
287 | | - |
288 | | - switch event.Type { |
289 | | - case "container": |
290 | | - watchedContainerActions := []string{"start", "stop", "die", "health_status"} |
291 | | - watchedEvent = slices.Contains(watchedContainerActions, event.Action) |
292 | | - case "network": |
293 | | - watchedNetworkActions := []string{"connect", "disconnect"} |
294 | | - watchedEvent = slices.Contains(watchedNetworkActions, event.Action) |
295 | | - } |
296 | | - |
297 | | - if watchedEvent { |
298 | | - log.Printf("Received event %s for %s %s", event.Action, event.Type, event.Actor.ID[:12]) |
299 | | - // fanout event to all watchers |
300 | | - for _, watcher := range watchers { |
301 | | - watcher <- event |
302 | | - } |
| 292 | + log.Printf("Received event %s for %s %s", event.Action, event.Type, event.Actor.ID[:12]) |
| 293 | + // fanout event to all watchers |
| 294 | + for _, watcher := range watchers { |
| 295 | + watcher <- event |
303 | 296 | } |
304 | 297 | case <-time.After(10 * time.Second): |
305 | 298 | // check for docker liveness |
|
0 commit comments