mirror of
				https://github.com/optim-enterprises-bv/kubernetes.git
				synced 2025-11-03 19:58:17 +00:00 
			
		
		
		
	Merge pull request #73315 from Zyqsempai/wait-cmd-detailed-output
Added resource name to timeout error output on WAIT cmd
This commit is contained in:
		@@ -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,11 +18,9 @@ package wait
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"io/ioutil"
 | 
			
		||||
	"testing"
 | 
			
		||||
 | 
			
		||||
	"time"
 | 
			
		||||
 | 
			
		||||
	"strings"
 | 
			
		||||
	"testing"
 | 
			
		||||
	"time"
 | 
			
		||||
 | 
			
		||||
	"github.com/davecgh/go-spew/spew"
 | 
			
		||||
 | 
			
		||||
@@ -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))
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user