Skip to content

Commit f31c3d0

Browse files
tejal29dgageot
authored andcommitted
[docs] [output] meaningful message for healthcheck context exceeded. (#3177)
* meaningful message * do not use errors.Unwrap since its in 1.13 go errors
1 parent e250e90 commit f31c3d0

File tree

3 files changed

+12
-5
lines changed

3 files changed

+12
-5
lines changed

pkg/skaffold/deploy/resource/deployment.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,12 @@ package resource
1818

1919
import (
2020
"context"
21-
"errors"
21+
"fmt"
2222
"strings"
2323
"time"
2424

25+
"github.com/pkg/errors"
26+
2527
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/kubectl"
2628
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/runner/runcontext"
2729
)
@@ -34,7 +36,7 @@ const (
3436
)
3537

3638
var (
37-
errKubectlKilled = errors.New("kubectl rollout status command killed")
39+
errKubectlKilled = errors.New("kubectl rollout status command interrupted")
3840
ErrKubectlConnection = errors.New("kubectl connection error")
3941
)
4042

@@ -74,6 +76,9 @@ func (d *Deployment) CheckStatus(ctx context.Context, runCtx *runcontext.RunCont
7476
b, err := kubeCtl.RunOut(ctx, "rollout", "status", "deployment", d.name, "--namespace", d.namespace, "--watch=false")
7577
details := string(b)
7678
err = parseKubectlRolloutError(err)
79+
if err == errKubectlKilled {
80+
err = errors.Wrap(err, fmt.Sprintf("received Ctrl-C or deployments could not stabilize within %v", d.deadline))
81+
}
7782
d.UpdateStatus(details, err)
7883
}
7984

pkg/skaffold/deploy/status_check.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,8 @@ func pollResourceStatus(ctx context.Context, runCtx *runcontext.RunContext, r Re
125125
for {
126126
select {
127127
case <-timeoutContext.Done():
128-
r.UpdateStatus(timeoutContext.Err().Error(), timeoutContext.Err())
128+
err := errors.Wrap(timeoutContext.Err(), fmt.Sprintf("could not stabilize within %v", r.Deadline()))
129+
r.UpdateStatus(err.Error(), err)
129130
return
130131
case <-time.After(pollDuration):
131132
r.CheckStatus(timeoutContext, runCtx)

pkg/skaffold/deploy/status_check_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ package deploy
1919
import (
2020
"bytes"
2121
"context"
22-
"errors"
2322
"testing"
2423
"time"
2524

2625
"github.com/google/go-cmp/cmp"
26+
"github.com/pkg/errors"
2727
appsv1 "k8s.io/api/apps/v1"
2828
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2929
"k8s.io/apimachinery/pkg/runtime"
@@ -208,6 +208,7 @@ type mockResource struct {
208208
}
209209

210210
func (m *mockResource) UpdateStatus(s string, err error) {
211+
err = errors.Cause(err)
211212
if err == context.DeadlineExceeded {
212213
m.inErr = true
213214
}
@@ -244,7 +245,7 @@ func TestPollResourceStatus(t *testing.T) {
244245
testutil.Run(t, test.description, func(t *testutil.T) {
245246
t.Override(&defaultPollPeriodInMilliseconds, 0)
246247
pollResourceStatus(context.Background(), nil, test.dummyResource)
247-
t.CheckDeepEqual(test.dummyResource.inErr, test.isInErr)
248+
t.CheckDeepEqual(test.isInErr, test.dummyResource.inErr)
248249
})
249250
}
250251
}

0 commit comments

Comments
 (0)