Treat HEALTHCHECK NONE the same as not setting a healthcheck

Signed-off-by: Josh Horwitz <horwitzja@gmail.com>
This commit is contained in:
Josh Horwitz 2016-07-21 16:02:12 -04:00
parent 771cf83807
commit 4016038bd3
3 changed files with 29 additions and 3 deletions

View file

@ -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"

View file

@ -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
}

View file

@ -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()