Skip to content

Commit

Permalink
fix(ovhcloud): Add mutex on NodeGroup.DeleteNodes to prevent outdated…
Browse files Browse the repository at this point in the history
… scale down payloads

Signed-off-by: Xavier Duthil <[email protected]>
  • Loading branch information
XavierDuthil committed Mar 10, 2023
1 parent c0219b2 commit 0907390
Showing 1 changed file with 8 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"math"
"math/rand"
"strings"
"sync"
"time"

apiv1 "k8s.io/api/core/v1"
Expand All @@ -44,6 +45,7 @@ type NodeGroup struct {

Manager *OvhCloudManager
CurrentSize int
mutex sync.Mutex
}

// MaxSize returns maximum size of the node pool.
Expand Down Expand Up @@ -111,6 +113,12 @@ func (ng *NodeGroup) IncreaseSize(delta int) error {

// DeleteNodes deletes the nodes from the group.
func (ng *NodeGroup) DeleteNodes(nodes []*apiv1.Node) error {
// DeleteNodes is called in goroutine so it can run in parallel
// Goroutines created in: ScaleDown.scheduleDeleteEmptyNodes()
// Adding mutex to ensure CurrentSize attribute keeps consistency
ng.mutex.Lock()
defer ng.mutex.Unlock()

// Do not use node group which does not support autoscaling
if !ng.Autoscale {
return nil
Expand Down

0 comments on commit 0907390

Please sign in to comment.