Skip to content

Commit 3777d6b

Browse files
committed
fix(k8s): satisfy staticcheck on watch-error classification
FromObject never returns nil, so the nil guard was dead code (SA4023). Extract the Status checks into a helper to drop the multi-line if, and build the Gone case from a raw Status instead of the deprecated NewGone. Signed-off-by: Rohit Rajani <rorajani@nvidia.com>
1 parent 760998a commit 3777d6b

2 files changed

Lines changed: 23 additions & 9 deletions

File tree

pkg/k8s/pod/job.go

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,19 +76,27 @@ func isRetryableWatchError(event watch.Event) bool {
7676
return false
7777
}
7878
err := apierrors.FromObject(event.Object)
79-
if err == nil {
80-
return false
81-
}
82-
if apierrors.IsResourceExpired(err) || apierrors.IsGone(err) ||
83-
apierrors.IsTimeout(err) || apierrors.IsServerTimeout(err) ||
84-
apierrors.IsTooManyRequests(err) || apierrors.IsServiceUnavailable(err) {
79+
if isTransientAPIStatus(err) {
8580
return true
8681
}
82+
// The StreamWatcher wraps transport failures in a generic InternalError, so
83+
// the Reason carries no signal and the message is the only discriminator.
8784
msg := strings.ToLower(err.Error())
8885
return strings.Contains(msg, "http2: client connection lost") ||
8986
strings.Contains(msg, "unable to decode an event from the watch stream")
9087
}
9188

89+
// isTransientAPIStatus reports whether an apiserver Status error is one the
90+
// client is expected to retry rather than a terminal rejection.
91+
func isTransientAPIStatus(err error) bool {
92+
return apierrors.IsResourceExpired(err) ||
93+
apierrors.IsGone(err) ||
94+
apierrors.IsTimeout(err) ||
95+
apierrors.IsServerTimeout(err) ||
96+
apierrors.IsTooManyRequests(err) ||
97+
apierrors.IsServiceUnavailable(err)
98+
}
99+
92100
// resumeJobWatch reconnects a Job watch that ended — the channel closed or the
93101
// apiserver emitted a retryable watch.Error (410, HTTP/2 drop) — before the
94102
// Job reached a terminal state.

pkg/k8s/pod/wait_internal_test.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -389,9 +389,15 @@ func TestIsRetryableWatchError(t *testing.T) {
389389
want: true,
390390
},
391391
{
392-
name: "410 Gone is retryable",
393-
event: errorEvent(statusOf(apierrors.NewGone("gone"))),
394-
want: true,
392+
// Built from a raw Status rather than the deprecated NewGone: a
393+
// bare 410 with no expiry semantics is what an LB-terminated
394+
// watch returns.
395+
name: "410 Gone is retryable",
396+
event: errorEvent(&metav1.Status{
397+
Status: metav1.StatusFailure,
398+
Reason: metav1.StatusReasonGone,
399+
}),
400+
want: true,
395401
},
396402
{
397403
name: "503 ServiceUnavailable is retryable",

0 commit comments

Comments
 (0)