diff --git a/libnetwork/sandbox.go b/libnetwork/sandbox.go index e53aa7d35f..bf1bdf4fc6 100644 --- a/libnetwork/sandbox.go +++ b/libnetwork/sandbox.go @@ -369,28 +369,24 @@ func (sb *Sandbox) ResolveIP(ip string) string { // ResolveService returns all the backend details about the containers or hosts // backing a service. Its purpose is to satisfy an SRV query. func (sb *Sandbox) ResolveService(name string) ([]*net.SRV, []net.IP) { - srv := []*net.SRV{} - ip := []net.IP{} - log.G(context.TODO()).Debugf("Service name To resolve: %v", name) // There are DNS implementations that allow SRV queries for names not in // the format defined by RFC 2782. Hence specific validations checks are // not done - parts := strings.Split(name, ".") - if len(parts) < 3 { + if parts := strings.SplitN(name, ".", 3); len(parts) < 3 { return nil, nil } for _, ep := range sb.Endpoints() { n := ep.getNetwork() - srv, ip = n.ResolveService(name) + srv, ip := n.ResolveService(name) if len(srv) > 0 { - break + return srv, ip } } - return srv, ip + return nil, nil } func getDynamicNwEndpoints(epList []*Endpoint) []*Endpoint { diff --git a/libnetwork/sandbox_store.go b/libnetwork/sandbox_store.go index 08cee95668..cc138e2273 100644 --- a/libnetwork/sandbox_store.go +++ b/libnetwork/sandbox_store.go @@ -143,12 +143,10 @@ retry: continue } - eps := epState{ + sbs.Eps = append(sbs.Eps, epState{ Nid: ep.getNetwork().ID(), Eid: ep.ID(), - } - - sbs.Eps = append(sbs.Eps, eps) + }) } err := sb.controller.updateToStore(sbs) @@ -164,15 +162,13 @@ retry: } func (sb *Sandbox) storeDelete() error { - sbs := &sbState{ + return sb.controller.deleteFromStore(&sbState{ c: sb.controller, ID: sb.id, Cid: sb.containerID, dbIndex: sb.dbIndex, dbExists: sb.dbExists, - } - - return sb.controller.deleteFromStore(sbs) + }) } func (c *Controller) sandboxCleanup(activeSandboxes map[string]interface{}) { @@ -182,20 +178,18 @@ func (c *Controller) sandboxCleanup(activeSandboxes map[string]interface{}) { return } - kvol, err := store.List(datastore.Key(sandboxPrefix), &sbState{c: c}) - if err != nil && err != datastore.ErrKeyNotFound { + sandboxStates, err := store.List(datastore.Key(sandboxPrefix), &sbState{c: c}) + if err != nil { + if err == datastore.ErrKeyNotFound { + // It's normal for no sandboxes to be found. Just bail out. + return + } log.G(context.TODO()).Errorf("failed to get sandboxes for scope %s: %v", store.Scope(), err) return } - // It's normal for no sandboxes to be found. Just bail out. - if err == datastore.ErrKeyNotFound { - return - } - - for _, kvo := range kvol { - sbs := kvo.(*sbState) - + for _, s := range sandboxStates { + sbs := s.(*sbState) sb := &Sandbox{ id: sbs.ID, controller: sbs.c, @@ -235,13 +229,25 @@ func (c *Controller) sandboxCleanup(activeSandboxes map[string]interface{}) { var ep *Endpoint if err != nil { log.G(context.TODO()).Errorf("getNetworkFromStore for nid %s failed while trying to build sandbox for cleanup: %v", eps.Nid, err) - n = &Network{id: eps.Nid, ctrlr: c, drvOnce: &sync.Once{}, persist: true} - ep = &Endpoint{id: eps.Eid, network: n, sandboxID: sbs.ID} + ep = &Endpoint{ + id: eps.Eid, + network: &Network{ + id: eps.Nid, + ctrlr: c, + drvOnce: &sync.Once{}, + persist: true, + }, + sandboxID: sbs.ID, + } } else { ep, err = n.getEndpointFromStore(eps.Eid) if err != nil { log.G(context.TODO()).Errorf("getEndpointFromStore for eid %s failed while trying to build sandbox for cleanup: %v", eps.Eid, err) - ep = &Endpoint{id: eps.Eid, network: n, sandboxID: sbs.ID} + ep = &Endpoint{ + id: eps.Eid, + network: n, + sandboxID: sbs.ID, + } } } if _, ok := activeSandboxes[sb.ID()]; ok && err != nil {