-
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
2 changed files
with
95 additions
and
0 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
79 changes: 79 additions & 0 deletions
79
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,79 @@ | ||
package actuation | ||
|
||
import ( | ||
"time" | ||
|
||
"k8s.io/autoscaler/cluster-autoscaler/utils/kubernetes" | ||
"k8s.io/autoscaler/cluster-autoscaler/utils/taints" | ||
"k8s.io/klog/v2" | ||
) | ||
|
||
type UpdateLatencyTracker struct { | ||
startTimestamp map[string]time.Time | ||
finishTimestamp map[string]time.Time | ||
nodeLister kubernetes.NodeLister | ||
} | ||
|
||
func NewUpdateLatencyTracker(startTimestamp map[string]time.Time, nodeLister kubernetes.NodeLister) *UpdateLatencyTracker { | ||
return &UpdateLatencyTracker{ | ||
startTimestamp: startTimestamp, | ||
finishTimestamp: map[string]time.Time{}, | ||
nodeLister: nodeLister, | ||
} | ||
} | ||
|
||
func (u *UpdateLatencyTracker) Start(stopChan <-chan struct{}, resultChan chan int64) { | ||
for { | ||
select { | ||
case <-stopChan: | ||
var remainingNodes []string | ||
for node, _ := range u.startTimestamp { | ||
remainingNodes = append(remainingNodes, node) | ||
} | ||
for remainingNodes != nil { | ||
time.Sleep(100 * time.Millisecond) | ||
u.updateFinishTime() | ||
remainingNodes = u.remainingNodesToFinish(remainingNodes) | ||
} | ||
latency := u.calculateLatency() | ||
resultChan <- latency | ||
return | ||
default: | ||
} | ||
u.updateFinishTime() | ||
time.Sleep(50 * time.Millisecond) | ||
} | ||
} | ||
|
||
func (u *UpdateLatencyTracker) updateFinishTime() { | ||
nodes, err := u.nodeLister.List() | ||
if err != nil { | ||
klog.Errorf("Error listing nodes: %v", err) | ||
} | ||
for _, node := range nodes { | ||
if _, ok := u.finishTimestamp[node.Name]; !ok && taints.HasToBeDeletedTaint(node) { | ||
u.finishTimestamp[node.Name] = time.Now() | ||
} | ||
} | ||
} | ||
|
||
func (u *UpdateLatencyTracker) remainingNodesToFinish(nodes []string) []string { | ||
var remainingNodes []string | ||
for _, node := range nodes { | ||
if _, ok := u.finishTimestamp[node]; !ok { | ||
remainingNodes = append(remainingNodes, node) | ||
} | ||
} | ||
return remainingNodes | ||
} | ||
|
||
func (u *UpdateLatencyTracker) calculateLatency() int64 { | ||
var sumOfDurations time.Duration = 0 | ||
var n int64 = 0 | ||
for node, startTime := range u.startTimestamp { | ||
endTime, _ := u.finishTimestamp[node] | ||
sumOfDurations += endTime.Sub(startTime) | ||
n += 1 | ||
} | ||
return sumOfDurations.Milliseconds() / n | ||
} |