Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added resource name to timeout error output on WAIT cmd #73315

Merged
merged 1 commit into from
Feb 23, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 0 additions & 1 deletion pkg/kubectl/cmd/wait/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ go_test(
"//staging/src/k8s.io/apimachinery/pkg/runtime:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/runtime/schema:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/types:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/util/wait:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/watch:go_default_library",
"//staging/src/k8s.io/cli-runtime/pkg/genericclioptions:go_default_library",
"//staging/src/k8s.io/cli-runtime/pkg/genericclioptions/printers:go_default_library",
Expand Down
18 changes: 12 additions & 6 deletions pkg/kubectl/cmd/wait/wait.go
Original file line number Diff line number Diff line change
Expand Up @@ -292,9 +292,10 @@ func IsDeleted(info *resource.Info, o *WaitOptions) (runtime.Object, bool, error
}

timeout := endTime.Sub(time.Now())
errWaitTimeoutWithName := extendErrWaitTimeout(wait.ErrWaitTimeout, info)
if timeout < 0 {
// we're out of time
return gottenObj, false, wait.ErrWaitTimeout
return gottenObj, false, errWaitTimeoutWithName
}

ctx, cancel := watchtools.ContextWithOptionalTimeout(context.Background(), o.Timeout)
Expand All @@ -307,9 +308,9 @@ func IsDeleted(info *resource.Info, o *WaitOptions) (runtime.Object, bool, error
continue
case err == wait.ErrWaitTimeout:
if watchEvent != nil {
return watchEvent.Object, false, wait.ErrWaitTimeout
return watchEvent.Object, false, errWaitTimeoutWithName
}
return gottenObj, false, wait.ErrWaitTimeout
return gottenObj, false, errWaitTimeoutWithName
default:
return gottenObj, false, err
}
Expand Down Expand Up @@ -386,9 +387,10 @@ func (w ConditionalWait) IsConditionMet(info *resource.Info, o *WaitOptions) (ru
}

timeout := endTime.Sub(time.Now())
errWaitTimeoutWithName := extendErrWaitTimeout(wait.ErrWaitTimeout, info)
if timeout < 0 {
// we're out of time
return gottenObj, false, wait.ErrWaitTimeout
return gottenObj, false, errWaitTimeoutWithName
}

ctx, cancel := watchtools.ContextWithOptionalTimeout(context.Background(), o.Timeout)
Expand All @@ -401,9 +403,9 @@ func (w ConditionalWait) IsConditionMet(info *resource.Info, o *WaitOptions) (ru
continue
case err == wait.ErrWaitTimeout:
if watchEvent != nil {
return watchEvent.Object, false, wait.ErrWaitTimeout
return watchEvent.Object, false, errWaitTimeoutWithName
}
return gottenObj, false, wait.ErrWaitTimeout
return gottenObj, false, errWaitTimeoutWithName
default:
return gottenObj, false, err
}
Expand Down Expand Up @@ -449,3 +451,7 @@ func (w ConditionalWait) isConditionMet(event watch.Event) (bool, error) {
obj := event.Object.(*unstructured.Unstructured)
return w.checkCondition(obj)
}

func extendErrWaitTimeout(err error, info *resource.Info) error {
return fmt.Errorf("%s on %s/%s", err.Error(), info.Mapping.Resource.Resource, info.Name)
}
13 changes: 5 additions & 8 deletions pkg/kubectl/cmd/wait/wait_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,10 @@ package wait

import (
"io/ioutil"
"strings"
"testing"

"time"

"strings"

"github.com/davecgh/go-spew/spew"

"k8s.io/apimachinery/pkg/api/meta"
Expand All @@ -32,7 +30,6 @@ import (
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/wait"
"k8s.io/apimachinery/pkg/watch"
"k8s.io/cli-runtime/pkg/genericclioptions"
"k8s.io/cli-runtime/pkg/genericclioptions/printers"
Expand Down Expand Up @@ -203,7 +200,7 @@ func TestWaitForDeletion(t *testing.T) {
},
timeout: 1 * time.Second,

expectedErr: wait.ErrWaitTimeout.Error(),
expectedErr: "timed out waiting for the condition on theresource/name-foo",
validateActions: func(t *testing.T, actions []clienttesting.Action) {
if len(actions) != 2 {
t.Fatal(spew.Sdump(actions))
Expand Down Expand Up @@ -254,7 +251,7 @@ func TestWaitForDeletion(t *testing.T) {
},
timeout: 3 * time.Second,

expectedErr: wait.ErrWaitTimeout.Error(),
expectedErr: "timed out waiting for the condition on theresource/name-foo",
validateActions: func(t *testing.T, actions []clienttesting.Action) {
if len(actions) != 4 {
t.Fatal(spew.Sdump(actions))
Expand Down Expand Up @@ -502,7 +499,7 @@ func TestWaitForCondition(t *testing.T) {
},
timeout: 1 * time.Second,

expectedErr: wait.ErrWaitTimeout.Error(),
expectedErr: "timed out waiting for the condition on theresource/name-foo",
validateActions: func(t *testing.T, actions []clienttesting.Action) {
if len(actions) != 2 {
t.Fatal(spew.Sdump(actions))
Expand Down Expand Up @@ -553,7 +550,7 @@ func TestWaitForCondition(t *testing.T) {
},
timeout: 3 * time.Second,

expectedErr: wait.ErrWaitTimeout.Error(),
expectedErr: "timed out waiting for the condition on theresource/name-foo",
validateActions: func(t *testing.T, actions []clienttesting.Action) {
if len(actions) != 4 {
t.Fatal(spew.Sdump(actions))
Expand Down