Merge pull request #96702 from lingsamuel/wait-for-delete-ignore-not-found

Fix `kubectl wait --for=delete` ignore not found
This commit is contained in:
Kubernetes Prow Robot 2021-05-07 20:29:17 -07:00 committed by GitHub
commit c05810cc5d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 11 deletions

View File

@ -249,7 +249,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)
}
@ -257,7 +258,7 @@ func (o *WaitOptions) RunWait() error {
if err != nil {
return err
}
if visitCount == 0 {
if visitCount == 0 && !isForDelete {
return errNoMatchingResources
}
return err

View File

@ -985,15 +985,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

@ -1831,6 +1831,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.