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:
Yu-Ju Hong 2015-12-21 09:08:18 -08:00
parent 73a4f8225c
commit 4ab505606b
2 changed files with 2 additions and 20 deletions

View File

@ -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)
}

View File

@ -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())
}