Make IPAM work even without a backing store

In general the core IPAM and bitseq implementation has
very little assumptions about the presence of a backing
store. But there are a few places where this assumption exists
and this makes it not useful as a simple in-memory allocator.
This PR removes those false assumptions.

Signed-off-by: Jana Radhakrishnan <mrjana@docker.com>
This commit is contained in:
Jana Radhakrishnan 2016-03-01 15:05:36 -08:00
parent ac7fa8454d
commit 4289ea637a
2 changed files with 15 additions and 11 deletions

View File

@ -58,9 +58,6 @@ func NewAllocator(lcDs, glDs datastore.DataStore) (*Allocator, error) {
{localAddressSpace, lcDs},
{globalAddressSpace, glDs},
} {
if aspc.ds == nil {
continue
}
a.initializeAddressSpace(aspc.as, aspc.ds)
}
@ -143,6 +140,11 @@ func (a *Allocator) checkConsistency(as string) {
}
func (a *Allocator) initializeAddressSpace(as string, ds datastore.DataStore) error {
scope := ""
if ds != nil {
scope = ds.Scope()
}
a.Lock()
if _, ok := a.addrSpaces[as]; ok {
a.Unlock()
@ -151,7 +153,7 @@ func (a *Allocator) initializeAddressSpace(as string, ds datastore.DataStore) er
a.addrSpaces[as] = &addrSpace{
subnets: map[SubnetKey]*PoolData{},
id: dsConfigKey + "/" + as,
scope: ds.Scope(),
scope: scope,
ds: ds,
alloc: a,
}
@ -313,10 +315,6 @@ func (a *Allocator) insertBitMask(key SubnetKey, pool *net.IPNet) error {
//log.Debugf("Inserting bitmask (%s, %s)", key.String(), pool.String())
store := a.getStore(key.AddressSpace)
if store == nil {
return types.InternalErrorf("could not find store for address space %s while inserting bit mask", key.AddressSpace)
}
ipVer := getAddressVersion(pool.IP)
ones, bits := pool.Mask.Size()
numAddresses := uint64(1 << uint(bits-ones))

View File

@ -82,8 +82,10 @@ func (a *Allocator) getStore(as string) datastore.DataStore {
func (a *Allocator) getAddressSpaceFromStore(as string) (*addrSpace, error) {
store := a.getStore(as)
// IPAM may not have a valid store. In such cases it is just in-memory state.
if store == nil {
return nil, types.InternalErrorf("store for address space %s not found", as)
return nil, nil
}
pc := &addrSpace{id: dsConfigKey + "/" + as, ds: store, alloc: a}
@ -100,8 +102,10 @@ func (a *Allocator) getAddressSpaceFromStore(as string) (*addrSpace, error) {
func (a *Allocator) writeToStore(aSpace *addrSpace) error {
store := aSpace.store()
// IPAM may not have a valid store. In such cases it is just in-memory state.
if store == nil {
return types.InternalErrorf("invalid store while trying to write %s address space", aSpace.DataScope())
return nil
}
err := store.PutObjectAtomic(aSpace)
@ -114,8 +118,10 @@ func (a *Allocator) writeToStore(aSpace *addrSpace) error {
func (a *Allocator) deleteFromStore(aSpace *addrSpace) error {
store := aSpace.store()
// IPAM may not have a valid store. In such cases it is just in-memory state.
if store == nil {
return types.InternalErrorf("invalid store while trying to delete %s address space", aSpace.DataScope())
return nil
}
return store.DeleteObjectAtomic(aSpace)