fix kubectl wait --for=delete ignore not found

Signed-off-by: Ling Samuel <lingsamuelgrace@gmail.com>
This commit is contained in:
Ling Samuel 2020-11-19 14:48:28 +08:00
parent d20e3246ba
commit 99cdc37e2a
No known key found for this signature in database
GPG Key ID: 1405A670863B367F
3 changed files with 12 additions and 11 deletions

View File

@ -247,7 +247,8 @@ func (o *WaitOptions) RunWait() error {
return err
}
visitor := o.ResourceFinder.Do()
if visitor, ok := visitor.(*resource.Result); ok && strings.ToLower(o.ForCondition) == "delete" {
isForDelete := strings.ToLower(o.ForCondition) == "delete"
if visitor, ok := visitor.(*resource.Result); ok && isForDelete {
visitor.IgnoreErrors(apierrors.IsNotFound)
}
@ -255,7 +256,7 @@ func (o *WaitOptions) RunWait() error {
if err != nil {
return err
}
if visitCount == 0 {
if visitCount == 0 && !isForDelete {
return errNoMatchingResources
}
return err

View File

@ -801,15 +801,7 @@ func TestWaitForDeletionIgnoreNotFound(t *testing.T) {
listMapping := map[schema.GroupVersionResource]string{
{Group: "group", Version: "version", Resource: "theresource"}: "TheKindList",
}
infos := []*resource.Info{
{
Mapping: &meta.RESTMapping{
Resource: schema.GroupVersionResource{Group: "group", Version: "version", Resource: "theresource"},
},
Name: "name-foo",
Namespace: "ns-foo",
},
}
infos := []*resource.Info{}
fakeClient := dynamicfakeclient.NewSimpleDynamicClientWithCustomListKinds(scheme, listMapping)
o := &WaitOptions{

View File

@ -1827,6 +1827,14 @@ metadata:
}
})
})
ginkgo.Describe("kubectl wait", func() {
ginkgo.It("should ignore not found error with --for=delete", func() {
ginkgo.By("calling kubectl wait --for=delete")
framework.RunKubectlOrDie(ns, "wait", "--for=delete", "pod/doesnotexist")
framework.RunKubectlOrDie(ns, "wait", "--for=delete", "pod", "--selector=app.kubernetes.io/name=noexist")
})
})
})
// Checks whether the output split by line contains the required elements.