Skip to content

Commit

Permalink
Merge pull request #486 from bcreane/kddsync
Browse files Browse the repository at this point in the history
Treat initial and subsequent resync events identically for node ip
  • Loading branch information
caseydavenport authored Aug 4, 2017
2 parents 93f9e49 + e749045 commit 2b80ed5
Showing 1 changed file with 21 additions and 14 deletions.
35 changes: 21 additions & 14 deletions lib/backend/k8s/syncer.go
Original file line number Diff line number Diff line change
Expand Up @@ -794,14 +794,15 @@ func (syn *kubeSyncer) performSnapshot(versions *resourceVersions) (map[string][

versions.nodeVersion = noList.ListMeta.ResourceVersion
for _, no := range noList.Items {
node, err := resources.K8sNodeToCalico(&no)
if err != nil {
log.WithError(err).Fatal("Error converting node")
}
if node != nil {
snap[KEY_NO] = append(snap[KEY_NO], *node)
keys[KEY_NO][node.Key.String()] = true
}
kvpHostIP, kvpIPIPAddr := splitNodeEvent(&no)
log.WithFields(log.Fields{
"kvpHostIP": kvpHostIP,
"kvpIPIPAddr": kvpIPIPAddr,
}).Debug("Got node KVs.")
snap[KEY_NO] = append(snap[KEY_NO], *kvpHostIP)
keys[KEY_NO][kvpHostIP.Key.String()] = true
snap[KEY_HC] = append(snap[KEY_HC], *kvpIPIPAddr)
keys[KEY_HC][kvpIPIPAddr.Key.String()] = true
}
}

Expand Down Expand Up @@ -884,12 +885,7 @@ func (syn *kubeSyncer) parseNamespaceEvent(e watch.Event) []model.KVPair {
return []model.KVPair{*rules, *tags, *labels}
}

func (syn *kubeSyncer) parseNodeEvent(e watch.Event) (*model.KVPair, *model.KVPair) {
node, ok := e.Object.(*k8sapi.Node)
if !ok {
log.Panicf("Invalid node event. Type: %s, Object: %+v", e.Type, e.Object)
}

func splitNodeEvent(node *k8sapi.Node) (*model.KVPair, *model.KVPair) {
kvp, err := resources.K8sNodeToCalico(node)
if err != nil {
log.WithError(err).Panic("Failed to convert k8s node to Calico node.")
Expand Down Expand Up @@ -922,6 +918,17 @@ func (syn *kubeSyncer) parseNodeEvent(e watch.Event) (*model.KVPair, *model.KVPa
}
kvpIPIPAddr.Revision = kvp.Revision

return kvpHostIp, kvpIPIPAddr
}

func (syn *kubeSyncer) parseNodeEvent(e watch.Event) (*model.KVPair, *model.KVPair) {
node, ok := e.Object.(*k8sapi.Node)
if !ok {
log.Panicf("Invalid node event. Type: %s, Object: %+v", e.Type, e.Object)
}

kvpHostIp, kvpIPIPAddr := splitNodeEvent(node)

if e.Type == watch.Deleted {
kvpHostIp.Value = nil
kvpIPIPAddr.Value = nil
Expand Down

0 comments on commit 2b80ed5

Please sign in to comment.