Skip to content

Commit

Permalink
fix: fix node readiness condition logic
Browse files Browse the repository at this point in the history
Longhron 9616

Signed-off-by: Derek Su <[email protected]>
  • Loading branch information
derekbit committed Oct 14, 2024
1 parent 4e21dd8 commit 56903ba
Showing 1 changed file with 8 additions and 11 deletions.
19 changes: 8 additions & 11 deletions controller/node_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -1978,10 +1978,10 @@ func isNodeOrDisksEvictionRequested(node *longhorn.Node) bool {
return false
}

func (nc *NodeController) setReadyAndSchedulableConditions(node *longhorn.Node, kubeNode *corev1.Node,
managerPods []*corev1.Pod) error {
nodeReady := nc.setReadyConditionForManagerPod(node, managerPods)
nodeReady = nodeReady && nc.setReadyConditionForKubeNode(node, kubeNode)
func (nc *NodeController) setReadyAndSchedulableConditions(node *longhorn.Node, kubeNode *corev1.Node, managerPods []*corev1.Pod) error {
nodeReady := true
nodeReady = nc.setReadyConditionForManagerPod(node, managerPods, nodeReady)
nodeReady = nc.setReadyConditionForKubeNode(node, kubeNode, nodeReady)
if nodeReady {
// Only record true if we did not already record false.
node.Status.Conditions = types.SetConditionAndRecord(node.Status.Conditions,
Expand All @@ -2000,9 +2000,7 @@ func (nc *NodeController) setReadyAndSchedulableConditions(node *longhorn.Node,
return nil
}

func (nc *NodeController) setReadyConditionForManagerPod(node *longhorn.Node,
managerPods []*corev1.Pod) (nodeReady bool) {
nodeReady = true
func (nc *NodeController) setReadyConditionForManagerPod(node *longhorn.Node, managerPods []*corev1.Pod, nodeReady bool) bool {
nodeManagerFound := false
for _, pod := range managerPods {
if pod.Spec.NodeName == node.Name {
Expand Down Expand Up @@ -2032,11 +2030,10 @@ func (nc *NodeController) setReadyConditionForManagerPod(node *longhorn.Node,
fmt.Sprintf("Manager pod is missing: node %v has no manager pod running on it", node.Name),
nc.eventRecorder, node, corev1.EventTypeWarning)
}
return // nodeReady is already correctly set.
return nodeReady
}

func (nc *NodeController) setReadyConditionForKubeNode(node *longhorn.Node, kubeNode *corev1.Node) (nodeReady bool) {
nodeReady = true
func (nc *NodeController) setReadyConditionForKubeNode(node *longhorn.Node, kubeNode *corev1.Node, nodeReady bool) bool {
kubeConditions := kubeNode.Status.Conditions
for _, con := range kubeConditions {
switch con.Type {
Expand Down Expand Up @@ -2071,7 +2068,7 @@ func (nc *NodeController) setReadyConditionForKubeNode(node *longhorn.Node, kube
}
}
}
return // nodeReady is already correctly set.
return nodeReady
}

// Update node condition based on DisableSchedulingOnCordonedNode setting and Kubernetes node status.
Expand Down

0 comments on commit 56903ba

Please sign in to comment.