Skip to content

Commit d9e9af4

Browse files
committed
refresh container list on stop and die
1 parent 1eb7b01 commit d9e9af4

1 file changed

Lines changed: 17 additions & 2 deletions

File tree

internal/discovery/docker.go

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -243,8 +243,23 @@ func (w *DockerWatcher) handleEventStream(eventsChan <-chan events.Message, errC
243243
if !ok {
244244
return fmt.Errorf("event channel closed")
245245
}
246-
if event.Action == "start" && w.onHealthy != nil {
247-
go w.waitForHealthy(event.Actor.ID)
246+
switch event.Action {
247+
case "start":
248+
if w.onHealthy != nil {
249+
go w.waitForHealthy(event.Actor.ID)
250+
}
251+
case "stop", "die":
252+
containers, unrouted, err := w.listContainers()
253+
if err != nil {
254+
log.Printf("docker: failed to list containers after %s: %v", event.Action, err)
255+
continue
256+
}
257+
if w.onChange != nil {
258+
w.onChange(containers)
259+
}
260+
if w.onUnroutedChanged != nil {
261+
w.onUnroutedChanged(unrouted)
262+
}
248263
}
249264
case err := <-errChan:
250265
return fmt.Errorf("event stream: %w", err)

0 commit comments

Comments
 (0)