mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-01 07:47:56 +00:00
Merge pull request #130416 from macsko/add_backoff_expiration
Store Pod backoff expiration time in QueuedPodInfo
This commit is contained in:
commit
7c78041218
@ -20,6 +20,7 @@ import (
|
|||||||
"container/list"
|
"container/list"
|
||||||
"fmt"
|
"fmt"
|
||||||
"sync"
|
"sync"
|
||||||
|
"time"
|
||||||
|
|
||||||
v1 "k8s.io/api/core/v1"
|
v1 "k8s.io/api/core/v1"
|
||||||
"k8s.io/apimachinery/pkg/types"
|
"k8s.io/apimachinery/pkg/types"
|
||||||
@ -252,6 +253,7 @@ func (aq *activeQueue) unlockedPop(logger klog.Logger) (*framework.QueuedPodInfo
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
pInfo.Attempts++
|
pInfo.Attempts++
|
||||||
|
pInfo.BackoffExpiration = time.Time{}
|
||||||
// In flight, no concurrent events yet.
|
// In flight, no concurrent events yet.
|
||||||
if aq.isSchedulingQueueHintEnabled {
|
if aq.isSchedulingQueueHintEnabled {
|
||||||
// If the pod is already in the map, we shouldn't overwrite the inFlightPods otherwise it'd lead to a memory leak.
|
// If the pod is already in the map, we shouldn't overwrite the inFlightPods otherwise it'd lead to a memory leak.
|
||||||
|
@ -32,8 +32,6 @@ type backoffQueuer interface {
|
|||||||
// isPodBackingoff returns true if a pod is still waiting for its backoff timer.
|
// isPodBackingoff returns true if a pod is still waiting for its backoff timer.
|
||||||
// If this returns true, the pod should not be re-tried.
|
// If this returns true, the pod should not be re-tried.
|
||||||
isPodBackingoff(podInfo *framework.QueuedPodInfo) bool
|
isPodBackingoff(podInfo *framework.QueuedPodInfo) bool
|
||||||
// getBackoffTime returns the time that podInfo completes backoff
|
|
||||||
getBackoffTime(podInfo *framework.QueuedPodInfo) time.Time
|
|
||||||
// popEachBackoffCompleted run fn for all pods from podBackoffQ and podErrorBackoffQ that completed backoff while popping them.
|
// popEachBackoffCompleted run fn for all pods from podBackoffQ and podErrorBackoffQ that completed backoff while popping them.
|
||||||
popEachBackoffCompleted(logger klog.Logger, fn func(pInfo *framework.QueuedPodInfo))
|
popEachBackoffCompleted(logger klog.Logger, fn func(pInfo *framework.QueuedPodInfo))
|
||||||
|
|
||||||
@ -113,11 +111,17 @@ func (bq *backoffQueue) isPodBackingoff(podInfo *framework.QueuedPodInfo) bool {
|
|||||||
return boTime.After(bq.clock.Now())
|
return boTime.After(bq.clock.Now())
|
||||||
}
|
}
|
||||||
|
|
||||||
// getBackoffTime returns the time that podInfo completes backoff
|
// getBackoffTime returns the time that podInfo completes backoff.
|
||||||
|
// It caches the result in podInfo.BackoffExpiration and returns this value in subsequent calls.
|
||||||
|
// The cache will be cleared when this pod is poped from the scheduling queue again (i.e., at activeQ's pop),
|
||||||
|
// because of the fact that the backoff time is calculated based on podInfo.Attempts,
|
||||||
|
// which doesn't get changed until the pod's scheduling is retried.
|
||||||
func (bq *backoffQueue) getBackoffTime(podInfo *framework.QueuedPodInfo) time.Time {
|
func (bq *backoffQueue) getBackoffTime(podInfo *framework.QueuedPodInfo) time.Time {
|
||||||
|
if podInfo.BackoffExpiration.IsZero() {
|
||||||
duration := bq.calculateBackoffDuration(podInfo)
|
duration := bq.calculateBackoffDuration(podInfo)
|
||||||
backoffTime := podInfo.Timestamp.Add(duration)
|
podInfo.BackoffExpiration = podInfo.Timestamp.Add(duration)
|
||||||
return backoffTime
|
}
|
||||||
|
return podInfo.BackoffExpiration
|
||||||
}
|
}
|
||||||
|
|
||||||
// calculateBackoffDuration is a helper function for calculating the backoffDuration
|
// calculateBackoffDuration is a helper function for calculating the backoffDuration
|
||||||
|
@ -3640,7 +3640,7 @@ func TestBackOffFlow(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Check backoff duration.
|
// Check backoff duration.
|
||||||
deadline := q.backoffQ.getBackoffTime(podInfo)
|
deadline := podInfo.BackoffExpiration
|
||||||
backoff := deadline.Sub(timestamp)
|
backoff := deadline.Sub(timestamp)
|
||||||
if backoff != step.wantBackoff {
|
if backoff != step.wantBackoff {
|
||||||
t.Errorf("got backoff %s, want %s", backoff, step.wantBackoff)
|
t.Errorf("got backoff %s, want %s", backoff, step.wantBackoff)
|
||||||
|
@ -366,6 +366,8 @@ type QueuedPodInfo struct {
|
|||||||
// Number of schedule attempts before successfully scheduled.
|
// Number of schedule attempts before successfully scheduled.
|
||||||
// It's used to record the # attempts metric and calculate the backoff time this Pod is obliged to get before retrying.
|
// It's used to record the # attempts metric and calculate the backoff time this Pod is obliged to get before retrying.
|
||||||
Attempts int
|
Attempts int
|
||||||
|
// BackoffExpiration is the time when the Pod will complete its backoff.
|
||||||
|
BackoffExpiration time.Time
|
||||||
// The time when the pod is added to the queue for the first time. The pod may be added
|
// The time when the pod is added to the queue for the first time. The pod may be added
|
||||||
// back to the queue multiple times before it's successfully scheduled.
|
// back to the queue multiple times before it's successfully scheduled.
|
||||||
// It shouldn't be updated once initialized. It's used to record the e2e scheduling
|
// It shouldn't be updated once initialized. It's used to record the e2e scheduling
|
||||||
|
Loading…
Reference in New Issue
Block a user