diff --git a/endpoint.go b/endpoint.go index 111b747352..4af4f492be 100644 --- a/endpoint.go +++ b/endpoint.go @@ -822,7 +822,7 @@ func (ep *endpoint) Delete(force bool) error { } } - if err = n.getController().deleteFromStore(ep); err != nil { + if err = n.getController().deleteFromStore(ep); err != nil && !force { return err } diff --git a/sandbox.go b/sandbox.go index 9454c5c286..a4c2750c4c 100644 --- a/sandbox.go +++ b/sandbox.go @@ -182,10 +182,10 @@ func (sb *sandbox) Statistics() (map[string]*types.InterfaceStatistics, error) { } func (sb *sandbox) Delete() error { - return sb.delete(false) + return sb.delete() } -func (sb *sandbox) delete(force bool) error { +func (sb *sandbox) delete() error { sb.Lock() if sb.inDelete { sb.Unlock() @@ -208,10 +208,10 @@ func (sb *sandbox) delete(force bool) error { retain := false for _, ep := range sb.getConnectedEndpoints() { // gw network endpoint detach and removal are automatic - if ep.endpointInGWNetwork() && !force { + if ep.endpointInGWNetwork() { continue } - // Retain the sanbdox if we can't obtain the network from store. + // Retain the sandbox if we can't obtain the network from store. if _, err := c.getNetworkFromStore(ep.getNetwork().ID()); err != nil { if c.isDistributedControl() { retain = true @@ -220,13 +220,11 @@ func (sb *sandbox) delete(force bool) error { continue } - if !force { - if err := ep.Leave(sb); err != nil { - logrus.Warnf("Failed detaching sandbox %s from endpoint %s: %v\n", sb.ID(), ep.ID(), err) - } + if err := ep.Leave(sb); err != nil { + logrus.Warnf("Failed detaching sandbox %s from endpoint %s: %v\n", sb.ID(), ep.ID(), err) } - if err := ep.Delete(force); err != nil { + if err := ep.Delete(true); err != nil { logrus.Warnf("Failed deleting endpoint %s: %v\n", ep.ID(), err) } } diff --git a/sandbox_store.go b/sandbox_store.go index 38b2bd7e8b..e46a6a0d32 100644 --- a/sandbox_store.go +++ b/sandbox_store.go @@ -279,7 +279,7 @@ func (c *controller) sandboxCleanup(activeSandboxes map[string]interface{}) { if _, ok := activeSandboxes[sb.ID()]; !ok { logrus.Infof("Removing stale sandbox %s (%s)", sb.id, sb.containerID) - if err := sb.delete(true); err != nil { + if err := sb.delete(); err != nil { logrus.Errorf("Failed to delete sandbox %s while trying to cleanup: %v", sb.id, err) } continue