mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-11-28 03:47:34 +00:00
Add a backoff policy for failing pods.
This commit is contained in:
@@ -187,7 +187,11 @@ func TestDefaultErrorFunc(t *testing.T) {
|
||||
server := httptest.NewServer(mux)
|
||||
factory := ConfigFactory{client.NewOrDie(&client.Config{Host: server.URL, Version: testapi.Version()})}
|
||||
queue := cache.NewFIFO()
|
||||
errFunc := factory.makeDefaultErrorFunc(queue)
|
||||
podBackoff := podBackoff{
|
||||
perPodBackoff: map[string]*backoffEntry{},
|
||||
clock: &fakeClock{},
|
||||
}
|
||||
errFunc := factory.makeDefaultErrorFunc(&podBackoff, queue)
|
||||
|
||||
errFunc(testPod, nil)
|
||||
for {
|
||||
@@ -276,6 +280,14 @@ func TestMinionEnumerator(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
type fakeClock struct {
|
||||
t time.Time
|
||||
}
|
||||
|
||||
func (f *fakeClock) Now() time.Time {
|
||||
return f.t
|
||||
}
|
||||
|
||||
func TestBind(t *testing.T) {
|
||||
table := []struct {
|
||||
binding *api.Binding
|
||||
@@ -301,3 +313,55 @@ func TestBind(t *testing.T) {
|
||||
handler.ValidateRequest(t, "/api/"+testapi.Version()+"/bindings", "POST", &expectedBody)
|
||||
}
|
||||
}
|
||||
|
||||
func TestBackoff(t *testing.T) {
|
||||
clock := fakeClock{}
|
||||
backoff := podBackoff{
|
||||
perPodBackoff: map[string]*backoffEntry{},
|
||||
clock: &clock,
|
||||
}
|
||||
|
||||
tests := []struct {
|
||||
podID string
|
||||
expectedDuration time.Duration
|
||||
advanceClock time.Duration
|
||||
}{
|
||||
{
|
||||
podID: "foo",
|
||||
expectedDuration: 1 * time.Second,
|
||||
},
|
||||
{
|
||||
podID: "foo",
|
||||
expectedDuration: 2 * time.Second,
|
||||
},
|
||||
{
|
||||
podID: "foo",
|
||||
expectedDuration: 4 * time.Second,
|
||||
},
|
||||
{
|
||||
podID: "bar",
|
||||
expectedDuration: 1 * time.Second,
|
||||
advanceClock: 120 * time.Second,
|
||||
},
|
||||
// 'foo' should have been gc'd here.
|
||||
{
|
||||
podID: "foo",
|
||||
expectedDuration: 1 * time.Second,
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
duration := backoff.getBackoff(test.podID)
|
||||
if duration != test.expectedDuration {
|
||||
t.Errorf("expected: %s, got %s for %s", test.expectedDuration.String(), duration.String(), test.podID)
|
||||
}
|
||||
clock.t = clock.t.Add(test.advanceClock)
|
||||
backoff.gc()
|
||||
}
|
||||
|
||||
backoff.perPodBackoff["foo"].backoff = 60 * time.Second
|
||||
duration := backoff.getBackoff("foo")
|
||||
if duration != 60*time.Second {
|
||||
t.Errorf("expected: 60, got %s", duration.String())
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user