Skip to content

Commit 48a0122

Browse files
Merge pull request #18281 from pravisankar/fix-master-nodeevent
Automatic merge from submit-queue. Bug 1538389 - Allow node IP change to update Host IP in HostSubnet resource - Node status addresses may have both old and new IP address and by validating against these addrs we may not be able to update HostSubnet with new node IP. Openshift node service waits for its HostSubnet resource with new Host IP and eventually fails. - This change fixes the above issue by reverting the change for node flip/flop. Recommended/correct way to handle node flip/flop case is to specify nodeIP config option in node-config.yaml
2 parents 7f5189a + 31fcad5 commit 48a0122

File tree

1 file changed

+15
-27
lines changed

1 file changed

+15
-27
lines changed

pkg/network/master/subnets.go

Lines changed: 15 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,10 @@ func (master *OsdnMaster) SubnetStartMaster(clusterNetworks []common.ClusterNetw
6060
return nil
6161
}
6262

63-
// addNode takes the nodeName, a preferred nodeIP, the node's annotations and other valid ip addresses
63+
// addNode takes the nodeName, a preferred nodeIP and the node's annotations
6464
// Creates or updates a HostSubnet if needed
6565
// Returns the IP address used for hostsubnet (either the preferred or one from the otherValidAddresses) and any error
66-
func (master *OsdnMaster) addNode(nodeName string, nodeIP string, hsAnnotations map[string]string, otherValidAddresses []kapi.NodeAddress) (string, error) {
66+
func (master *OsdnMaster) addNode(nodeName string, nodeIP string, hsAnnotations map[string]string) (string, error) {
6767
// Validate node IP before proceeding
6868
if err := master.networkInfo.ValidateNodeIP(nodeIP); err != nil {
6969
return "", err
@@ -74,8 +74,6 @@ func (master *OsdnMaster) addNode(nodeName string, nodeIP string, hsAnnotations
7474
if err == nil {
7575
if sub.HostIP == nodeIP {
7676
return nodeIP, nil
77-
} else if isValidNodeIP(otherValidAddresses, sub.HostIP) {
78-
return sub.HostIP, nil
7977
} else {
8078
// Node IP changed, update old subnet
8179
sub.HostIP = nodeIP
@@ -131,23 +129,6 @@ func (master *OsdnMaster) deleteNode(nodeName string) error {
131129
return nil
132130
}
133131

134-
func isValidNodeIP(validAddresses []kapi.NodeAddress, nodeIP string) bool {
135-
for _, addr := range validAddresses {
136-
if addr.Address == nodeIP {
137-
return true
138-
}
139-
}
140-
return false
141-
}
142-
143-
func getNodeIP(node *kapi.Node) (string, error) {
144-
if len(node.Status.Addresses) > 0 && node.Status.Addresses[0].Address != "" {
145-
return node.Status.Addresses[0].Address, nil
146-
} else {
147-
return netutils.GetNodeIP(node.Name)
148-
}
149-
}
150-
151132
// Because openshift-sdn uses an overlay and doesn't need GCE Routes, we need to
152133
// clear the NetworkUnavailable condition that kubelet adds to initial node
153134
// status when using GCE.
@@ -210,20 +191,27 @@ func (master *OsdnMaster) watchNodes() {
210191

211192
func (master *OsdnMaster) handleAddOrUpdateNode(obj, _ interface{}, eventType watch.EventType) {
212193
node := obj.(*kapi.Node)
213-
nodeIP, err := getNodeIP(node)
214-
if err != nil {
215-
glog.Errorf("Failed to get node IP for node %s, skipping %s event, node: %v", node.Name, eventType, node)
194+
195+
var nodeIP string
196+
for _, addr := range node.Status.Addresses {
197+
if addr.Type == kapi.NodeInternalIP {
198+
nodeIP = addr.Address
199+
break
200+
}
201+
}
202+
if len(nodeIP) == 0 {
203+
glog.Errorf("Node IP is not set for node %s, skipping %s event, node: %v", node.Name, eventType, node)
216204
return
217205
}
218206
master.clearInitialNodeNetworkUnavailableCondition(node)
219207

220-
if oldNodeIP, ok := master.hostSubnetNodeIPs[node.UID]; ok && ((nodeIP == oldNodeIP) || isValidNodeIP(node.Status.Addresses, oldNodeIP)) {
208+
if oldNodeIP, ok := master.hostSubnetNodeIPs[node.UID]; ok && (nodeIP == oldNodeIP) {
221209
return
222210
}
223211
// Node status is frequently updated by kubelet, so log only if the above condition is not met
224212
glog.V(5).Infof("Watch %s event for Node %q", eventType, node.Name)
225213

226-
usedNodeIP, err := master.addNode(node.Name, nodeIP, nil, node.Status.Addresses)
214+
usedNodeIP, err := master.addNode(node.Name, nodeIP, nil)
227215
if err != nil {
228216
glog.Errorf("Error creating subnet for node %s, ip %s: %v", node.Name, nodeIP, err)
229217
return
@@ -280,7 +268,7 @@ func (master *OsdnMaster) handleAddOrUpdateSubnet(obj, _ interface{}, eventType
280268
glog.Errorf("VNID %s is an invalid value for annotation %s. Annotation will be ignored.", vnid, networkapi.FixedVNIDHostAnnotation)
281269
}
282270
}
283-
_, err = master.addNode(hs.Name, hs.HostIP, hsAnnotations, nil)
271+
_, err = master.addNode(hs.Name, hs.HostIP, hsAnnotations)
284272
if err != nil {
285273
glog.Errorf("Error creating subnet for node %s, ip %s: %v", hs.Name, hs.HostIP, err)
286274
return

0 commit comments

Comments
 (0)