diff --git a/container/health.go b/container/health.go index 0955a6d476..7a459d8182 100644 --- a/container/health.go +++ b/container/health.go @@ -13,9 +13,12 @@ type Health struct { // String returns a human-readable description of the health-check state func (s *Health) String() string { + // This happens when the container is being shutdown and the monitor has stopped + // or the monitor has yet to be setup. if s.stop == nil { - return "no healthcheck" + return types.Unhealthy } + switch s.Status { case types.Starting: return "health: starting" diff --git a/daemon/health.go b/daemon/health.go index 2f2d79ebc5..094dd226a1 100644 --- a/daemon/health.go +++ b/daemon/health.go @@ -203,6 +203,7 @@ func monitor(d *Daemon, c *container.Container, stop chan struct{}, probe probe) } // Get a suitable probe implementation for the container's healthcheck configuration. +// Nil will be returned if no healthcheck was configured or NONE was set. func getProbe(c *container.Container) probe { config := c.Config.Healthcheck if config == nil || len(config.Test) == 0 { @@ -244,7 +245,8 @@ func (d *Daemon) updateHealthMonitor(c *container.Container) { // two instances at once. // Called with c locked. func (d *Daemon) initHealthMonitor(c *container.Container) { - if c.Config.Healthcheck == nil { + // If no healthcheck is setup then don't init the monitor + if getProbe(c) == nil { return } @@ -254,7 +256,6 @@ func (d *Daemon) initHealthMonitor(c *container.Container) { if c.State.Health == nil { h := &container.Health{} h.Status = types.Starting - h.FailingStreak = 0 c.State.Health = h } diff --git a/daemon/health_test.go b/daemon/health_test.go index f53c32f4f2..2b561b7096 100644 --- a/daemon/health_test.go +++ b/daemon/health_test.go @@ -17,6 +17,28 @@ func reset(c *container.Container) { c.State.Health.Status = types.Starting } +func TestNoneHealthcheck(t *testing.T) { + c := &container.Container{ + CommonContainer: container.CommonContainer{ + ID: "container_id", + Name: "container_name", + Config: &containertypes.Config{ + Image: "image_name", + Healthcheck: &containertypes.HealthConfig{ + Test: []string{"NONE"}, + }, + }, + State: &container.State{}, + }, + } + daemon := &Daemon{} + + daemon.initHealthMonitor(c) + if c.State.Health != nil { + t.Errorf("Expecting Health to be nil, but was not") + } +} + func TestHealthStates(t *testing.T) { e := events.New() _, l, _ := e.Subscribe()