diff --git a/main.go b/main.go index a939bf3..1c9d7ab 100644 --- a/main.go +++ b/main.go @@ -3,7 +3,6 @@ package main import ( "context" "log" - "strings" "time" "github.com/docker/docker/api/types" @@ -27,6 +26,7 @@ func createClient() (*context.Context, *client.Client, error) { func streamEvents(ctx *context.Context, c *client.Client) (<-chan events.Message, <-chan error) { filter := filters.NewArgs() filter.Add("type", "container") + filter.Add("label", "UFW_MANAGED=TRUE") return c.Events(*ctx, types.EventsOptions{Filters: filter}) } @@ -67,18 +67,16 @@ func main() { for { select { case msg := <-messages: - if ufwManaged := msg.Actor.Attributes["UFW_MANAGED"]; strings.ToUpper(ufwManaged) == "TRUE" { - if msg.Action == "start" { - container, err := client.ContainerInspect(*ctx, msg.ID) - if err != nil { - log.Println("ufw-docker-automated: Couldn't inspect container:", err) - continue - } - createChannel <- &container - } - if msg.Action == "die" { - deleteChannel <- msg.ID[:12] + if msg.Action == "start" { + container, err := client.ContainerInspect(*ctx, msg.ID) + if err != nil { + log.Println("ufw-docker-automated: Couldn't inspect container:", err) + continue } + createChannel <- &container + } + if msg.Action == "die" { + deleteChannel <- msg.ID[:12] } case err := <-errors: if err != nil { diff --git a/ufwhandler/sync.go b/ufwhandler/sync.go index 5a99c76..29aec7f 100644 --- a/ufwhandler/sync.go +++ b/ufwhandler/sync.go @@ -5,14 +5,11 @@ import ( "log" "github.com/docker/docker/api/types" - "github.com/docker/docker/api/types/filters" "github.com/docker/docker/client" ) func Sync(createChannel chan *types.ContainerJSON, client *client.Client, ctx *context.Context) { - var filter = filters.NewArgs() - filter.Add("label", "UFW_MANAGED=TRUE") - containers, err := client.ContainerList(*ctx, types.ContainerListOptions{Filters: filter}) + containers, err := client.ContainerList(*ctx, types.ContainerListOptions{}) if err != nil { log.Println(err) }