Merge pull request #69196 from CaoShuFeng/job.yaml

fix kubectl wait with no resource name provided
pull/58/head
k8s-ci-robot 2018-11-15 14:59:42 -08:00 committed by GitHub
commit 7cf211d7de
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 0 deletions

View File

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

View File

@ -445,6 +445,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", name: "times out",
infos: []*resource.Info{ infos: []*resource.Info{