From c1d51959d5f7bcef97510072154cb5a6b3565698 Mon Sep 17 00:00:00 2001 From: Jan Eitzinger Date: Wed, 18 Mar 2026 10:57:06 +0100 Subject: [PATCH] Change dtermineState to enforce priority order Make exception if node is idle + down, then final state is idle Entire-Checkpoint: 92c797737df8 --- internal/api/node.go | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/internal/api/node.go b/internal/api/node.go index 06787cd1..c6727866 100644 --- a/internal/api/node.go +++ b/internal/api/node.go @@ -34,21 +34,26 @@ func metricListToNames(metricList map[string]*schema.Metric) []string { return names } -// this routine assumes that only one of them exists per node +// determineState resolves multiple states to a single state using priority order: +// allocated > reserved > idle > down > mixed. +// Exception: if both idle and down are present, idle is returned. func determineState(states []string) schema.SchedulerState { - for _, state := range states { - switch strings.ToLower(state) { - case "allocated": - return schema.NodeStateAllocated - case "reserved": - return schema.NodeStateReserved - case "idle": - return schema.NodeStateIdle - case "down": - return schema.NodeStateDown - case "mixed": - return schema.NodeStateMixed - } + stateSet := make(map[string]bool, len(states)) + for _, s := range states { + stateSet[strings.ToLower(s)] = true + } + + switch { + case stateSet["allocated"]: + return schema.NodeStateAllocated + case stateSet["reserved"]: + return schema.NodeStateReserved + case stateSet["idle"]: + return schema.NodeStateIdle + case stateSet["down"]: + return schema.NodeStateDown + case stateSet["mixed"]: + return schema.NodeStateMixed } return schema.NodeStateUnknown