Skip to content

Commit

Permalink
tmp: fix bad node update logic
Browse files Browse the repository at this point in the history
  • Loading branch information
sharnoff committed Dec 14, 2024
1 parent c7dee65 commit babcffc
Showing 1 changed file with 17 additions and 20 deletions.
37 changes: 17 additions & 20 deletions pkg/plugin/state/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,34 +210,31 @@ func (n *Node) Update(newState *Node) (changed bool) {
changed = newState.CPU.Total != n.CPU.Total || newState.Mem.Total != n.Mem.Total ||
newState.CPU.Watermark != n.CPU.Watermark || newState.Mem.Watermark != n.Mem.Watermark

// check if the labels changed:
if !changed {
tmpNewLabels := newState.Labels.NewTransaction()
n.Labels.Iter(func(lc LoopControl, label string, value string) LoopControlFlow {
v, ok := tmpNewLabels.Get(label)
if !ok || v != value {
changed = true
return lc.Break()
}

// remove from tmpNewLabels so it should be empty after if all the labels match
tmpNewLabels.Delete(label)
return lc.Continue()
})
tmpNewLabels.Iter(func(lc LoopControl, label string, value string) LoopControlFlow {
// there's at least one label in the new node state that doesn't exist in the old one.
// Propagate changes to labels:
newState.Labels.Iter(func(lc LoopControl, label string, value string) LoopControlFlow {
v, ok := n.Labels.Get(label)
if !ok || v != value {
n.Labels.Set(label, value)
changed = true
return lc.Break()
})
}
}
return lc.Continue()
})
n.Labels.Iter(func(lc LoopControl, label string, value string) LoopControlFlow {
// remove labels that no longer exist
if _, ok := newState.Labels.Get(label); !ok {
n.Labels.Delete(label)
changed = true
}
return lc.Continue()
})

if !changed {
return
}

*n = Node{
Name: n.Name,
Labels: newState.Labels,
Labels: n.Labels,
pods: n.pods,
migratablePods: n.migratablePods,
CPU: NodeResources[vmv1.MilliCPU]{
Expand Down

0 comments on commit babcffc

Please sign in to comment.