Explorar o código

Check if address space valid in getStore

Added a check to see if address space is valid in
addrSpaces map before accessing it. Also fixed some
error strings so that it provides better information
to the user.

Signed-off-by: Jana Radhakrishnan <mrjana@docker.com>
Jana Radhakrishnan %!s(int64=9) %!d(string=hai) anos
pai
achega
6d6490b91c
Modificáronse 2 ficheiros con 7 adicións e 3 borrados
  1. 2 2
      libnetwork/ipam/allocator.go
  2. 5 1
      libnetwork/ipam/store.go

+ 2 - 2
libnetwork/ipam/allocator.go

@@ -130,7 +130,7 @@ func (a *Allocator) RequestPool(addressSpace, pool, subPool string, options map[
 	log.Debugf("RequestPool(%s, %s, %s, %v, %t)", addressSpace, pool, subPool, options, v6)
 	k, nw, ipr, err := a.parsePoolRequest(addressSpace, pool, subPool, v6)
 	if err != nil {
-		return "", nil, nil, ipamapi.ErrInvalidPool
+		return "", nil, nil, types.InternalErrorf("failed to parse pool request for address space %q pool %q subpool %q: %v", addressSpace, pool, subPool, err)
 	}
 
 retry:
@@ -199,7 +199,7 @@ func (a *Allocator) getAddrSpace(as string) (*addrSpace, error) {
 	defer a.Unlock()
 	aSpace, ok := a.addrSpaces[as]
 	if !ok {
-		return nil, types.BadRequestErrorf("cannot find locality of address space: %s", as)
+		return nil, types.BadRequestErrorf("cannot find address space %s (most likey the backing datastore is not configured)", as)
 	}
 	return aSpace, nil
 }

+ 5 - 1
libnetwork/ipam/store.go

@@ -74,7 +74,11 @@ func (a *Allocator) getStore(as string) datastore.DataStore {
 	a.Lock()
 	defer a.Unlock()
 
-	return a.addrSpaces[as].ds
+	if aSpace, ok := a.addrSpaces[as]; ok {
+		return aSpace.ds
+	}
+
+	return nil
 }
 
 func (a *Allocator) getAddressSpaceFromStore(as string) (*addrSpace, error) {