Skip to content

Commit

Permalink
Reducing calls to checkConflictingNodes()
Browse files Browse the repository at this point in the history
This fix should result in less calls to `checkConflictingNodes()` which
makes API calls to `client.Nodes.List()` which is a very expensive call.

Added in env car check to `DISABLE_NODE_IP_CHECK`, will skip conflict
checks if set to "true".
  • Loading branch information
heschlie committed Jul 18, 2017
1 parent f61eef2 commit 1dbc0af
Showing 1 changed file with 23 additions and 7 deletions.
30 changes: 23 additions & 7 deletions calico_node/startup/startup.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,17 @@ func main() {
node := getNode(client, nodeName)

// Configure and verify the node IP addresses and subnets.
configureIPsAndSubnets(node)
checkConflicts := configureIPsAndSubnets(node)

// If we report an IP change (v4 or v6) we should verify there are no
// conflicts between Nodes.
if checkConflicts && os.Getenv("DISABLE_NODE_IP_CHECK") != "true" {
checkConflictingNodes(client, node)
}

// Configure the node AS number.
configureASNumber(node)

// Check for conflicting node configuration
checkConflictingNodes(client, node)

// Check expected filesystem
ensureFilesystemAsExpected()

Expand Down Expand Up @@ -236,7 +239,7 @@ func getNode(client *client.Client, nodeName string) *api.Node {

// configureIPsAndSubnets updates the supplied node resource with IP and Subnet
// information to use for BGP.
func configureIPsAndSubnets(node *api.Node) {
func configureIPsAndSubnets(node *api.Node) bool {
// If the node resource currently has no BGP configuration, add an empty
// set of configuration as it makes the processing below easier, and we
// must end up configuring some BGP fields before we complete.
Expand All @@ -245,6 +248,10 @@ func configureIPsAndSubnets(node *api.Node) {
node.Spec.BGP = &api.NodeBGPSpec{}
}

// This flag will let us know if we need to check conflicts when we see our
// IP address (v4 or v6) change.
checkConflicts := false

// Determine the autodetection type for IPv4 and IPv6. Note that we
// only autodetect IPv4 when it has not been specified. IPv6 must be
// explicitly requested using the "autodetect" value.
Expand All @@ -256,7 +263,11 @@ func configureIPsAndSubnets(node *api.Node) {
adm := os.Getenv("IP_AUTODETECTION_METHOD")
cidr := autoDetectCIDR(adm, 4)
if cidr != nil {
// We autodetected an IPv4 address so update the value in the node.
// We autodetected an IPv4 address, if we have no previous IP, or it is different than the previous IP,
// we need to update it and check for conflicts.
if node.Spec.BGP.IPv4Address == nil || !node.Spec.BGP.IPv4Address.IP.Equal(cidr.IP) {
checkConflicts = true
}
node.Spec.BGP.IPv4Address = cidr
} else if node.Spec.BGP.IPv4Address == nil {
// No IPv4 address is configured, but we always require one, so exit.
Expand Down Expand Up @@ -284,7 +295,11 @@ func configureIPsAndSubnets(node *api.Node) {
adm := os.Getenv("IP6_AUTODETECTION_METHOD")
cidr := autoDetectCIDR(adm, 6)
if cidr != nil {
// We autodetected an IPv6 address so update the value in the node.
// We autodetected an IPv6 address, if we have no previous IP, or it is different than the previous IP,
// we need to update it and check for conflicts.
if node.Spec.BGP.IPv6Address == nil || !node.Spec.BGP.IPv6Address.IP.Equal(cidr.IP) {
checkConflicts = true
}
node.Spec.BGP.IPv6Address = cidr
} else if node.Spec.BGP.IPv6Address == nil {
// No IPv6 address is configured, but we have requested one, so exit.
Expand All @@ -308,6 +323,7 @@ func configureIPsAndSubnets(node *api.Node) {
validateIP(node.Spec.BGP.IPv6Address)
}

return checkConflicts
}

// fetchAndValidateIPAndNetwork fetches and validates the IP configuration from
Expand Down

0 comments on commit 1dbc0af

Please sign in to comment.