mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-19 18:02:01 +00:00
Merge pull request #90969 from zhouya0/kubectl_wait_add_ignore_not_found
Ignore not found in `kubectl wait --for=delete`
This commit is contained in:
commit
3d52b8b5d6
@ -165,6 +165,7 @@ func (flags *WaitFlags) ToOptions(args []string) (*WaitOptions, error) {
|
||||
ResourceFinder: builder,
|
||||
DynamicClient: dynamicClient,
|
||||
Timeout: effectiveTimeout,
|
||||
ForCondition: flags.ForCondition,
|
||||
|
||||
Printer: printer,
|
||||
ConditionFn: conditionFn,
|
||||
@ -215,6 +216,7 @@ type WaitOptions struct {
|
||||
UIDMap UIDMap
|
||||
DynamicClient dynamic.Interface
|
||||
Timeout time.Duration
|
||||
ForCondition string
|
||||
|
||||
Printer printers.ResourcePrinter
|
||||
ConditionFn ConditionFunc
|
||||
@ -227,7 +229,7 @@ type ConditionFunc func(info *resource.Info, o *WaitOptions) (finalObject runtim
|
||||
// RunWait runs the waiting logic
|
||||
func (o *WaitOptions) RunWait() error {
|
||||
visitCount := 0
|
||||
err := o.ResourceFinder.Do().Visit(func(info *resource.Info, err error) error {
|
||||
visitFunc := func(info *resource.Info, err error) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -242,7 +244,13 @@ func (o *WaitOptions) RunWait() error {
|
||||
return fmt.Errorf("%v unsatisified for unknown reason", finalObject)
|
||||
}
|
||||
return err
|
||||
})
|
||||
}
|
||||
visitor := o.ResourceFinder.Do()
|
||||
if visitor, ok := visitor.(*resource.Result); ok && strings.ToLower(o.ForCondition) == "delete" {
|
||||
visitor.IgnoreErrors(apierrors.IsNotFound)
|
||||
}
|
||||
|
||||
err := visitor.Visit(visitFunc)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -787,3 +787,30 @@ func TestWaitForCondition(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestWaitForDeletionIgnoreNotFound(t *testing.T) {
|
||||
scheme := runtime.NewScheme()
|
||||
infos := []*resource.Info{
|
||||
{
|
||||
Mapping: &meta.RESTMapping{
|
||||
Resource: schema.GroupVersionResource{Group: "group", Version: "version", Resource: "theresource"},
|
||||
},
|
||||
Name: "name-foo",
|
||||
Namespace: "ns-foo",
|
||||
},
|
||||
}
|
||||
fakeClient := dynamicfakeclient.NewSimpleDynamicClient(scheme)
|
||||
|
||||
o := &WaitOptions{
|
||||
ResourceFinder: genericclioptions.NewSimpleFakeResourceFinder(infos...),
|
||||
DynamicClient: fakeClient,
|
||||
Printer: printers.NewDiscardingPrinter(),
|
||||
ConditionFn: IsDeleted,
|
||||
IOStreams: genericclioptions.NewTestIOStreamsDiscard(),
|
||||
ForCondition: "delete",
|
||||
}
|
||||
err := o.RunWait()
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error: %v", err)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user