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

Bug 1550266 - Fix clearInitialNodeNetworkUnavailableCondition() in sdn master #18758

Merged
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 19 additions & 28 deletions pkg/network/master/subnets.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,53 +190,44 @@ func (master *OsdnMaster) deleteNode(nodeName string) error {
// TODO: make upstream kubelet more flexible with overlays and GCE so this
// condition doesn't get added for network plugins that don't want it, and then
// we can remove this function.
func (master *OsdnMaster) clearInitialNodeNetworkUnavailableCondition(node *kapi.Node) {
func (master *OsdnMaster) clearInitialNodeNetworkUnavailableCondition(origNode *kapi.Node) {
// Informer cache should not be mutated, so get a copy of the object
node := origNode.DeepCopy()
knode := node
cleared := false
resultErr := retry.RetryOnConflict(retry.DefaultBackoff, func() error {
var err error

if knode != node {
knode, err = master.kClient.Core().Nodes().Get(node.ObjectMeta.Name, metav1.GetOptions{})
knode, err = master.kClient.Core().Nodes().Get(node.Name, metav1.GetOptions{})
if err != nil {
return err
}
}

// Let caller modify knode's status, then push to api server.
_, condition := GetNodeCondition(&node.Status, kapi.NodeNetworkUnavailable)
if condition != nil && condition.Status != kapi.ConditionFalse && condition.Reason == "NoRouteCreated" {
condition.Status = kapi.ConditionFalse
condition.Reason = "RouteCreated"
condition.Message = "openshift-sdn cleared kubelet-set NoRouteCreated"
condition.LastTransitionTime = metav1.Now()
knode, err = master.kClient.Core().Nodes().UpdateStatus(knode)
if err == nil {
cleared = true
for i := range knode.Status.Conditions {
if knode.Status.Conditions[i].Type == kapi.NodeNetworkUnavailable {
condition := &knode.Status.Conditions[i]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for _, condition := range knode.Status.Conditions {
        if condition.Type == kapi.NodeNetworkUnavailable {

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for _, condition := range knode.Status.Conditions {

With this implementation, 'condition' is a copy from knode.Status.Conditions[i] and modifying 'condition' will not reflect any change in knode.Status.Conditions.
In this case, we do want to modify condition.{Status, Reason, ...} fields.

if condition.Status != kapi.ConditionFalse && condition.Reason == "NoRouteCreated" {
condition.Status = kapi.ConditionFalse
condition.Reason = "RouteCreated"
condition.Message = "openshift-sdn cleared kubelet-set NoRouteCreated"
condition.LastTransitionTime = metav1.Now()

if knode, err = master.kClient.Core().Nodes().UpdateStatus(knode); err == nil {
cleared = true
}
}
break
}
}
return err
})
if resultErr != nil {
utilruntime.HandleError(fmt.Errorf("status update failed for local node: %v", resultErr))
} else if cleared {
glog.Infof("Cleared node NetworkUnavailable/NoRouteCreated condition for %s", node.ObjectMeta.Name)
}
}

// TODO remove this and switch to external
// GetNodeCondition extracts the provided condition from the given status and returns that.
// Returns nil and -1 if the condition is not present, and the index of the located condition.
func GetNodeCondition(status *kapi.NodeStatus, conditionType kapi.NodeConditionType) (int, *kapi.NodeCondition) {
if status == nil {
return -1, nil
}
for i := range status.Conditions {
if status.Conditions[i].Type == conditionType {
return i, &status.Conditions[i]
}
glog.Infof("Cleared node NetworkUnavailable/NoRouteCreated condition for %s", node.Name)
}
return -1, nil
}

func (master *OsdnMaster) watchNodes() {
Expand Down