Merge pull request #708 from vdemeester/docker-support-healthcheck

Add support for docker healthcheck 👼
This commit is contained in:
Emile Vauge 2016-10-03 12:44:38 +02:00 committed by GitHub
commit 8ee6bf044a
2 changed files with 28 additions and 0 deletions

View file

@ -58,6 +58,7 @@ type dockerData struct {
Name string
Labels map[string]string // List of labels set to container or service
NetworkSettings networkSettings
Health string
}
// NetworkSettings holds the networks data to the Docker provider
@ -214,6 +215,9 @@ func (provider *Docker) Provide(configurationChan chan<- types.ConfigMessage, po
}
eventHandler.Handle("start", startStopHandle)
eventHandler.Handle("die", startStopHandle)
eventHandler.Handle("health_status: healthy", startStopHandle)
eventHandler.Handle("health_status: unhealthy", startStopHandle)
eventHandler.Handle("health_status: starting", startStopHandle)
errChan := events.MonitorWithHandler(ctx, dockerClient, options, eventHandler)
if err := <-errChan; err != nil {
@ -378,6 +382,11 @@ func (provider *Docker) containerFilter(container dockerData) bool {
return false
}
if container.Health != "" && container.Health != "healthy" {
log.Debugf("Filtering unhealthy or starting container %s", container.Name)
return false
}
return true
}
@ -578,6 +587,10 @@ func parseContainer(container dockertypes.ContainerJSON) dockerData {
}
if container.State != nil && container.State.Health != nil {
dockerData.Health = container.State.Health.Status
}
return dockerData
}

View file

@ -569,12 +569,18 @@ func TestDockerGetLabel(t *testing.T) {
}{
{
container: docker.ContainerJSON{
ContainerJSONBase: &docker.ContainerJSONBase{
Name: "foo",
},
Config: &container.Config{},
},
expected: "Label not found:",
},
{
container: docker.ContainerJSON{
ContainerJSONBase: &docker.ContainerJSONBase{
Name: "foo",
},
Config: &container.Config{
Labels: map[string]string{
"foo": "bar",
@ -608,6 +614,9 @@ func TestDockerGetLabels(t *testing.T) {
}{
{
container: docker.ContainerJSON{
ContainerJSONBase: &docker.ContainerJSONBase{
Name: "foo",
},
Config: &container.Config{},
},
expectedLabels: map[string]string{},
@ -615,6 +624,9 @@ func TestDockerGetLabels(t *testing.T) {
},
{
container: docker.ContainerJSON{
ContainerJSONBase: &docker.ContainerJSONBase{
Name: "foo",
},
Config: &container.Config{
Labels: map[string]string{
"foo": "fooz",
@ -628,6 +640,9 @@ func TestDockerGetLabels(t *testing.T) {
},
{
container: docker.ContainerJSON{
ContainerJSONBase: &docker.ContainerJSONBase{
Name: "foo",
},
Config: &container.Config{
Labels: map[string]string{
"foo": "fooz",