Skip to content

Commit cb48a7f

Browse files
authored
fix(network_routes): missing node ip -> error log (#904)
Before we used to raise an error when a node was missing an IP, but it turns out that this is not a required attribute of a node. And while it is rare that a node would be missing an IP address, a node doesn't require an IP address or a name or really much of anything in order to exist. This brings us to stronger conformance with the Kubernetes API and makes it so that kube-router logs errors rather than changing it's health status and potentially causing cascading failures across the fleet if a user adds a node like this.
1 parent d2178da commit cb48a7f

File tree

3 files changed

+23
-7
lines changed

3 files changed

+23
-7
lines changed

pkg/controllers/routing/bgp_peers.go

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,11 @@ func (nrc *NetworkRoutingController) syncInternalPeers() {
4545
currentNodes := make([]string, 0)
4646
for _, obj := range nodes {
4747
node := obj.(*v1core.Node)
48-
nodeIP, _ := utils.GetNodeIP(node)
48+
nodeIP, err := utils.GetNodeIP(node)
49+
if err != nil {
50+
glog.Errorf("Failed to find a node IP and therefore cannot sync internal BGP Peer: %v", err)
51+
continue
52+
}
4953

5054
// skip self
5155
if nodeIP.String() == nrc.nodeIP.String() {
@@ -321,7 +325,11 @@ func (nrc *NetworkRoutingController) newNodeEventHandler() cache.ResourceEventHa
321325
return cache.ResourceEventHandlerFuncs{
322326
AddFunc: func(obj interface{}) {
323327
node := obj.(*v1core.Node)
324-
nodeIP, _ := utils.GetNodeIP(node)
328+
nodeIP, err := utils.GetNodeIP(node)
329+
if err != nil {
330+
glog.Errorf("New node received, but we were unable to add it as we were couldn't find it's node IP: %v", err)
331+
return
332+
}
325333

326334
glog.V(2).Infof("Received node %s added update from watch API so peer with new node", nodeIP)
327335
nrc.OnNodeUpdate(obj)
@@ -344,9 +352,15 @@ func (nrc *NetworkRoutingController) newNodeEventHandler() cache.ResourceEventHa
344352
return
345353
}
346354
}
347-
nodeIP, _ := utils.GetNodeIP(node)
355+
nodeIP, err := utils.GetNodeIP(node)
356+
// In this case even if we can't get the NodeIP that's alright as the node is being removed anyway and
357+
// future node lister operations that happen in OnNodeUpdate won't be affected as the node won't be returned
358+
if err == nil {
359+
glog.Infof("Received node %s removed update from watch API, so remove node from peer", nodeIP)
360+
} else {
361+
glog.Infof("Received node (IP unavailable) removed update from watch API, so remove node from peer")
362+
}
348363

349-
glog.Infof("Received node %s removed update from watch API, so remove node from peer", nodeIP)
350364
nrc.OnNodeUpdate(obj)
351365
},
352366
}

pkg/controllers/routing/bgp_policies.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package routing
22

33
import (
44
"errors"
5-
"fmt"
5+
"github.com/golang/glog"
66

77
"github.com/cloudnativelabs/kube-router/pkg/utils"
88
"github.com/osrg/gobgp/config"
@@ -56,7 +56,8 @@ func (nrc *NetworkRoutingController) AddPolicies() error {
5656
nodeObj := node.(*v1core.Node)
5757
nodeIP, err := utils.GetNodeIP(nodeObj)
5858
if err != nil {
59-
return fmt.Errorf("Failed to find a node IP: %s", err)
59+
glog.Errorf("Failed to find a node IP and therefore cannot add internal BGP Peer: %v", err)
60+
continue
6061
}
6162
iBGPPeers = append(iBGPPeers, nodeIP.String())
6263
}

pkg/controllers/routing/network_routes_controller.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -553,7 +553,8 @@ func (nrc *NetworkRoutingController) syncNodeIPSets() error {
553553
currentPodCidrs = append(currentPodCidrs, podCIDR)
554554
nodeIP, err := utils.GetNodeIP(node)
555555
if err != nil {
556-
return fmt.Errorf("Failed to find a node IP: %s", err)
556+
glog.Errorf("Failed to find a node IP, cannot add to node ipset which could affect routing: %v", err)
557+
continue
557558
}
558559
currentNodeIPs = append(currentNodeIPs, nodeIP.String())
559560
}

0 commit comments

Comments
 (0)