Skip to content

Commit

Permalink
node: Integration test for node ID lifecycle
Browse files Browse the repository at this point in the history
The node ID lifecycle is tied to the node lifecycle. This commit adds an
integration test to cover this lifecycle. It covers the creation and
deletion of nodes, as well as the update of a node's IP addresses. It
also checks that two nodes don't end up with the same node ID and that
each node has a single node ID for all its IP addresses.

Signed-off-by: Paul Chaignon <paul.chaignon@gmail.com>
  • Loading branch information
pchaigno committed Jul 27, 2023
1 parent 52b0430 commit fc8da72
Showing 1 changed file with 105 additions and 0 deletions.
105 changes: 105 additions & 0 deletions pkg/datapath/linux/node_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -643,6 +643,111 @@ func (s *linuxPrivilegedBaseTestSuite) TestNodeUpdateEncapsulation(c *check.C) {
}
}

// Tests that the node ID BPF map is correctly updated during the lifecycle of
// nodes and that the mapping nodeID:node remains 1:1.
func (s *linuxPrivilegedBaseTestSuite) TestNodeUpdateIDs(c *check.C) {
nodeIP1 := net.ParseIP("4.4.4.4")
nodeIP2 := net.ParseIP("8.8.8.8")
nodeIP3 := net.ParseIP("1.1.1.1")

nodeMap := nodemapfake.NewFakeNodeMap()

dpConfig := DatapathConfiguration{HostDevice: dummyHostDeviceName}
linuxNodeHandler := NewNodeHandler(dpConfig, s.nodeAddressing, nodeMap)
c.Assert(linuxNodeHandler, check.Not(check.IsNil))

err := linuxNodeHandler.NodeConfigurationChanged(datapath.LocalNodeConfiguration{
EnableIPv4: s.enableIPv4,
EnableIPv6: s.enableIPv6,
})
c.Assert(err, check.IsNil)

// New node receives a node ID.
node1v1 := nodeTypes.Node{
Name: "node1",
IPAddresses: []nodeTypes.Address{
{IP: nodeIP1, Type: nodeaddressing.NodeInternalIP},
},
}
err = linuxNodeHandler.NodeAdd(node1v1)
c.Assert(err, check.IsNil)

nodeID1, err := nodeMap.Lookup(nodeIP1)
c.Assert(err, check.IsNil)
c.Assert(nodeID1, check.Not(check.Equals), 0)

// When the node is updated, the new IPs are mapped to the existing node ID.
node1v2 := nodeTypes.Node{
Name: "node1",
IPAddresses: []nodeTypes.Address{
{IP: nodeIP1, Type: nodeaddressing.NodeInternalIP},
{IP: nodeIP2, Type: nodeaddressing.NodeExternalIP},
},
}
err = linuxNodeHandler.NodeUpdate(node1v1, node1v2)
c.Assert(err, check.IsNil)

_, err = nodeMap.Lookup(nodeIP1)
c.Assert(err, check.IsNil)
nodeID2, err := nodeMap.Lookup(nodeIP2)
c.Assert(err, check.IsNil)
c.Assert(nodeID2, check.Equals, nodeID1)

// When the node is updated, the old IPs are unmapped from the node ID.
node1v3 := nodeTypes.Node{
Name: "node1",
IPAddresses: []nodeTypes.Address{
{IP: nodeIP2, Type: nodeaddressing.NodeExternalIP},
},
}
err = linuxNodeHandler.NodeUpdate(node1v2, node1v3)
c.Assert(err, check.IsNil)

_, err = nodeMap.Lookup(nodeIP1)
c.Assert(err, check.ErrorMatches, "IP not found in node ID map")
nodeID3, err := nodeMap.Lookup(nodeIP2)
c.Assert(err, check.IsNil)
c.Assert(nodeID3, check.Equals, nodeID2)

// If a second node is created, it receives a different node ID.
node2 := nodeTypes.Node{
Name: "node2",
IPAddresses: []nodeTypes.Address{
{IP: nodeIP1, Type: nodeaddressing.NodeInternalIP},
},
}
err = linuxNodeHandler.NodeAdd(node2)
c.Assert(err, check.IsNil)

nodeID4, err := nodeMap.Lookup(nodeIP1)
c.Assert(err, check.IsNil)
c.Assert(nodeID4, check.Not(check.Equals), nodeID3)

// When the node is deleted, all references to its ID are also removed.
err = linuxNodeHandler.NodeDelete(node1v3)
c.Assert(err, check.IsNil)

_, err = nodeMap.Lookup(nodeIP2)
c.Assert(err, check.ErrorMatches, "IP not found in node ID map")

// When a node is created with multiple IP addresses, they all have the same ID.
node3 := nodeTypes.Node{
Name: "node3",
IPAddresses: []nodeTypes.Address{
{IP: nodeIP2, Type: nodeaddressing.NodeInternalIP},
{IP: nodeIP3, Type: nodeaddressing.NodeCiliumInternalIP},
},
}
err = linuxNodeHandler.NodeAdd(node3)
c.Assert(err, check.IsNil)

nodeID5, err := nodeMap.Lookup(nodeIP2)
c.Assert(err, check.IsNil)
nodeID6, err := nodeMap.Lookup(nodeIP3)
c.Assert(err, check.IsNil)
c.Assert(nodeID5, check.Equals, nodeID6)
}

func lookupDirectRoute(CIDR *cidr.CIDR, nodeIP net.IP) ([]netlink.Route, error) {
routeSpec, err := createDirectRouteSpec(CIDR, nodeIP)
if err != nil {
Expand Down

0 comments on commit fc8da72

Please sign in to comment.