Skip to content

Commit 7e57d43

Browse files
committed
k8s: include entity kind/name in kubectl timeout error message
When kubectl apply times out, the error now identifies which resource timed out (e.g. "Deployment/my-app") instead of just reporting the duration. Also fixes the timeout condition which was checking wgCtx instead of the returned error, making the timeout error unreachable. Fixes #3686 Signed-off-by: Brent Hiranaka <brenthiranaka95@gmail.com>
1 parent 98108ca commit 7e57d43

2 files changed

Lines changed: 11 additions & 4 deletions

File tree

internal/k8s/client.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -313,8 +313,8 @@ func ServiceURL(service *v1.Service, ip NodeIP) (*url.URL, error) {
313313
return nil, nil
314314
}
315315

316-
func timeoutError(timeout time.Duration) error {
317-
return errors.New(fmt.Sprintf("Killed kubectl. Hit timeout of %v.", timeout))
316+
func timeoutError(timeout time.Duration, entity K8sEntity) error {
317+
return errors.New(fmt.Sprintf("Killed kubectl. Hit timeout of %v applying %s/%s.", timeout, entity.GVK().Kind, entity.Name()))
318318
}
319319

320320
func (k *K8sClient) ToRESTConfig() (*rest.Config, error) {
@@ -378,8 +378,8 @@ func (k *K8sClient) upsertParallel(ctx context.Context, entities []K8sEntity, ti
378378

379379
newEntityList, err := k.escalatingUpdate(innerCtx, entity, ssa)
380380
if err != nil {
381-
if errors.Is(wgCtx.Err(), context.DeadlineExceeded) {
382-
return timeoutError(timeout)
381+
if errors.Is(err, context.DeadlineExceeded) {
382+
return timeoutError(timeout, entity)
383383
}
384384
return err
385385
}

internal/k8s/client_test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,13 @@ func TestNotEmptyNamespace(t *testing.T) {
4949
assert.Equal(t, "x", ns.String())
5050
}
5151

52+
func TestTimeoutErrorMessage(t *testing.T) {
53+
entities := MustParseYAMLFromString(t, testyaml.SanchoYAML)
54+
err := timeoutError(10*time.Second, entities[0])
55+
assert.Contains(t, err.Error(), "10s")
56+
assert.Contains(t, err.Error(), "Deployment/sancho")
57+
}
58+
5259
func TestUpsert(t *testing.T) {
5360
f := newClientTestFixture(t)
5461
postgres, err := ParseYAMLFromString(testyaml.PostgresYAML)

0 commit comments

Comments
 (0)