-
Notifications
You must be signed in to change notification settings - Fork 4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix race condition between ca and scheduler
Implement dynamically adjustment of NodeDeleteDelayAfterTaint based on round trip time between ca and apiserver
- Loading branch information
Showing
4 changed files
with
159 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
107 changes: 107 additions & 0 deletions
107
cluster-autoscaler/core/scaledown/actuation/update_latency_tracker.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
package actuation | ||
|
||
import ( | ||
"time" | ||
|
||
"k8s.io/autoscaler/cluster-autoscaler/utils/kubernetes" | ||
"k8s.io/autoscaler/cluster-autoscaler/utils/taints" | ||
"k8s.io/klog/v2" | ||
) | ||
|
||
const sleepDurationWhenPolling = 50 * time.Millisecond | ||
const waitForTaintingTimeoutDuration = 2 * time.Minute | ||
|
||
type NodeTaintStartTime struct { | ||
nodeName string | ||
startTime time.Time | ||
} | ||
|
||
type UpdateLatencyTracker struct { | ||
startTimestamp map[string]time.Time | ||
finishTimestamp map[string]time.Time | ||
remainingNodeCount int | ||
nodeLister kubernetes.NodeLister | ||
StartTimeChan chan NodeTaintStartTime | ||
// Send bool for await close the chanell to stop | ||
AwaitOrStopChan chan bool | ||
ResultChan chan time.Duration | ||
} | ||
|
||
func NewUpdateLatencyTracker(nodeLister kubernetes.NodeLister) *UpdateLatencyTracker { | ||
return &UpdateLatencyTracker{ | ||
startTimestamp: map[string]time.Time{}, | ||
finishTimestamp: map[string]time.Time{}, | ||
remainingNodeCount: 0, | ||
nodeLister: nodeLister, | ||
StartTimeChan: make(chan NodeTaintStartTime), | ||
AwaitOrStopChan: make(chan bool), | ||
ResultChan: make(chan time.Duration), | ||
} | ||
} | ||
|
||
func (u *UpdateLatencyTracker) Start() { | ||
for { | ||
select { | ||
case _, ok := <-u.AwaitOrStopChan: | ||
if ok { | ||
u.await() | ||
} | ||
return | ||
case ntst := <-u.StartTimeChan: | ||
u.startTimestamp[ntst.nodeName] = ntst.startTime | ||
u.remainingNodeCount += 1 | ||
continue | ||
default: | ||
} | ||
u.updateFinishTime() | ||
time.Sleep(sleepDurationWhenPolling) | ||
} | ||
} | ||
|
||
func (u *UpdateLatencyTracker) updateFinishTime() { | ||
for nodeName, _ := range u.startTimestamp { | ||
if _, ok := u.finishTimestamp[nodeName]; ok { | ||
continue | ||
} | ||
node, err := u.nodeLister.Get(nodeName) | ||
if err != nil { | ||
klog.Errorf("Error getting node: %v", err) | ||
continue | ||
} | ||
if taints.HasToBeDeletedTaint(node) { | ||
u.finishTimestamp[node.Name] = time.Now() | ||
u.remainingNodeCount -= 1 | ||
} | ||
} | ||
} | ||
|
||
func (u *UpdateLatencyTracker) calculateLatency() time.Duration { | ||
var maxLatency time.Duration = 0 | ||
for node, startTime := range u.startTimestamp { | ||
endTime, _ := u.finishTimestamp[node] | ||
currentLatency := endTime.Sub(startTime) | ||
if currentLatency > maxLatency { | ||
maxLatency = currentLatency | ||
} | ||
} | ||
return maxLatency | ||
} | ||
|
||
func (u *UpdateLatencyTracker) await() { | ||
waitingForTaintingStartTime := time.Now() | ||
for { | ||
switch { | ||
case u.remainingNodeCount == 0: | ||
latency := u.calculateLatency() | ||
u.ResultChan <- latency | ||
return | ||
case time.Now().After(waitingForTaintingStartTime.Add(waitForTaintingTimeoutDuration)): | ||
klog.Errorf("Timeout before tainting all nodes") | ||
close(u.ResultChan) | ||
return | ||
default: | ||
time.Sleep(sleepDurationWhenPolling) | ||
u.updateFinishTime() | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters