Sync 'owned' data with existing containers at startup

This commit is contained in:
Bryan Boreham committed 2016-03-02 11:35:24 -08:00
1 parent f29716387f
commit 95cbc8940e
3 files changed
+42

No files matched your search

+27
View File
@@ -267,6 +267,16 @@ func (alloc *Allocator) ContainerStarted(ident string) {
}
}
func (alloc *Allocator) AllContainerIDs(ids []string) {
alloc.actionChan <- func() {
idmap := make(map[string]struct{}, len(ids))
for _, id := range ids {
idmap[id] = struct{}{}
}
alloc.syncOwned(idmap)
}
}
// Delete (Sync) - release all IP addresses for container with given name
func (alloc *Allocator) Delete(ident string) error {
errChan := make(chan error)
@@ -871,6 +881,23 @@ func (alloc *Allocator) findOwner(addr address.Address) string {
return ""
}
// For each ID in the 'owned' map, remove the entry if it isn't in the map
func (alloc *Allocator) syncOwned(ids map[string]struct{}) {
changed := false
for ident, addrs := range alloc.owned {
if _, found := ids[ident]; !found {
for _, addr := range addrs {
alloc.space.Free(addr)
}
delete(alloc.owned, ident)
changed = true
}
}
if changed {
alloc.persistOwned()
}
}
// Logging
func (alloc *Allocator) fatalf(fmt string, args ...interface{}) {