From e5954c7dcb596acea1e85945a5dc97f7fd6cbec3 Mon Sep 17 00:00:00 2001 From: Juanadelacuesta <8647634+Juanadelacuesta@users.noreply.github.com> Date: Fri, 8 May 2026 12:39:49 +0200 Subject: [PATCH] func: rename the function and create a new status for a node that is not stored --- nomad/structs/structs.go | 1 + scheduler/generic_sched.go | 2 +- scheduler/reconciler/reconcile_cluster_test.go | 2 +- scheduler/scheduler_sysbatch.go | 2 +- scheduler/scheduler_system.go | 2 +- scheduler/util.go | 14 +++++++++----- scheduler/util_test.go | 4 ++-- 7 files changed, 16 insertions(+), 11 deletions(-) diff --git a/nomad/structs/structs.go b/nomad/structs/structs.go index 93d8b02c75a..f76bdf1162c 100644 --- a/nomad/structs/structs.go +++ b/nomad/structs/structs.go @@ -1861,6 +1861,7 @@ const ( NodeStatusReady = "ready" NodeStatusDown = "down" NodeStatusDisconnected = "disconnected" + NodeStatusNoRecord = "no_record" ) // ShouldDrainNode checks if a given node status should trigger an diff --git a/scheduler/generic_sched.go b/scheduler/generic_sched.go index 3ac133ed761..450942f343d 100644 --- a/scheduler/generic_sched.go +++ b/scheduler/generic_sched.go @@ -331,7 +331,7 @@ func (s *GenericScheduler) computeJobAllocs() error { } // Determine the tainted nodes containing job allocs - tainted, err := taintedNodes(s.state, allocs) + tainted, err := getTaintedNodes(s.state, allocs) if err != nil { return fmt.Errorf("failed to get tainted nodes for job '%s': %v", s.eval.JobID, err) diff --git a/scheduler/reconciler/reconcile_cluster_test.go b/scheduler/reconciler/reconcile_cluster_test.go index e8428fd2839..a8797a53844 100644 --- a/scheduler/reconciler/reconcile_cluster_test.go +++ b/scheduler/reconciler/reconcile_cluster_test.go @@ -5070,7 +5070,7 @@ func TestReconciler_TaintedNode_RollingUpgrade(t *testing.T) { // Tests the reconciler handles a failed deployment with allocs on tainted // nodes -func TestReconciler_FailedDeployment_TaintedNodes(t *testing.T) { +func TestReconciler_FailedDeployment_GetTaintedNodes(t *testing.T) { ci.Parallel(t) job := mock.Job() diff --git a/scheduler/scheduler_sysbatch.go b/scheduler/scheduler_sysbatch.go index 8b9e9bc4a7a..aa4cc1a145d 100644 --- a/scheduler/scheduler_sysbatch.go +++ b/scheduler/scheduler_sysbatch.go @@ -218,7 +218,7 @@ func (s *SysBatchScheduler) computeJobAllocs() error { } // Determine the tainted nodes containing job allocs - tainted, err := taintedNodes(s.state, allocs) + tainted, err := getTaintedNodes(s.state, allocs) if err != nil { return fmt.Errorf("failed to get tainted nodes for job '%s': %v", s.eval.JobID, err) } diff --git a/scheduler/scheduler_system.go b/scheduler/scheduler_system.go index 9fd17ab625b..22f093c6ade 100644 --- a/scheduler/scheduler_system.go +++ b/scheduler/scheduler_system.go @@ -235,7 +235,7 @@ func (s *SystemScheduler) computeJobAllocs() error { } // Determine the tainted nodes containing job allocs - tainted, err := taintedNodes(s.state, allocs) + tainted, err := getTaintedNodes(s.state, allocs) if err != nil { return fmt.Errorf("failed to get tainted nodes for job '%s': %v", s.eval.JobID, err) } diff --git a/scheduler/util.go b/scheduler/util.go index b461c0834ba..7744c618428 100644 --- a/scheduler/util.go +++ b/scheduler/util.go @@ -96,12 +96,13 @@ func progressMade(result *structs.PlanResult) bool { len(result.DeploymentUpdates) != 0) } -// taintedNodes is used to scan the allocations and then check if the +// getTaintedNodes is used to scan the allocations and then check if the // underlying nodes are tainted, and should force a migration of the allocation, // or if the underlying nodes are disconnected, and should be used to calculate // the reconnect timeout of its allocations. All the nodes returned in the map are tainted. -func taintedNodes(state sstructs.State, allocs []*structs.Allocation) (map[string]*structs.Node, error) { +func getTaintedNodes(state sstructs.State, allocs []*structs.Allocation) (map[string]*structs.Node, error) { out := make(map[string]*structs.Node) + for _, alloc := range allocs { if _, ok := out[alloc.NodeID]; ok { continue @@ -115,16 +116,19 @@ func taintedNodes(state sstructs.State, allocs []*structs.Allocation) (map[strin // If the node does not exist, we should migrate if node == nil { - out[alloc.NodeID] = nil + out[alloc.NodeID] = &structs.Node{ + Status: structs.NodeStatusNoRecord, + } continue } + if structs.ShouldDrainNode(node.Status) || node.DrainStrategy != nil { out[alloc.NodeID] = node + continue } // Disconnected nodes are included in the tainted set so that their - // disconnect.lost_after configuration can be included in the - // timeout calculation. + // disconnect flow for allocs can be triggered. if node.Status == structs.NodeStatusDisconnected { out[alloc.NodeID] = node } diff --git a/scheduler/util_test.go b/scheduler/util_test.go index 5db2e54ce6c..3db7e7a5317 100644 --- a/scheduler/util_test.go +++ b/scheduler/util_test.go @@ -157,7 +157,7 @@ func TestRetryMax(t *testing.T) { must.Eq(t, 1, calls) } -func TestTaintedNodes(t *testing.T) { +func TestGetTaintedNodes(t *testing.T) { ci.Parallel(t) state := state.TestStateStore(t) @@ -180,7 +180,7 @@ func TestTaintedNodes(t *testing.T) { {NodeID: node4.ID}, {NodeID: "12345678-abcd-efab-cdef-123456789abc"}, } - tainted, err := taintedNodes(state, allocs) + tainted, err := getTaintedNodes(state, allocs) must.NoError(t, err) must.Eq(t, 3, len(tainted)) must.MapNotContainsKey(t, tainted, node1.ID)