Skip to content

Commit dacd766

Browse files
author
Rajat Chopra
committed
Fix for bz1438402
* where when a node is rebooted alongwith the master, and node reports with a flipped status address. It causes the hostsubnet to be re-assigned. * the fix looks at all existing valid addresses and if the existing hostsubnet has a nodeIP that is among the valid ones, then no update is performed.
1 parent 7c91f63 commit dacd766

File tree

1 file changed

+19
-14
lines changed

1 file changed

+19
-14
lines changed

pkg/sdn/plugin/subnets.go

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -48,33 +48,38 @@ func (master *OsdnMaster) SubnetStartMaster(clusterNetwork *net.IPNet, hostSubne
4848
return nil
4949
}
5050

51-
func (master *OsdnMaster) addNode(nodeName string, nodeIP string, hsAnnotations map[string]string) error {
51+
// addNode takes the nodeName, a preferred nodeIP, the node's annotations and other valid ip addresses
52+
// Creates or updates a HostSubnet if needed
53+
// Returns the IP address used for hostsubnet (either the preferred or one from the otherValidAddresses) and any error
54+
func (master *OsdnMaster) addNode(nodeName string, nodeIP string, hsAnnotations map[string]string, otherValidAddresses []kapi.NodeAddress) (string, error) {
5255
// Validate node IP before proceeding
5356
if err := master.networkInfo.validateNodeIP(nodeIP); err != nil {
54-
return err
57+
return "", err
5558
}
5659

5760
// Check if subnet needs to be created or updated
5861
sub, err := master.osClient.HostSubnets().Get(nodeName)
5962
if err == nil {
6063
if sub.HostIP == nodeIP {
61-
return nil
64+
return nodeIP, nil
65+
} else if isValidNodeIP(otherValidAddresses, sub.HostIP) {
66+
return sub.HostIP, nil
6267
} else {
6368
// Node IP changed, update old subnet
6469
sub.HostIP = nodeIP
6570
sub, err = master.osClient.HostSubnets().Update(sub)
6671
if err != nil {
67-
return fmt.Errorf("error updating subnet %s for node %s: %v", sub.Subnet, nodeName, err)
72+
return "", fmt.Errorf("error updating subnet %s for node %s: %v", sub.Subnet, nodeName, err)
6873
}
6974
log.Infof("Updated HostSubnet %s", hostSubnetToString(sub))
70-
return nil
75+
return nodeIP, nil
7176
}
7277
}
7378

7479
// Create new subnet
7580
sn, err := master.subnetAllocator.GetNetwork()
7681
if err != nil {
77-
return fmt.Errorf("error allocating network for node %s: %v", nodeName, err)
82+
return "", fmt.Errorf("error allocating network for node %s: %v", nodeName, err)
7883
}
7984

8085
sub = &osapi.HostSubnet{
@@ -87,10 +92,10 @@ func (master *OsdnMaster) addNode(nodeName string, nodeIP string, hsAnnotations
8792
sub, err = master.osClient.HostSubnets().Create(sub)
8893
if err != nil {
8994
master.subnetAllocator.ReleaseNetwork(sn)
90-
return fmt.Errorf("error creating subnet %s for node %s: %v", sn.String(), nodeName, err)
95+
return "", fmt.Errorf("error creating subnet %s for node %s: %v", sn.String(), nodeName, err)
9196
}
9297
log.Infof("Created HostSubnet %s", hostSubnetToString(sub))
93-
return nil
98+
return nodeIP, nil
9499
}
95100

96101
func (master *OsdnMaster) deleteNode(nodeName string) error {
@@ -107,8 +112,8 @@ func (master *OsdnMaster) deleteNode(nodeName string) error {
107112
return nil
108113
}
109114

110-
func isValidNodeIP(node *kapi.Node, nodeIP string) bool {
111-
for _, addr := range node.Status.Addresses {
115+
func isValidNodeIP(validAddresses []kapi.NodeAddress, nodeIP string) bool {
116+
for _, addr := range validAddresses {
112117
if addr.Address == nodeIP {
113118
return true
114119
}
@@ -180,17 +185,17 @@ func (master *OsdnMaster) watchNodes() {
180185
case cache.Sync, cache.Added, cache.Updated:
181186
master.clearInitialNodeNetworkUnavailableCondition(node)
182187

183-
if oldNodeIP, ok := nodeAddressMap[uid]; ok && ((nodeIP == oldNodeIP) || isValidNodeIP(node, oldNodeIP)) {
188+
if oldNodeIP, ok := nodeAddressMap[uid]; ok && ((nodeIP == oldNodeIP) || isValidNodeIP(node.Status.Addresses, oldNodeIP)) {
184189
break
185190
}
186191
// Node status is frequently updated by kubelet, so log only if the above condition is not met
187192
log.V(5).Infof("Watch %s event for Node %q", delta.Type, name)
188193

189-
err = master.addNode(name, nodeIP, nil)
194+
usedNodeIP, err := master.addNode(name, nodeIP, nil, node.Status.Addresses)
190195
if err != nil {
191196
return fmt.Errorf("error creating subnet for node %s, ip %s: %v", name, nodeIP, err)
192197
}
193-
nodeAddressMap[uid] = nodeIP
198+
nodeAddressMap[uid] = usedNodeIP
194199
case cache.Deleted:
195200
log.V(5).Infof("Watch %s event for Node %q", delta.Type, name)
196201
delete(nodeAddressMap, uid)
@@ -242,7 +247,7 @@ func (master *OsdnMaster) watchSubnets() {
242247
log.Errorf("Vnid %s is an invalid value for annotation %s. Annotation will be ignored.", vnid, osapi.FixedVNIDHostAnnotation)
243248
}
244249
}
245-
err = master.addNode(name, hostIP, hsAnnotations)
250+
_, err = master.addNode(name, hostIP, hsAnnotations, nil)
246251
if err != nil {
247252
log.Errorf("Error creating subnet for node %s, ip %s: %v", name, hostIP, err)
248253
return nil

0 commit comments

Comments
 (0)