mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-31 15:25:57 +00:00
Always overwrite items in kubelet's work queue
This allows kubelet to change the next sync time based on the last result.
This commit is contained in:
parent
73a4f8225c
commit
4ab505606b
@ -29,8 +29,7 @@ import (
|
||||
type WorkQueue interface {
|
||||
// GetWork dequeues and returns all ready items.
|
||||
GetWork() []types.UID
|
||||
// Enqueue inserts a new item or overwrites an existing item with the
|
||||
// new timestamp (time.Now() + delay) if it is greater.
|
||||
// Enqueue inserts a new item or overwrites an existing item.
|
||||
Enqueue(item types.UID, delay time.Duration)
|
||||
}
|
||||
|
||||
@ -64,10 +63,5 @@ func (q *basicWorkQueue) GetWork() []types.UID {
|
||||
func (q *basicWorkQueue) Enqueue(item types.UID, delay time.Duration) {
|
||||
q.lock.Lock()
|
||||
defer q.lock.Unlock()
|
||||
now := q.clock.Now()
|
||||
timestamp := now.Add(delay)
|
||||
existing, ok := q.queue[item]
|
||||
if !ok || (ok && existing.Before(timestamp)) {
|
||||
q.queue[item] = timestamp
|
||||
}
|
||||
q.queue[item] = q.clock.Now().Add(delay)
|
||||
}
|
||||
|
@ -63,15 +63,3 @@ func TestGetWork(t *testing.T) {
|
||||
compareResults(t, expected, q.GetWork())
|
||||
compareResults(t, []types.UID{}, q.GetWork())
|
||||
}
|
||||
|
||||
func TestEnqueueKeepGreaterTimestamp(t *testing.T) {
|
||||
q, _ := newTestBasicWorkQueue()
|
||||
item := types.UID("foo")
|
||||
q.Enqueue(item, -7*time.Hour)
|
||||
q.Enqueue(item, 3*time.Hour)
|
||||
compareResults(t, []types.UID{}, q.GetWork())
|
||||
|
||||
q.Enqueue(item, 3*time.Hour)
|
||||
q.Enqueue(item, -7*time.Hour)
|
||||
compareResults(t, []types.UID{}, q.GetWork())
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user