Browse code

Treat HEALTHCHECK NONE the same as not setting a healthcheck

Signed-off-by: Josh Horwitz <horwitzja@gmail.com>

Josh Horwitz authored on 2016/07/22 05:02:12
Showing 3 changed files
... ...
@@ -13,9 +13,12 @@ type Health struct {
13 13
 
14 14
 // String returns a human-readable description of the health-check state
15 15
 func (s *Health) String() string {
16
+	// This happens when the container is being shutdown and the monitor has stopped
17
+	// or the monitor has yet to be setup.
16 18
 	if s.stop == nil {
17
-		return "no healthcheck"
19
+		return types.Unhealthy
18 20
 	}
21
+
19 22
 	switch s.Status {
20 23
 	case types.Starting:
21 24
 		return "health: starting"
... ...
@@ -203,6 +203,7 @@ func monitor(d *Daemon, c *container.Container, stop chan struct{}, probe probe)
203 203
 }
204 204
 
205 205
 // Get a suitable probe implementation for the container's healthcheck configuration.
206
+// Nil will be returned if no healthcheck was configured or NONE was set.
206 207
 func getProbe(c *container.Container) probe {
207 208
 	config := c.Config.Healthcheck
208 209
 	if config == nil || len(config.Test) == 0 {
... ...
@@ -244,7 +245,8 @@ func (d *Daemon) updateHealthMonitor(c *container.Container) {
244 244
 // two instances at once.
245 245
 // Called with c locked.
246 246
 func (d *Daemon) initHealthMonitor(c *container.Container) {
247
-	if c.Config.Healthcheck == nil {
247
+	// If no healthcheck is setup then don't init the monitor
248
+	if getProbe(c) == nil {
248 249
 		return
249 250
 	}
250 251
 
... ...
@@ -254,7 +256,6 @@ func (d *Daemon) initHealthMonitor(c *container.Container) {
254 254
 	if c.State.Health == nil {
255 255
 		h := &container.Health{}
256 256
 		h.Status = types.Starting
257
-		h.FailingStreak = 0
258 257
 		c.State.Health = h
259 258
 	}
260 259
 
... ...
@@ -17,6 +17,28 @@ func reset(c *container.Container) {
17 17
 	c.State.Health.Status = types.Starting
18 18
 }
19 19
 
20
+func TestNoneHealthcheck(t *testing.T) {
21
+	c := &container.Container{
22
+		CommonContainer: container.CommonContainer{
23
+			ID:   "container_id",
24
+			Name: "container_name",
25
+			Config: &containertypes.Config{
26
+				Image: "image_name",
27
+				Healthcheck: &containertypes.HealthConfig{
28
+					Test: []string{"NONE"},
29
+				},
30
+			},
31
+			State: &container.State{},
32
+		},
33
+	}
34
+	daemon := &Daemon{}
35
+
36
+	daemon.initHealthMonitor(c)
37
+	if c.State.Health != nil {
38
+		t.Errorf("Expecting Health to be nil, but was not")
39
+	}
40
+}
41
+
20 42
 func TestHealthStates(t *testing.T) {
21 43
 	e := events.New()
22 44
 	_, l, _ := e.Subscribe()