From fda861c13928b6a88676f1fad74db634fa663778 Mon Sep 17 00:00:00 2001 From: smallfish Date: Thu, 28 Jan 2016 18:00:11 +0800 Subject: [PATCH 1/2] Update StartMonitorEvents support MonitorEventsOptions option, and MonitorEventsFilters support label --- README.md | 2 +- dockerclient.go | 7 +++++-- examples/events.go | 2 +- interface.go | 2 +- mockclient/mock.go | 4 ++-- nopclient/nop.go | 2 +- types.go | 1 + 7 files changed, 12 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 6cad9bd..3675b28 100644 --- a/README.md +++ b/README.md @@ -79,7 +79,7 @@ func main() { docker.StopContainer(containerId, 5) // Listen to events - docker.StartMonitorEvents(eventCallback, nil) + docker.StartMonitorEvents(nil, eventCallback, nil) // Hold the execution to look at the events coming time.Sleep(3600 * time.Second) diff --git a/dockerclient.go b/dockerclient.go index fb1fdd9..68db704 100644 --- a/dockerclient.go +++ b/dockerclient.go @@ -450,6 +450,9 @@ func (client *DockerClient) MonitorEvents(options *MonitorEventsOptions, stopCha if len(options.Filters.Container) > 0 { filterMap["container"] = []string{options.Filters.Container} } + if len(options.Filters.Label) > 0 { + filterMap["label"] = []string{options.Filters.Label} + } if len(filterMap) > 0 { filterJSONBytes, err := json.Marshal(filterMap) if err != nil { @@ -488,11 +491,11 @@ func (client *DockerClient) MonitorEvents(options *MonitorEventsOptions, stopCha return eventOrErrorChan, nil } -func (client *DockerClient) StartMonitorEvents(cb Callback, ec chan error, args ...interface{}) { +func (client *DockerClient) StartMonitorEvents(options *MonitorEventsOptions, cb Callback, ec chan error, args ...interface{}) { client.eventStopChan = make(chan struct{}) go func() { - eventErrChan, err := client.MonitorEvents(nil, client.eventStopChan) + eventErrChan, err := client.MonitorEvents(options, client.eventStopChan) if err != nil { if ec != nil { ec <- err diff --git a/examples/events.go b/examples/events.go index 2d6de40..4233f9d 100644 --- a/examples/events.go +++ b/examples/events.go @@ -33,7 +33,7 @@ func main() { client = docker - client.StartMonitorEvents(eventCallback, nil) + client.StartMonitorEvents(nil, eventCallback, nil) waitForInterrupt() } diff --git a/interface.go b/interface.go index 45e1a2d..2174eb2 100644 --- a/interface.go +++ b/interface.go @@ -30,7 +30,7 @@ type Client interface { // events will be sent. If a stop channel is provided, events will stop // being monitored after the stop channel is closed. MonitorEvents(options *MonitorEventsOptions, stopChan <-chan struct{}) (<-chan EventOrError, error) - StartMonitorEvents(cb Callback, ec chan error, args ...interface{}) + StartMonitorEvents(options *MonitorEventsOptions, cb Callback, ec chan error, args ...interface{}) StopAllMonitorEvents() StartMonitorStats(id string, cb StatCallback, ec chan error, args ...interface{}) StopAllMonitorStats() diff --git a/mockclient/mock.go b/mockclient/mock.go index eff16d5..7772d15 100644 --- a/mockclient/mock.go +++ b/mockclient/mock.go @@ -85,8 +85,8 @@ func (client *MockClient) MonitorEvents(options *dockerclient.MonitorEventsOptio return args.Get(0).(<-chan dockerclient.EventOrError), args.Error(1) } -func (client *MockClient) StartMonitorEvents(cb dockerclient.Callback, ec chan error, args ...interface{}) { - client.Mock.Called(cb, ec, args) +func (client *MockClient) StartMonitorEvents(options *dockerclient.MonitorEventsOptions, cb dockerclient.Callback, ec chan error, args ...interface{}) { + client.Mock.Called(options, cb, ec, args) } func (client *MockClient) StopAllMonitorEvents() { diff --git a/nopclient/nop.go b/nopclient/nop.go index cea96a2..30cdbe6 100644 --- a/nopclient/nop.go +++ b/nopclient/nop.go @@ -74,7 +74,7 @@ func (client *NopClient) MonitorEvents(options *dockerclient.MonitorEventsOption return nil, ErrNoEngine } -func (client *NopClient) StartMonitorEvents(cb dockerclient.Callback, ec chan error, args ...interface{}) { +func (client *NopClient) StartMonitorEvents(options *dockerclient.MonitorEventsOptions, cb dockerclient.Callback, ec chan error, args ...interface{}) { return } diff --git a/types.go b/types.go index b98d46b..bb5c000 100644 --- a/types.go +++ b/types.go @@ -124,6 +124,7 @@ type MonitorEventsFilters struct { Event string `json:",omitempty"` Image string `json:",omitempty"` Container string `json:",omitempty"` + Label string `json:",omitempty"` } type MonitorEventsOptions struct { From de8d60c712a185a1815f80a9fb533d8554738dcf Mon Sep 17 00:00:00 2001 From: smallfish Date: Fri, 29 Jan 2016 16:50:07 +0800 Subject: [PATCH 2/2] update ContainerInfo struct, add Networks --- types.go | 1 + 1 file changed, 1 insertion(+) diff --git a/types.go b/types.go index bb5c000..48f6482 100644 --- a/types.go +++ b/types.go @@ -234,6 +234,7 @@ type ContainerInfo struct { Gateway string Bridge string Ports map[string][]PortBinding + Networks map[string]*EndpointSettings } SysInitPath string ResolvConfPath string