do not error if last_reserved_ip is missing for host local ipam
authorEvan Hazlett <ejhazlett@gmail.com>
Fri, 3 Feb 2017 22:58:30 +0000 (17:58 -0500)
committerEvan Hazlett <ejhazlett@gmail.com>
Thu, 2 Mar 2017 18:59:21 +0000 (13:59 -0500)
Signed-off-by: Evan Hazlett <ejhazlett@gmail.com>
plugins/ipam/host-local/backend/allocator/allocator.go
plugins/ipam/host-local/backend/disk/backend.go

index 5f93424..c3211fc 100644 (file)
@@ -18,6 +18,7 @@ import (
        "fmt"
        "log"
        "net"
+       "os"
 
        "github.com/containernetworking/cni/pkg/ip"
        "github.com/containernetworking/cni/pkg/types"
@@ -253,7 +254,7 @@ func (a *IPAllocator) getSearchRange() (net.IP, net.IP) {
        var endIP net.IP
        startFromLastReservedIP := false
        lastReservedIP, err := a.store.LastReservedIP()
-       if err != nil {
+       if err != nil && !os.IsNotExist(err) {
                log.Printf("Error retriving last reserved ip: %v", err)
        } else if lastReservedIP != nil {
                subnet := net.IPNet{
index 9c11699..183b76e 100644 (file)
@@ -15,7 +15,6 @@
 package disk
 
 import (
-       "fmt"
        "io/ioutil"
        "net"
        "os"
@@ -85,7 +84,7 @@ func (s *Store) LastReservedIP() (net.IP, error) {
        ipfile := filepath.Join(s.dataDir, lastIPFile)
        data, err := ioutil.ReadFile(ipfile)
        if err != nil {
-               return nil, fmt.Errorf("Failed to retrieve last reserved ip: %v", err)
+               return nil, err
        }
        return net.ParseIP(string(data)), nil
 }