Skip to content

node monitoring: correctly recognize NotReady Nodes as unscheduable #345

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

Merged
merged 1 commit into from
Apr 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
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
17 changes: 15 additions & 2 deletions internal/controller/appwrapper/node_health_monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ var (
// noScheduleNodes is a mapping from Node names to ResourceLists of unschedulable resources.
// A resource may be unschedulable either because:
// (a) the Node is cordoned (node.Spec.Unschedulable is true) or
// (b) Autopilot has labeled the Node with a NoExecute or NoSchedule taint for the resource.
// (b) the Node has been marked as NotReady by Kubernetes or
// (c) Autopilot has labeled the Node with a NoExecute or NoSchedule taint for the resource.
noScheduleNodes = make(map[string]v1.ResourceList)
// noScheduleNodesMutex synchronizes access to noScheduleNodes
noScheduleNodesMutex sync.RWMutex
Expand Down Expand Up @@ -136,7 +137,7 @@ func (r *NodeHealthMonitor) updateNoExecuteNodes(ctx context.Context, node *v1.N
// update noScheduleNodes entry for node
func (r *NodeHealthMonitor) updateNoScheduleNodes(ctx context.Context, node *v1.Node) {
var noScheduleResources v1.ResourceList
if node.Spec.Unschedulable {
if r.nodeIsUnscheduable(node) {
noScheduleResources = node.Status.Capacity.DeepCopy()
delete(noScheduleResources, v1.ResourcePods)
} else {
Expand Down Expand Up @@ -178,6 +179,18 @@ func (r *NodeHealthMonitor) updateNoScheduleNodes(ctx context.Context, node *v1.
}
}

func (r *NodeHealthMonitor) nodeIsUnscheduable(node *v1.Node) bool {
if node.Spec.Unschedulable {
return true
}
for _, taint := range node.Spec.Taints {
if taint.Key == "node.kubernetes.io/unreachable" || taint.Key == "node.kubernetes.io/not-ready" {
return true
}
}
return false
}

// SetupWithManager sets up the controller with the Manager.
func (r *NodeHealthMonitor) SetupWithManager(mgr ctrl.Manager) error {
return ctrl.NewControllerManagedBy(mgr).
Expand Down
62 changes: 62 additions & 0 deletions internal/controller/appwrapper/node_health_monitor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,13 @@ var _ = Describe("NodeMonitor Controller", func() {
Expect(k8sClient.Create(ctx, node)).To(Succeed())
node = getNode(nodeName)
node.Status.Capacity = nodeGPUs
node.Status.Conditions = append(node.Status.Conditions, v1.NodeCondition{
Type: v1.NodeReady,
Status: v1.ConditionTrue,
})
Expect(k8sClient.Status().Update(ctx, node)).To(Succeed())
node.Spec.Taints = []v1.Taint{}
Expect(k8sClient.Update(ctx, node)).To(Succeed())
}

deleteNode := func(nodeName string) {
Expand Down Expand Up @@ -106,6 +112,62 @@ var _ = Describe("NodeMonitor Controller", func() {
Expect(err).NotTo(HaveOccurred())
Expect(noExecuteNodes).Should(BeEmpty())

By("A Node tainted as unreachable is detected as unscheduable")
node = getNode(node1Name.Name)
node.Spec.Taints = append(node.Spec.Taints, v1.Taint{Key: "node.kubernetes.io/unreachable", Effect: v1.TaintEffectNoExecute})
Expect(k8sClient.Update(ctx, node)).Should(Succeed())
_, err = nodeMonitor.Reconcile(ctx, reconcile.Request{NamespacedName: node1Name})
Expect(err).NotTo(HaveOccurred())
_, err = nodeMonitor.Reconcile(ctx, reconcile.Request{NamespacedName: node2Name})
Expect(err).NotTo(HaveOccurred())
Expect(noScheduleNodes).Should(HaveLen(1))
Expect(noScheduleNodes).Should(HaveKey(node1Name.Name))
Expect(noScheduleNodes[node1Name.Name]).Should(HaveKey(v1.ResourceName("nvidia.com/gpu")))

By("Repeated reconcile does not change map")
_, err = nodeMonitor.Reconcile(ctx, reconcile.Request{NamespacedName: node1Name})
Expect(err).NotTo(HaveOccurred())
_, err = nodeMonitor.Reconcile(ctx, reconcile.Request{NamespacedName: node2Name})
Expect(err).NotTo(HaveOccurred())
Expect(noScheduleNodes).Should(HaveLen(1))
Expect(noScheduleNodes).Should(HaveKey(node1Name.Name))
Expect(noScheduleNodes[node1Name.Name]).Should(HaveKey(v1.ResourceName("nvidia.com/gpu")))

By("Removing the taint updates unhealthyNodes")
node.Spec.Taints = []v1.Taint{}
Expect(k8sClient.Update(ctx, node)).Should(Succeed())
_, err = nodeMonitor.Reconcile(ctx, reconcile.Request{NamespacedName: node1Name})
Expect(err).NotTo(HaveOccurred())
Expect(noScheduleNodes).Should(BeEmpty())

By("A Node tainted as not-read is detected as unscheduable")
node = getNode(node1Name.Name)
node.Spec.Taints = append(node.Spec.Taints, v1.Taint{Key: "node.kubernetes.io/not-ready", Effect: v1.TaintEffectNoExecute})
Expect(k8sClient.Update(ctx, node)).Should(Succeed())
_, err = nodeMonitor.Reconcile(ctx, reconcile.Request{NamespacedName: node1Name})
Expect(err).NotTo(HaveOccurred())
_, err = nodeMonitor.Reconcile(ctx, reconcile.Request{NamespacedName: node2Name})
Expect(err).NotTo(HaveOccurred())
Expect(noScheduleNodes).Should(HaveLen(1))
Expect(noScheduleNodes).Should(HaveKey(node1Name.Name))
Expect(noScheduleNodes[node1Name.Name]).Should(HaveKey(v1.ResourceName("nvidia.com/gpu")))

By("Repeated reconcile does not change map")
_, err = nodeMonitor.Reconcile(ctx, reconcile.Request{NamespacedName: node1Name})
Expect(err).NotTo(HaveOccurred())
_, err = nodeMonitor.Reconcile(ctx, reconcile.Request{NamespacedName: node2Name})
Expect(err).NotTo(HaveOccurred())
Expect(noScheduleNodes).Should(HaveLen(1))
Expect(noScheduleNodes).Should(HaveKey(node1Name.Name))
Expect(noScheduleNodes[node1Name.Name]).Should(HaveKey(v1.ResourceName("nvidia.com/gpu")))

By("Removing the taint updates unhealthyNodes")
node.Spec.Taints = []v1.Taint{}
Expect(k8sClient.Update(ctx, node)).Should(Succeed())
_, err = nodeMonitor.Reconcile(ctx, reconcile.Request{NamespacedName: node1Name})
Expect(err).NotTo(HaveOccurred())
Expect(noScheduleNodes).Should(BeEmpty())

deleteNode(node1Name.Name)
deleteNode(node2Name.Name)
})
Expand Down
Loading