Browse code

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 <yong.tang.github@outlook.com>

Yong Tang authored on 2017/01/17 14:53:31
Showing 2 changed files
... ...
@@ -205,7 +205,7 @@ func (r *controller) Start(ctx context.Context) error {
205 205
 	}
206 206
 
207 207
 	// no health check
208
-	if ctnr.Config == nil || ctnr.Config.Healthcheck == nil {
208
+	if ctnr.Config == nil || ctnr.Config.Healthcheck == nil || len(ctnr.Config.Healthcheck.Test) == 0 || ctnr.Config.Healthcheck.Test[0] == "NONE" {
209 209
 		if err := r.adapter.activateServiceBinding(); err != nil {
210 210
 			log.G(ctx).WithError(err).Errorf("failed to activate service binding for container %s which has no healthcheck config", r.adapter.container.name())
211 211
 			return err
... ...
@@ -213,12 +213,6 @@ func (r *controller) Start(ctx context.Context) error {
213 213
 		return nil
214 214
 	}
215 215
 
216
-	healthCmd := ctnr.Config.Healthcheck.Test
217
-
218
-	if len(healthCmd) == 0 || healthCmd[0] == "NONE" {
219
-		return nil
220
-	}
221
-
222 216
 	// wait for container to be healthy
223 217
 	eventq := r.adapter.events(ctx)
224 218
 
... ...
@@ -16,6 +16,7 @@ import (
16 16
 	"time"
17 17
 
18 18
 	"github.com/docker/docker/api/types"
19
+	"github.com/docker/docker/api/types/container"
19 20
 	"github.com/docker/docker/api/types/swarm"
20 21
 	"github.com/docker/docker/integration-cli/checker"
21 22
 	"github.com/docker/docker/integration-cli/daemon"
... ...
@@ -1384,3 +1385,26 @@ func (s *DockerSwarmSuite) TestAPIDuplicateNetworks(c *check.C) {
1384 1384
 
1385 1385
 	c.Assert(r2.Scope, checker.Equals, "swarm")
1386 1386
 }
1387
+
1388
+// Test case for 30178
1389
+func (s *DockerSwarmSuite) TestAPISwarmHealthcheckNone(c *check.C) {
1390
+	d := s.AddDaemon(c, true, true)
1391
+
1392
+	out, err := d.Cmd("network", "create", "-d", "overlay", "lb")
1393
+	c.Assert(err, checker.IsNil, check.Commentf(out))
1394
+
1395
+	instances := 1
1396
+	d.CreateService(c, simpleTestService, setInstances(instances), func(s *swarm.Service) {
1397
+		s.Spec.TaskTemplate.ContainerSpec.Healthcheck = &container.HealthConfig{}
1398
+		s.Spec.TaskTemplate.Networks = []swarm.NetworkAttachmentConfig{
1399
+			{Target: "lb"},
1400
+		}
1401
+	})
1402
+
1403
+	waitAndAssert(c, defaultReconciliationTimeout, d.CheckActiveContainerCount, checker.Equals, instances)
1404
+
1405
+	containers := d.ActiveContainers()
1406
+
1407
+	out, err = d.Cmd("exec", containers[0], "ping", "-c1", "-W3", "top")
1408
+	c.Assert(err, checker.IsNil, check.Commentf(out))
1409
+}