Merge pull request #125630 from liggitt/rollback-wait

Revert kubectl wait regression

Kubernetes-commit: da479a82ebb6d4117b69f2c78364c81a513ad511
This commit is contained in:
Kubernetes Publisher 2024-06-21 11:21:01 -07:00
commit 7e6366765e
1 changed files with 13 additions and 54 deletions

View File

@ -82,10 +82,7 @@ var (
# Wait for the pod "busybox1" to be deleted, with a timeout of 60s, after having issued the "delete" command
kubectl delete pod/busybox1
kubectl wait --for=delete pod/busybox1 --timeout=60s
# Wait for the creation of the service "loadbalancer" in addition to wait to have ingress
kubectl wait --for=jsonpath='{.status.loadBalancer.ingress}' service/loadbalancer --wait-for-creation`))
kubectl wait --for=delete pod/busybox1 --timeout=60s`))
)
// errNoMatchingResources is returned when there is no resources matching a query.
@ -101,7 +98,6 @@ type WaitFlags struct {
Timeout time.Duration
ForCondition string
WaitForCreation bool
genericiooptions.IOStreams
}
@ -120,7 +116,6 @@ func NewWaitFlags(restClientGetter genericclioptions.RESTClientGetter, streams g
WithLatest(),
Timeout: 30 * time.Second,
WaitForCreation: true,
IOStreams: streams,
}
@ -157,7 +152,6 @@ func (flags *WaitFlags) AddFlags(cmd *cobra.Command) {
cmd.Flags().DurationVar(&flags.Timeout, "timeout", flags.Timeout, "The length of time to wait before giving up. Zero means check once and don't wait, negative means wait for a week.")
cmd.Flags().StringVar(&flags.ForCondition, "for", flags.ForCondition, "The condition to wait on: [delete|condition=condition-name[=condition-value]|jsonpath='{JSONPath expression}'=[JSONPath value]]. The default condition-value is true. Condition values are compared after Unicode simple case folding, which is a more general form of case-insensitivity.")
cmd.Flags().BoolVar(&flags.WaitForCreation, "wait-for-creation", flags.WaitForCreation, "The default value is true. If set to true, also wait for creation of objects if they do not already exist. This flag is ignored in --for=delete")
}
// ToOptions converts from CLI inputs to runtime inputs
@ -190,7 +184,6 @@ func (flags *WaitFlags) ToOptions(args []string) (*WaitOptions, error) {
DynamicClient: dynamicClient,
Timeout: effectiveTimeout,
ForCondition: flags.ForCondition,
WaitForCreation: flags.WaitForCreation,
Printer: printer,
ConditionFn: conditionFn,
@ -313,7 +306,6 @@ type WaitOptions struct {
DynamicClient dynamic.Interface
Timeout time.Duration
ForCondition string
WaitForCreation bool
Printer printers.ResourcePrinter
ConditionFn ConditionFunc
@ -328,40 +320,6 @@ func (o *WaitOptions) RunWait() error {
ctx, cancel := watchtools.ContextWithOptionalTimeout(context.Background(), o.Timeout)
defer cancel()
isForDelete := strings.ToLower(o.ForCondition) == "delete"
if o.WaitForCreation && o.Timeout == 0 {
return fmt.Errorf("--wait-for-creation requires a timeout value greater than 0")
}
if o.WaitForCreation && !isForDelete {
err := func() error {
for {
select {
case <-ctx.Done():
return fmt.Errorf("context deadline is exceeded while waiting for the creation of the resources")
default:
err := o.ResourceFinder.Do().Visit(func(info *resource.Info, err error) error {
// We don't need to do anything after we assure that the resources exist. Because
// actual logic will be incorporated after we wait all the resources' existence.
return nil
})
// It is verified that all the resources exist.
if err == nil {
return nil
}
// We specifically wait for the creation of resources and all the errors
// other than not found means that this is something we cannot handle.
if !apierrors.IsNotFound(err) {
return err
}
}
}
}()
if err != nil {
return err
}
}
visitCount := 0
visitFunc := func(info *resource.Info, err error) error {
if err != nil {
@ -380,6 +338,7 @@ func (o *WaitOptions) RunWait() error {
return err
}
visitor := o.ResourceFinder.Do()
isForDelete := strings.ToLower(o.ForCondition) == "delete"
if visitor, ok := visitor.(*resource.Result); ok && isForDelete {
visitor.IgnoreErrors(apierrors.IsNotFound)
}