mirror of https://github.com/k3s-io/k3s
Merge pull request #73315 from Zyqsempai/wait-cmd-detailed-output
Added resource name to timeout error output on WAIT cmdpull/564/head
commit
95e5705faf
|
@ -51,7 +51,6 @@ go_test(
|
||||||
"//staging/src/k8s.io/apimachinery/pkg/runtime:go_default_library",
|
"//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/runtime/schema:go_default_library",
|
||||||
"//staging/src/k8s.io/apimachinery/pkg/types: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/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:go_default_library",
|
||||||
"//staging/src/k8s.io/cli-runtime/pkg/genericclioptions/printers: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())
|
timeout := endTime.Sub(time.Now())
|
||||||
|
errWaitTimeoutWithName := extendErrWaitTimeout(wait.ErrWaitTimeout, info)
|
||||||
if timeout < 0 {
|
if timeout < 0 {
|
||||||
// we're out of time
|
// we're out of time
|
||||||
return gottenObj, false, wait.ErrWaitTimeout
|
return gottenObj, false, errWaitTimeoutWithName
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx, cancel := watchtools.ContextWithOptionalTimeout(context.Background(), o.Timeout)
|
ctx, cancel := watchtools.ContextWithOptionalTimeout(context.Background(), o.Timeout)
|
||||||
|
@ -310,9 +311,9 @@ func IsDeleted(info *resource.Info, o *WaitOptions) (runtime.Object, bool, error
|
||||||
continue
|
continue
|
||||||
case err == wait.ErrWaitTimeout:
|
case err == wait.ErrWaitTimeout:
|
||||||
if watchEvent != nil {
|
if watchEvent != nil {
|
||||||
return watchEvent.Object, false, wait.ErrWaitTimeout
|
return watchEvent.Object, false, errWaitTimeoutWithName
|
||||||
}
|
}
|
||||||
return gottenObj, false, wait.ErrWaitTimeout
|
return gottenObj, false, errWaitTimeoutWithName
|
||||||
default:
|
default:
|
||||||
return gottenObj, false, err
|
return gottenObj, false, err
|
||||||
}
|
}
|
||||||
|
@ -389,9 +390,10 @@ func (w ConditionalWait) IsConditionMet(info *resource.Info, o *WaitOptions) (ru
|
||||||
}
|
}
|
||||||
|
|
||||||
timeout := endTime.Sub(time.Now())
|
timeout := endTime.Sub(time.Now())
|
||||||
|
errWaitTimeoutWithName := extendErrWaitTimeout(wait.ErrWaitTimeout, info)
|
||||||
if timeout < 0 {
|
if timeout < 0 {
|
||||||
// we're out of time
|
// we're out of time
|
||||||
return gottenObj, false, wait.ErrWaitTimeout
|
return gottenObj, false, errWaitTimeoutWithName
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx, cancel := watchtools.ContextWithOptionalTimeout(context.Background(), o.Timeout)
|
ctx, cancel := watchtools.ContextWithOptionalTimeout(context.Background(), o.Timeout)
|
||||||
|
@ -404,9 +406,9 @@ func (w ConditionalWait) IsConditionMet(info *resource.Info, o *WaitOptions) (ru
|
||||||
continue
|
continue
|
||||||
case err == wait.ErrWaitTimeout:
|
case err == wait.ErrWaitTimeout:
|
||||||
if watchEvent != nil {
|
if watchEvent != nil {
|
||||||
return watchEvent.Object, false, wait.ErrWaitTimeout
|
return watchEvent.Object, false, errWaitTimeoutWithName
|
||||||
}
|
}
|
||||||
return gottenObj, false, wait.ErrWaitTimeout
|
return gottenObj, false, errWaitTimeoutWithName
|
||||||
default:
|
default:
|
||||||
return gottenObj, false, err
|
return gottenObj, false, err
|
||||||
}
|
}
|
||||||
|
@ -452,3 +454,7 @@ func (w ConditionalWait) isConditionMet(event watch.Event) (bool, error) {
|
||||||
obj := event.Object.(*unstructured.Unstructured)
|
obj := event.Object.(*unstructured.Unstructured)
|
||||||
return w.checkCondition(obj)
|
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,11 +18,9 @@ package wait
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"testing"
|
|
||||||
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"strings"
|
"strings"
|
||||||
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/davecgh/go-spew/spew"
|
"github.com/davecgh/go-spew/spew"
|
||||||
|
|
||||||
|
@ -32,7 +30,6 @@ import (
|
||||||
"k8s.io/apimachinery/pkg/runtime"
|
"k8s.io/apimachinery/pkg/runtime"
|
||||||
"k8s.io/apimachinery/pkg/runtime/schema"
|
"k8s.io/apimachinery/pkg/runtime/schema"
|
||||||
"k8s.io/apimachinery/pkg/types"
|
"k8s.io/apimachinery/pkg/types"
|
||||||
"k8s.io/apimachinery/pkg/util/wait"
|
|
||||||
"k8s.io/apimachinery/pkg/watch"
|
"k8s.io/apimachinery/pkg/watch"
|
||||||
"k8s.io/cli-runtime/pkg/genericclioptions"
|
"k8s.io/cli-runtime/pkg/genericclioptions"
|
||||||
"k8s.io/cli-runtime/pkg/genericclioptions/printers"
|
"k8s.io/cli-runtime/pkg/genericclioptions/printers"
|
||||||
|
@ -203,7 +200,7 @@ func TestWaitForDeletion(t *testing.T) {
|
||||||
},
|
},
|
||||||
timeout: 1 * time.Second,
|
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) {
|
validateActions: func(t *testing.T, actions []clienttesting.Action) {
|
||||||
if len(actions) != 2 {
|
if len(actions) != 2 {
|
||||||
t.Fatal(spew.Sdump(actions))
|
t.Fatal(spew.Sdump(actions))
|
||||||
|
@ -254,7 +251,7 @@ func TestWaitForDeletion(t *testing.T) {
|
||||||
},
|
},
|
||||||
timeout: 3 * time.Second,
|
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) {
|
validateActions: func(t *testing.T, actions []clienttesting.Action) {
|
||||||
if len(actions) != 4 {
|
if len(actions) != 4 {
|
||||||
t.Fatal(spew.Sdump(actions))
|
t.Fatal(spew.Sdump(actions))
|
||||||
|
@ -554,7 +551,7 @@ func TestWaitForCondition(t *testing.T) {
|
||||||
},
|
},
|
||||||
timeout: 1 * time.Second,
|
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) {
|
validateActions: func(t *testing.T, actions []clienttesting.Action) {
|
||||||
if len(actions) != 2 {
|
if len(actions) != 2 {
|
||||||
t.Fatal(spew.Sdump(actions))
|
t.Fatal(spew.Sdump(actions))
|
||||||
|
@ -605,7 +602,7 @@ func TestWaitForCondition(t *testing.T) {
|
||||||
},
|
},
|
||||||
timeout: 3 * time.Second,
|
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) {
|
validateActions: func(t *testing.T, actions []clienttesting.Action) {
|
||||||
if len(actions) != 4 {
|
if len(actions) != 4 {
|
||||||
t.Fatal(spew.Sdump(actions))
|
t.Fatal(spew.Sdump(actions))
|
||||||
|
|
Loading…
Reference in New Issue