mirror of https://github.com/docker/docs.git
				
				
				
			Treat HEALTHCHECK NONE the same as not setting a healthcheck
Signed-off-by: Josh Horwitz <horwitzja@gmail.com> (cherry picked from commit 4016038bd323a4ef4ee8d0af8da5dafd88ab1721) Signed-off-by: Tibor Vass <tibor@docker.com>
This commit is contained in:
		
							parent
							
								
									a688a0ae9d
								
							
						
					
					
						commit
						c166b2c9da
					
				|  | @ -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() | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue