From 7b72f2afd44f0ac0270d8584f33472990bdb0b8a Mon Sep 17 00:00:00 2001 From: Michael Cambria Date: Thu, 20 Sep 2018 10:56:07 -0400 Subject: [PATCH] Handle the case of a Delete for a reservation stored with just ContainerID without the interface --- .../ipam/host-local/backend/disk/backend.go | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/plugins/ipam/host-local/backend/disk/backend.go b/plugins/ipam/host-local/backend/disk/backend.go index cc19afa9..742361ba 100644 --- a/plugins/ipam/host-local/backend/disk/backend.go +++ b/plugins/ipam/host-local/backend/disk/backend.go @@ -100,6 +100,8 @@ func (s *Store) Release(ip net.IP) error { // N.B. This function eats errors to be tolerant and // release as much as possible func (s *Store) ReleaseByID(id string, ifname string) error { + + found := false err := filepath.Walk(s.dataDir, func(path string, info os.FileInfo, err error) error { if err != nil || info.IsDir() { return nil @@ -112,9 +114,32 @@ func (s *Store) ReleaseByID(id string, ifname string) error { if err := os.Remove(path); err != nil { return nil } + found = true } return nil }) + + if (!found) && (err == nil) { + err = filepath.Walk(s.dataDir, func(path string, info os.FileInfo, err error) error { + if err != nil || info.IsDir() { + return nil + } + data, err := ioutil.ReadFile(path) + if err != nil { + return nil + } + isCurrent := strings.Contains(string(data), "\n") + + if !isCurrent { + if strings.TrimSpace(string(data)) == (strings.TrimSpace(id)) { + if err := os.Remove(path); err != nil { + return nil + } + } + } + return nil + }) + } return err }