From 93d37c339e61cfb49e8829f6046726e4f5c40a99 Mon Sep 17 00:00:00 2001 From: IWAMOTO Toshihiro Date: Fri, 21 Jul 2017 12:28:27 +0900 Subject: [PATCH] Fix IPAM cache initialization IPAM pools are not at the CALICO_IPAM level but we must descend into Nodes to find pools. --- ipam.go | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/ipam.go b/ipam.go index ca3d07a..80eb31a 100644 --- a/ipam.go +++ b/ipam.go @@ -103,6 +103,21 @@ func (c *ipamCache) update(node *etcd.Node, del bool) error { return nil } +func (c *ipamCache) syncsubr(n *etcd.Node) error { + for _, node := range n.Nodes { + if node.Dir { + if err := c.syncsubr(node); err != nil { + return err + } + } else { + if err := c.update(node, false); err != nil { + return err + } + } + } + return nil +} + // sync synchronizes the contents under /calico/v1/ipam func (c *ipamCache) sync() error { res, err := c.etcdAPI.Get(context.Background(), CALICO_IPAM, &etcd.GetOptions{Recursive: true}) @@ -115,7 +130,7 @@ func (c *ipamCache) sync() error { if node.ModifiedIndex > index { index = node.ModifiedIndex } - if err = c.update(node, false); err != nil { + if err = c.syncsubr(node); err != nil { return err } }