-
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
152 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
100 changes: 100 additions & 0 deletions
100
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,100 @@ | ||
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 watiForTaintingTimeoutDuration = 5 * 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 | ||
stopChan chan struct{} | ||
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), | ||
stopChan: make(chan struct{}), | ||
resultChan: make(chan time.Duration), | ||
} | ||
} | ||
|
||
func (u *UpdateLatencyTracker) Start() { | ||
for { | ||
select { | ||
case <-u.stopChan: | ||
waitingForTaintingStartTime := time.Now() | ||
for { | ||
switch { | ||
case u.remainingNodeCount == 0: | ||
latency := u.calculateLatency() | ||
u.resultChan <- latency | ||
return | ||
case time.Now().After(waitingForTaintingStartTime.Add(watiForTaintingTimeoutDuration)): | ||
klog.Errorf("Timeout before tainting all nodes") | ||
close(u.resultChan) | ||
return | ||
default: | ||
time.Sleep(sleepDurationWhenPolling) | ||
u.updateFinishTime() | ||
} | ||
} | ||
|
||
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 | ||
} |
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