Merge pull request #31142 from dongluochen/network_converge_delay
add 2 seconds delay to allow gossip converge
This commit is contained in:
commit
8fd55cd064
|
@ -21,6 +21,8 @@ import (
|
||||||
"golang.org/x/time/rate"
|
"golang.org/x/time/rate"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const defaultGossipConvergeDelay = 2 * time.Second
|
||||||
|
|
||||||
// controller implements agent.Controller against docker's API.
|
// controller implements agent.Controller against docker's API.
|
||||||
//
|
//
|
||||||
// Most operations against docker's API are done through the container name,
|
// Most operations against docker's API are done through the container name,
|
||||||
|
@ -301,6 +303,24 @@ func (r *controller) Wait(pctx context.Context) error {
|
||||||
return nil
|
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.
|
// Shutdown the container cleanly.
|
||||||
func (r *controller) Shutdown(ctx context.Context) error {
|
func (r *controller) Shutdown(ctx context.Context) error {
|
||||||
if err := r.checkClosed(); err != nil {
|
if err := r.checkClosed(); err != nil {
|
||||||
|
@ -311,12 +331,18 @@ func (r *controller) Shutdown(ctx context.Context) error {
|
||||||
r.cancelPull()
|
r.cancelPull()
|
||||||
}
|
}
|
||||||
|
|
||||||
// remove container from service binding
|
if r.hasServiceBinding() {
|
||||||
if err := r.adapter.deactivateServiceBinding(); err != nil {
|
// remove container from service binding
|
||||||
log.G(ctx).WithError(err).Warningf("failed to deactivate service binding for container %s", r.adapter.container.name())
|
if err := r.adapter.deactivateServiceBinding(); err != nil {
|
||||||
// Don't return an error here, because failure to deactivate
|
log.G(ctx).WithError(err).Warningf("failed to deactivate service binding for container %s", r.adapter.container.name())
|
||||||
// the service binding is expected if the container was never
|
// Don't return an error here, because failure to deactivate
|
||||||
// started.
|
// 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.
|
||||||
|
time.Sleep(defaultGossipConvergeDelay)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := r.adapter.shutdown(ctx); err != nil {
|
if err := r.adapter.shutdown(ctx); err != nil {
|
||||||
|
|
Loading…
Reference in New Issue