@@ -5,14 +5,12 @@ import (
55 "encoding/json"
66 "errors"
77 "fmt"
8- "os"
9- "slices"
10- "strings"
11- "time"
12-
138 docker "github.com/fsouza/go-dockerclient"
149 "github.com/go-viper/mapstructure/v2"
1510 "github.com/mcuadros/ofelia/core"
11+ "os"
12+ "strings"
13+ "time"
1614)
1715
1816const (
@@ -104,34 +102,22 @@ func (c *DockerHandler) watch() {
104102 }
105103 }()
106104
107-
108- shouldProcessEvent := func (event * docker.APIEvents ) bool {
109- if event .Type != "container" :
110- return false
111- }
112-
113- switch (event .Action ) {
114- // lifecycle events
115- case "create" , "start" , "restart" , "stop" , "kill" , "die" , "destroy" :
116- return true
117- // other management events
118- case "pause" , "unpause" , "rename" , "update" :
119- return true
120- default :
121- return false
122- }
123- }
124-
125105 for event := range events {
126- if ! shouldProcessEvent ( event ) {
127- continue
106+ if event . Type != "container" {
107+ continue
128108 }
109+
110+ switch event .Action {
111+ // |-----------------------lifecycle events---------------------| | ----- other management events -----|
112+ case "create" , "start" , "restart" , "stop" , "kill" , "die" , "destroy" , "pause" , "unpause" , "rename" , "update" :
129113 labels , err := c .GetDockerLabels ()
130114 // Do not print or care if there is no container up right now
131115 if err != nil && ! errors .Is (err , errNoContainersMatchingFilters ) {
132116 c .logger .Debugf ("%v" , err )
133117 }
134118 c .notifier .dockerLabelsUpdate (labels )
119+ default :
120+ continue
135121 }
136122 }
137123}
0 commit comments