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:
parent
ac7fa8454d
commit
4289ea637a
|
@ -58,9 +58,6 @@ func NewAllocator(lcDs, glDs datastore.DataStore) (*Allocator, error) {
|
||||||
{localAddressSpace, lcDs},
|
{localAddressSpace, lcDs},
|
||||||
{globalAddressSpace, glDs},
|
{globalAddressSpace, glDs},
|
||||||
} {
|
} {
|
||||||
if aspc.ds == nil {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
a.initializeAddressSpace(aspc.as, aspc.ds)
|
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 {
|
func (a *Allocator) initializeAddressSpace(as string, ds datastore.DataStore) error {
|
||||||
|
scope := ""
|
||||||
|
if ds != nil {
|
||||||
|
scope = ds.Scope()
|
||||||
|
}
|
||||||
|
|
||||||
a.Lock()
|
a.Lock()
|
||||||
if _, ok := a.addrSpaces[as]; ok {
|
if _, ok := a.addrSpaces[as]; ok {
|
||||||
a.Unlock()
|
a.Unlock()
|
||||||
|
@ -151,7 +153,7 @@ func (a *Allocator) initializeAddressSpace(as string, ds datastore.DataStore) er
|
||||||
a.addrSpaces[as] = &addrSpace{
|
a.addrSpaces[as] = &addrSpace{
|
||||||
subnets: map[SubnetKey]*PoolData{},
|
subnets: map[SubnetKey]*PoolData{},
|
||||||
id: dsConfigKey + "/" + as,
|
id: dsConfigKey + "/" + as,
|
||||||
scope: ds.Scope(),
|
scope: scope,
|
||||||
ds: ds,
|
ds: ds,
|
||||||
alloc: a,
|
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())
|
//log.Debugf("Inserting bitmask (%s, %s)", key.String(), pool.String())
|
||||||
|
|
||||||
store := a.getStore(key.AddressSpace)
|
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)
|
ipVer := getAddressVersion(pool.IP)
|
||||||
ones, bits := pool.Mask.Size()
|
ones, bits := pool.Mask.Size()
|
||||||
numAddresses := uint64(1 << uint(bits-ones))
|
numAddresses := uint64(1 << uint(bits-ones))
|
||||||
|
|
|
@ -82,8 +82,10 @@ func (a *Allocator) getStore(as string) datastore.DataStore {
|
||||||
|
|
||||||
func (a *Allocator) getAddressSpaceFromStore(as string) (*addrSpace, error) {
|
func (a *Allocator) getAddressSpaceFromStore(as string) (*addrSpace, error) {
|
||||||
store := a.getStore(as)
|
store := a.getStore(as)
|
||||||
|
|
||||||
|
// IPAM may not have a valid store. In such cases it is just in-memory state.
|
||||||
if store == nil {
|
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}
|
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 {
|
func (a *Allocator) writeToStore(aSpace *addrSpace) error {
|
||||||
store := aSpace.store()
|
store := aSpace.store()
|
||||||
|
|
||||||
|
// IPAM may not have a valid store. In such cases it is just in-memory state.
|
||||||
if store == nil {
|
if store == nil {
|
||||||
return types.InternalErrorf("invalid store while trying to write %s address space", aSpace.DataScope())
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
err := store.PutObjectAtomic(aSpace)
|
err := store.PutObjectAtomic(aSpace)
|
||||||
|
@ -114,8 +118,10 @@ func (a *Allocator) writeToStore(aSpace *addrSpace) error {
|
||||||
|
|
||||||
func (a *Allocator) deleteFromStore(aSpace *addrSpace) error {
|
func (a *Allocator) deleteFromStore(aSpace *addrSpace) error {
|
||||||
store := aSpace.store()
|
store := aSpace.store()
|
||||||
|
|
||||||
|
// IPAM may not have a valid store. In such cases it is just in-memory state.
|
||||||
if store == nil {
|
if store == nil {
|
||||||
return types.InternalErrorf("invalid store while trying to delete %s address space", aSpace.DataScope())
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
return store.DeleteObjectAtomic(aSpace)
|
return store.DeleteObjectAtomic(aSpace)
|
||||||
|
|
Loading…
Reference in New Issue