fix kubectl wait with no resource name provided

pull/58/head
Cao Shufeng 2018-09-28 12:03:11 +08:00
parent c79ad5a65b
commit e187e6d310
2 changed files with 28 additions and 0 deletions

View File

@ -242,6 +242,9 @@ func (o *WaitOptions) RunWait() error {
func IsDeleted(info *resource.Info, o *WaitOptions) (runtime.Object, bool, error) {
endTime := time.Now().Add(o.Timeout)
for {
if len(info.Name) == 0 {
return info.Object, false, fmt.Errorf("resource name must be provided")
}
gottenObj, err := o.DynamicClient.Resource(info.Mapping.Resource).Namespace(info.Namespace).Get(info.Name, metav1.GetOptions{})
if apierrors.IsNotFound(err) {
return info.Object, true, nil
@ -308,6 +311,9 @@ type ConditionalWait struct {
func (w ConditionalWait) IsConditionMet(info *resource.Info, o *WaitOptions) (runtime.Object, bool, error) {
endTime := time.Now().Add(o.Timeout)
for {
if len(info.Name) == 0 {
return info.Object, false, fmt.Errorf("resource name must be provided")
}
resourceVersion := ""
gottenObj, err := o.DynamicClient.Resource(info.Mapping.Resource).Namespace(info.Namespace).Get(info.Name, metav1.GetOptions{})
switch {

View File

@ -378,6 +378,28 @@ func TestWaitForCondition(t *testing.T) {
}
},
},
{
name: "handles empty object name",
infos: []*resource.Info{
{
Mapping: &meta.RESTMapping{
Resource: schema.GroupVersionResource{Group: "group", Version: "version", Resource: "theresource"},
},
Namespace: "ns-foo",
},
},
fakeClient: func() *dynamicfakeclient.FakeDynamicClient {
return dynamicfakeclient.NewSimpleDynamicClient(scheme)
},
timeout: 10 * time.Second,
expectedErr: "resource name must be provided",
validateActions: func(t *testing.T, actions []clienttesting.Action) {
if len(actions) != 0 {
t.Fatal(spew.Sdump(actions))
}
},
},
{
name: "times out",
infos: []*resource.Info{