From 4d233943331865cab0cdd1b0bb986a4492bf74b1 Mon Sep 17 00:00:00 2001 From: Dong Chen Date: Fri, 17 Feb 2017 10:34:21 -0800 Subject: [PATCH 1/2] add 2 seocnd delay to allow gossip converge Signed-off-by: Dong Chen --- daemon/cluster/executor/container/controller.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/daemon/cluster/executor/container/controller.go b/daemon/cluster/executor/container/controller.go index da09d2ee47..4552735f59 100644 --- a/daemon/cluster/executor/container/controller.go +++ b/daemon/cluster/executor/container/controller.go @@ -25,6 +25,8 @@ import ( "golang.org/x/time/rate" ) +const defaultGossipConvergeDelay = 2 * time.Second + // controller implements agent.Controller against docker's API. // // Most operations against docker's API are done through the container name, @@ -323,6 +325,13 @@ func (r *controller) Shutdown(ctx context.Context) error { // started. } + // add a delay for gossip converge + // TODO(dongluochen): this delay shoud be configurable to fit different cluster size and network delay. + // TODO(dongluochen): if there is no service binding for this container, this delay is not necessary. + // if r.adapter.deactivateServiceBinding can return an error to indicate that, it'd reduce service + // converge time. + time.Sleep(defaultGossipConvergeDelay) + if err := r.adapter.shutdown(ctx); err != nil { if isUnknownContainer(err) || isStoppedContainer(err) { return nil From bcb53d3489eee305f3e563a0cdbccca5085ac9a7 Mon Sep 17 00:00:00 2001 From: Dong Chen Date: Tue, 28 Feb 2017 16:12:24 -0800 Subject: [PATCH 2/2] Call deactivateServiceBinding when necessary Signed-off-by: Dong Chen --- .../cluster/executor/container/controller.go | 43 +++++++++++++------ 1 file changed, 30 insertions(+), 13 deletions(-) diff --git a/daemon/cluster/executor/container/controller.go b/daemon/cluster/executor/container/controller.go index 4552735f59..3b0156abc5 100644 --- a/daemon/cluster/executor/container/controller.go +++ b/daemon/cluster/executor/container/controller.go @@ -307,6 +307,24 @@ func (r *controller) Wait(pctx context.Context) error { return nil } +func (r *controller) hasServiceBinding() bool { + if r.task == nil { + return false + } + + // service is attached to a network besides the default bridge + for _, na := range r.task.Networks { + if na.Network == nil || + na.Network.DriverState == nil || + na.Network.DriverState.Name == "bridge" && na.Network.Spec.Annotations.Name == "bridge" { + continue + } + return true + } + + return false +} + // Shutdown the container cleanly. func (r *controller) Shutdown(ctx context.Context) error { if err := r.checkClosed(); err != nil { @@ -317,20 +335,19 @@ func (r *controller) Shutdown(ctx context.Context) error { r.cancelPull() } - // remove container from service binding - if err := r.adapter.deactivateServiceBinding(); err != nil { - log.G(ctx).WithError(err).Warningf("failed to deactivate service binding for container %s", r.adapter.container.name()) - // Don't return an error here, because failure to deactivate - // the service binding is expected if the container was never - // started. - } + if r.hasServiceBinding() { + // remove container from service binding + if err := r.adapter.deactivateServiceBinding(); err != nil { + log.G(ctx).WithError(err).Warningf("failed to deactivate service binding for container %s", r.adapter.container.name()) + // Don't return an error here, because failure to deactivate + // the service binding is expected if the container was never + // started. + } - // add a delay for gossip converge - // TODO(dongluochen): this delay shoud be configurable to fit different cluster size and network delay. - // TODO(dongluochen): if there is no service binding for this container, this delay is not necessary. - // if r.adapter.deactivateServiceBinding can return an error to indicate that, it'd reduce service - // converge time. - time.Sleep(defaultGossipConvergeDelay) + // add a delay for gossip converge + // TODO(dongluochen): this delay shoud be configurable to fit different cluster size and network delay. + time.Sleep(defaultGossipConvergeDelay) + } if err := r.adapter.shutdown(ctx); err != nil { if isUnknownContainer(err) || isStoppedContainer(err) {