From 8feb5c5a48eaadc1686e3b370f7ef9be128dd3cb Mon Sep 17 00:00:00 2001 From: Yong Tang Date: Mon, 16 Jan 2017 21:53:31 -0800 Subject: [PATCH] Fix issue where service healthcheck is `{}` in remote API This fix tries to address the issue raised in 30178 where service healthcheck is `{}` in remote API will result in dns resolve failue. The reason was that when service healthcheck is `{}`, service binding was not done. This fix fixes the issue. An integration test has been added. This fix fixes 30178. Signed-off-by: Yong Tang --- .../cluster/executor/container/controller.go | 8 +------ integration-cli/docker_api_swarm_test.go | 24 +++++++++++++++++++ 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/daemon/cluster/executor/container/controller.go b/daemon/cluster/executor/container/controller.go index 32c95f203d..0ecf58e62b 100644 --- a/daemon/cluster/executor/container/controller.go +++ b/daemon/cluster/executor/container/controller.go @@ -205,7 +205,7 @@ func (r *controller) Start(ctx context.Context) error { } // 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 { 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 @@ -213,12 +213,6 @@ func (r *controller) Start(ctx context.Context) error { return nil } - healthCmd := ctnr.Config.Healthcheck.Test - - if len(healthCmd) == 0 || healthCmd[0] == "NONE" { - return nil - } - // wait for container to be healthy eventq := r.adapter.events(ctx) diff --git a/integration-cli/docker_api_swarm_test.go b/integration-cli/docker_api_swarm_test.go index 048e6e63b7..07d0434e5a 100644 --- a/integration-cli/docker_api_swarm_test.go +++ b/integration-cli/docker_api_swarm_test.go @@ -16,6 +16,7 @@ import ( "time" "github.com/docker/docker/api/types" + "github.com/docker/docker/api/types/container" "github.com/docker/docker/api/types/swarm" "github.com/docker/docker/integration-cli/checker" "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") } + +// 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)) +}