Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[v1.13] Author Backport of #31380 #31657

Merged
merged 1 commit into from
Apr 5, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 18 additions & 0 deletions pkg/datapath/linux/node_ids.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ func (n *linuxNodeHandler) allocateIDForNode(node *nodeTypes.Node) uint16 {
nodeID = uint16(n.nodeIDs.AllocateID())
if nodeID == uint16(idpool.NoID) {
log.WithField(logfields.NodeName, node.Name).Error("No more IDs available for nodes")
// If we failed to allocate nodeID, don't map any IP to 0 nodeID.
// This causes later errors like "Found a foreign IP address with the ID of the current node"
// so we make early return here.
return nodeID
} else {
log.WithFields(logrus.Fields{
logfields.NodeID: nodeID,
Expand Down Expand Up @@ -212,11 +216,15 @@ func (n *linuxNodeHandler) DumpNodeIDs() []*models.NodeID {
func (n *linuxNodeHandler) RestoreNodeIDs() {
// Retrieve node IDs from the BPF map to be able to restore them.
nodeIDs := make(map[string]uint16)
incorrectNodeIDs := make(map[string]struct{})
parse := func(key *nodemap.NodeKey, val *nodemap.NodeValue) {
address := key.IP.String()
if key.Family == bpf.EndpointKeyIPv4 {
address = net.IP(key.IP[:net.IPv4len]).String()
}
if val.NodeID == 0 {
incorrectNodeIDs[address] = struct{}{}
}
nodeIDs[address] = val.NodeID
}
if err := nodemap.NodeMap().IterateWithCallback(parse); err != nil {
Expand All @@ -225,6 +233,16 @@ func (n *linuxNodeHandler) RestoreNodeIDs() {
}

n.registerNodeIDAllocations(nodeIDs)
if len(incorrectNodeIDs) > 0 {
log.Warnf("Removing %d incorrect node IP to node ID mappings from the BPF map", len(incorrectNodeIDs))
}
for ip := range incorrectNodeIDs {
if err := n.unmapNodeID(ip); err != nil {
log.WithError(err).WithFields(logrus.Fields{
logfields.IPAddr: ip,
}).Warn("Failed to remove a incorrect node IP to node ID mapping")
}
}
log.Infof("Restored %d node IDs from the BPF map", len(nodeIDs))
}

Expand Down