Quellcode durchsuchen

Merge pull request #24908 from jhorwit2/jah/24903

Treat HEALTHCHECK NONE the same as not setting a healthcheck
Tibor Vass vor 9 Jahren
Ursprung
Commit
79de4d2186
3 geänderte Dateien mit 29 neuen und 3 gelöschten Zeilen
  1. 4 1
      container/health.go
  2. 3 2
      daemon/health.go
  3. 22 0
      daemon/health_test.go

+ 4 - 1
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"

+ 3 - 2
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
 	}
 

+ 22 - 0
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()