diff --git a/sandbox_store.go b/sandbox_store.go index 38b2bd7e8b..a1c0505146 100644 --- a/sandbox_store.go +++ b/sandbox_store.go @@ -207,9 +207,36 @@ func (c *controller) sandboxCleanup(activeSandboxes map[string]interface{}) { // It's normal for no sandboxes to be found. Just bail out. if err == datastore.ErrKeyNotFound { + + return + } + // Get all the endpoints + endpointsFromNetworks := []*endpoint{} + nl, err := c.getNetworksForScope(datastore.LocalScope) + if err != nil { + logrus.Warnf("Could not get list of networks during sandbox cleanup: %v", err) return } + for _, n := range nl { + epl, err := n.getEndpointsFromStore() + if err != nil { + logrus.Warnf("Could not get list of endpoints in network %s during sandbox cleanup: %v", n.name, err) + continue + } + for _, ep := range epl { + ep, err = n.getEndpointFromStore(ep.id) + if err != nil { + logrus.Warnf("Could not get endpoint in network %s during sandbox cleanup: %v", n.name, err) + continue + } + endpointsFromNetworks = append(endpointsFromNetworks, ep) + } + } + + // To store the endpoints already stored in sanbox + epMap := make(map[string]int8) + for _, kvo := range kvol { sbs := kvo.(*sbState) @@ -275,6 +302,17 @@ func (c *controller) sandboxCleanup(activeSandboxes map[string]interface{}) { continue } heap.Push(&sb.endpoints, ep) + epMap[ep.id] = 1 + } + + // If endpoint has sb id, but not in sb eps, push it + for _, ep := range endpointsFromNetworks { + if ep.sandboxID != sb.id { + continue + } + if _, ok := epMap[ep.id]; !ok { + heap.Push(&sb.endpoints, ep) + } } if _, ok := activeSandboxes[sb.ID()]; !ok {