Browse Source

Merge pull request #30197 from yongtang/30178-service-health-check-none

Fix issue where service healthcheck is `{}` in remote API
Vincent Demeester 8 năm trước cách đây
mục cha
commit
09114fe9f0

+ 1 - 7
daemon/cluster/executor/container/controller.go

@@ -205,7 +205,7 @@ func (r *controller) Start(ctx context.Context) error {
 	}
 	}
 
 
 	// no health check
 	// no health check
-	if ctnr.Config == nil || ctnr.Config.Healthcheck == nil {
+	if ctnr.Config == nil || ctnr.Config.Healthcheck == nil || len(ctnr.Config.Healthcheck.Test) == 0 || ctnr.Config.Healthcheck.Test[0] == "NONE" {
 		if err := r.adapter.activateServiceBinding(); err != nil {
 		if err := r.adapter.activateServiceBinding(); err != nil {
 			log.G(ctx).WithError(err).Errorf("failed to activate service binding for container %s which has no healthcheck config", r.adapter.container.name())
 			log.G(ctx).WithError(err).Errorf("failed to activate service binding for container %s which has no healthcheck config", r.adapter.container.name())
 			return err
 			return err
@@ -213,12 +213,6 @@ func (r *controller) Start(ctx context.Context) error {
 		return nil
 		return nil
 	}
 	}
 
 
-	healthCmd := ctnr.Config.Healthcheck.Test
-
-	if len(healthCmd) == 0 || healthCmd[0] == "NONE" {
-		return nil
-	}
-
 	// wait for container to be healthy
 	// wait for container to be healthy
 	eventq := r.adapter.events(ctx)
 	eventq := r.adapter.events(ctx)
 
 

+ 24 - 0
integration-cli/docker_api_swarm_test.go

@@ -16,6 +16,7 @@ import (
 	"time"
 	"time"
 
 
 	"github.com/docker/docker/api/types"
 	"github.com/docker/docker/api/types"
+	"github.com/docker/docker/api/types/container"
 	"github.com/docker/docker/api/types/swarm"
 	"github.com/docker/docker/api/types/swarm"
 	"github.com/docker/docker/integration-cli/checker"
 	"github.com/docker/docker/integration-cli/checker"
 	"github.com/docker/docker/integration-cli/daemon"
 	"github.com/docker/docker/integration-cli/daemon"
@@ -1384,3 +1385,26 @@ func (s *DockerSwarmSuite) TestAPIDuplicateNetworks(c *check.C) {
 
 
 	c.Assert(r2.Scope, checker.Equals, "swarm")
 	c.Assert(r2.Scope, checker.Equals, "swarm")
 }
 }
+
+// Test case for 30178
+func (s *DockerSwarmSuite) TestAPISwarmHealthcheckNone(c *check.C) {
+	d := s.AddDaemon(c, true, true)
+
+	out, err := d.Cmd("network", "create", "-d", "overlay", "lb")
+	c.Assert(err, checker.IsNil, check.Commentf(out))
+
+	instances := 1
+	d.CreateService(c, simpleTestService, setInstances(instances), func(s *swarm.Service) {
+		s.Spec.TaskTemplate.ContainerSpec.Healthcheck = &container.HealthConfig{}
+		s.Spec.TaskTemplate.Networks = []swarm.NetworkAttachmentConfig{
+			{Target: "lb"},
+		}
+	})
+
+	waitAndAssert(c, defaultReconciliationTimeout, d.CheckActiveContainerCount, checker.Equals, instances)
+
+	containers := d.ActiveContainers()
+
+	out, err = d.Cmd("exec", containers[0], "ping", "-c1", "-W3", "top")
+	c.Assert(err, checker.IsNil, check.Commentf(out))
+}