Skip to content

Commit 41a9151

Browse files
EIP OVN controller: remove possibility of crash, improve logging and readability
No func changes. Check if obj is nil post parsing IP. Improve logging of stale OVN config. Signed-off-by: Martin Kennelly <[email protected]>
1 parent 68db55e commit 41a9151

File tree

1 file changed

+27
-8
lines changed

1 file changed

+27
-8
lines changed

go-controller/pkg/ovn/egressip.go

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1446,7 +1446,7 @@ func (e *EgressIPController) syncStaleGWMarkRules(egressIPCache egressIPCache) e
14461446
continue
14471447
}
14481448
for networkName, podCache := range networkPodCache {
1449-
for eIP, nodeName := range egressIPCache.egressIPIPToNodeCache {
1449+
for eIPIP, nodeName := range egressIPCache.egressIPIPToNodeCache {
14501450
if !egressIPCache.egressLocalNodesCache.Has(nodeName) {
14511451
continue
14521452
}
@@ -1460,7 +1460,7 @@ func (e *EgressIPController) syncStaleGWMarkRules(egressIPCache egressIPCache) e
14601460
return fmt.Errorf("failed to create new network %s: %v", networkName, err)
14611461
}
14621462
routerName := ni.GetNetworkScopedGWRouterName(nodeName)
1463-
isEIPIPv6 := utilnet.IsIPv6String(eIP)
1463+
isEIPIPv6 := utilnet.IsIPv6String(eIPIP)
14641464
for podKey, podIPs := range podCache.egressLocalPods {
14651465
ops, err = processPodFn(ops, eIPName, podKey, egressIPCache.markCache[eIPName], routerName, networkName, podIPs, isEIPIPv6)
14661466
if err != nil {
@@ -1679,7 +1679,14 @@ func (e *EgressIPController) syncStaleEgressReroutePolicy(cache egressIPCache) e
16791679

16801680
// Update Logical Router Policies that have stale nexthops. Notice that we must do this separately
16811681
// because logicalRouterPolicyStaleNexthops must be populated first
1682-
klog.Infof("syncStaleEgressReroutePolicy will remove stale nexthops for network %s: %+v", networkName, logicalRouterPolicyStaleNexthops)
1682+
for _, staleNextHopLogicalRouterPolicy := range logicalRouterPolicyStaleNexthops {
1683+
if staleNextHopLogicalRouterPolicy.Nexthop == nil {
1684+
continue
1685+
}
1686+
klog.Infof("syncStaleEgressReroutePolicy will remove stale nexthops for LRP %q for network %s: %s",
1687+
staleNextHopLogicalRouterPolicy.UUID, networkName, *staleNextHopLogicalRouterPolicy.Nexthop)
1688+
}
1689+
16831690
err = libovsdbops.DeleteNextHopsFromLogicalRouterPolicies(e.nbClient, cache.networkToRouter[networkName], logicalRouterPolicyStaleNexthops...)
16841691
if err != nil {
16851692
return fmt.Errorf("unable to remove stale next hops from logical router policies for network %s: %v", networkName, err)
@@ -1709,7 +1716,13 @@ func (e *EgressIPController) syncStaleSNATRules(egressIPCache egressIPCache) err
17091716
return false
17101717
}
17111718
egressIPName := egressIPMeta[0]
1712-
parsedLogicalIP := net.ParseIP(item.LogicalIP).String()
1719+
// check logical IP maps to a valid pod
1720+
parsedPodIP := net.ParseIP(item.LogicalIP)
1721+
if parsedPodIP == nil {
1722+
klog.Errorf("syncStaleSNATRules found invalid logical IP for NAT with UID %q", item.UUID)
1723+
return true
1724+
}
1725+
parsedPodIPStr := parsedPodIP.String()
17131726
cacheEntry, exists := egressIPCache.egressIPNameToPods[egressIPName][types.DefaultNetworkName]
17141727
egressPodIPs := sets.NewString()
17151728
if exists {
@@ -1722,7 +1735,7 @@ func (e *EgressIPController) syncStaleSNATRules(egressIPCache egressIPCache) err
17221735
egressPodIPs.Insert(podIPs.UnsortedList()...)
17231736
}
17241737
}
1725-
if !exists || !egressPodIPs.Has(parsedLogicalIP) {
1738+
if !exists || !egressPodIPs.Has(parsedPodIPStr) {
17261739
klog.Infof("syncStaleSNATRules will delete %s due to logical ip: %v", egressIPName, item)
17271740
return true
17281741
}
@@ -1731,9 +1744,15 @@ func (e *EgressIPController) syncStaleSNATRules(egressIPCache egressIPCache) err
17311744
klog.Errorf("syncStaleSNATRules failed to find default network in networks cache")
17321745
return false
17331746
}
1734-
if node, ok := egressIPCache.egressIPIPToNodeCache[item.ExternalIP]; !ok || !cacheEntry.egressLocalPods[types.DefaultNetworkName].Has(node) ||
1735-
item.LogicalPort == nil || *item.LogicalPort != ni.GetNetworkScopedK8sMgmtIntfName(node) {
1736-
klog.Infof("syncStaleSNATRules will delete %s due to external ip or stale logical port: %v", egressIPName, item)
1747+
// check external IP maps to a valid EgressIP IP and its assigned to a Node
1748+
node, ok := egressIPCache.egressIPIPToNodeCache[item.ExternalIP]
1749+
if !ok {
1750+
klog.Infof("syncStaleSNATRules found NAT %q without EIP assigned to a Node", item.UUID)
1751+
return true
1752+
}
1753+
// check logical port is set and correspondes to the correct egress node
1754+
if item.LogicalPort == nil || *item.LogicalPort != ni.GetNetworkScopedK8sMgmtIntfName(node) {
1755+
klog.Infof("syncStaleSNATRules found NAT %q with invalid logical port", item.UUID)
17371756
return true
17381757
}
17391758
return false

0 commit comments

Comments
 (0)