Unverified Commit 95e5705f authored by Kubernetes Prow Robot's avatar Kubernetes Prow Robot Committed by GitHub

Merge pull request #73315 from Zyqsempai/wait-cmd-detailed-output

Added resource name to timeout error output on WAIT cmd
parents 2f294573 892f15d9
......@@ -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",
......
......@@ -295,9 +295,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)
......@@ -310,9 +311,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
}
......@@ -389,9 +390,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)
......@@ -404,9 +406,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
}
......@@ -452,3 +454,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)
}
......@@ -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"
......@@ -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"
......@@ -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))
......@@ -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))
......@@ -554,7 +551,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))
......@@ -605,7 +602,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))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment