Skip to content

Commit e4ad531

Browse files
fix(apiserversource): fix backoff reset and dead test assertion
Backoff was reset on every successful LIST and Watch creation, so LIST-ok -> Watch-fail could hammer the API server at 1 req/s forever without ever reaching the 60s cap. Now resets only when a watch survives >30s; short-lived drains incur a backoff step so normal watch-close does not spin hot. Test assertion errors.Is(err, err) was always true; replaced with checks that error contains "mutually exclusive" and path "metadata.annotations".
1 parent a9f7673 commit e4ad531

2 files changed

Lines changed: 21 additions & 4 deletions

File tree

pkg/adapter/apiserver/adapter.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,6 @@ func (a *apiServerAdapter) watchResourceLoop(ctx context.Context, ri dynamic.Res
188188
continue
189189
}
190190
rv := list.GetResourceVersion()
191-
backoff = noCacheBackoff()
192191

193192
w, err := ri.Watch(ctx, metav1.ListOptions{
194193
LabelSelector: labelSelector,
@@ -209,8 +208,21 @@ func (a *apiServerAdapter) watchResourceLoop(ctx context.Context, ri dynamic.Res
209208
}
210209
continue
211210
}
212-
backoff = noCacheBackoff()
211+
212+
watchStart := time.Now()
213213
a.drainWatchEvents(ctx, w, delegate)
214+
if time.Since(watchStart) > 30*time.Second {
215+
// Watch was long-lived; treat connection as stable and reset backoff.
216+
backoff = noCacheBackoff()
217+
} else {
218+
t := time.NewTimer(backoff.Step())
219+
select {
220+
case <-ctx.Done():
221+
t.Stop()
222+
return
223+
case <-t.C:
224+
}
225+
}
214226
}
215227
}
216228

pkg/apis/sources/v1/apiserver_validation_test.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package v1
1919
import (
2020
"context"
2121
"errors"
22+
"strings"
2223
"testing"
2324

2425
"github.com/stretchr/testify/assert"
@@ -294,8 +295,12 @@ func TestAPIServerDisableCacheAnnotationValidation(t *testing.T) {
294295
if err == nil {
295296
t.Fatal("expected validation error for conflicting annotations, got nil")
296297
}
297-
if !errors.Is(err, err) {
298-
t.Errorf("unexpected error: %v", err)
298+
errStr := err.Error()
299+
if !strings.Contains(errStr, "mutually exclusive") {
300+
t.Errorf("error missing 'mutually exclusive': %v", err)
301+
}
302+
if !strings.Contains(errStr, "metadata.annotations") {
303+
t.Errorf("error missing field path 'metadata.annotations': %v", err)
299304
}
300305
})
301306

0 commit comments

Comments
 (0)