Merge pull request #24908 from jhorwit2/jah/24903

Treat HEALTHCHECK NONE the same as not setting a healthcheck
This commit is contained in:
Tibor Vass 2016-07-25 10:14:38 -07:00 коммит произвёл GitHub
Родитель 1315573093 4016038bd3
Коммит 79de4d2186
3 изменённых файлов: 29 добавлений и 3 удалений

Просмотреть файл

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

Просмотреть файл

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

Просмотреть файл

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