82
82
83
83
# Wait for the pod "busybox1" to be deleted, with a timeout of 60s, after having issued the "delete" command
84
84
kubectl delete pod/busybox1
85
- kubectl wait --for=delete pod/busybox1 --timeout=60s
86
-
87
- # Wait for the creation of the service "loadbalancer" in addition to wait to have ingress
88
- kubectl wait --for=jsonpath='{.status.loadBalancer.ingress}' service/loadbalancer --wait-for-creation` ))
85
+ kubectl wait --for=delete pod/busybox1 --timeout=60s` ))
89
86
)
90
87
91
88
// errNoMatchingResources is returned when there is no resources matching a query.
@@ -99,9 +96,8 @@ type WaitFlags struct {
99
96
PrintFlags * genericclioptions.PrintFlags
100
97
ResourceBuilderFlags * genericclioptions.ResourceBuilderFlags
101
98
102
- Timeout time.Duration
103
- ForCondition string
104
- WaitForCreation bool
99
+ Timeout time.Duration
100
+ ForCondition string
105
101
106
102
genericiooptions.IOStreams
107
103
}
@@ -119,8 +115,7 @@ func NewWaitFlags(restClientGetter genericclioptions.RESTClientGetter, streams g
119
115
WithLocal (false ).
120
116
WithLatest (),
121
117
122
- Timeout : 30 * time .Second ,
123
- WaitForCreation : true ,
118
+ Timeout : 30 * time .Second ,
124
119
125
120
IOStreams : streams ,
126
121
}
@@ -157,7 +152,6 @@ func (flags *WaitFlags) AddFlags(cmd *cobra.Command) {
157
152
158
153
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." )
159
154
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." )
160
- 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" )
161
155
}
162
156
163
157
// ToOptions converts from CLI inputs to runtime inputs
@@ -186,11 +180,10 @@ func (flags *WaitFlags) ToOptions(args []string) (*WaitOptions, error) {
186
180
}
187
181
188
182
o := & WaitOptions {
189
- ResourceFinder : builder ,
190
- DynamicClient : dynamicClient ,
191
- Timeout : effectiveTimeout ,
192
- ForCondition : flags .ForCondition ,
193
- WaitForCreation : flags .WaitForCreation ,
183
+ ResourceFinder : builder ,
184
+ DynamicClient : dynamicClient ,
185
+ Timeout : effectiveTimeout ,
186
+ ForCondition : flags .ForCondition ,
194
187
195
188
Printer : printer ,
196
189
ConditionFn : conditionFn ,
@@ -309,11 +302,10 @@ type WaitOptions struct {
309
302
ResourceFinder genericclioptions.ResourceFinder
310
303
// UIDMap maps a resource location to a UID. It is optional, but ConditionFuncs may choose to use it to make the result
311
304
// more reliable. For instance, delete can look for UID consistency during delegated calls.
312
- UIDMap UIDMap
313
- DynamicClient dynamic.Interface
314
- Timeout time.Duration
315
- ForCondition string
316
- WaitForCreation bool
305
+ UIDMap UIDMap
306
+ DynamicClient dynamic.Interface
307
+ Timeout time.Duration
308
+ ForCondition string
317
309
318
310
Printer printers.ResourcePrinter
319
311
ConditionFn ConditionFunc
@@ -328,40 +320,6 @@ func (o *WaitOptions) RunWait() error {
328
320
ctx , cancel := watchtools .ContextWithOptionalTimeout (context .Background (), o .Timeout )
329
321
defer cancel ()
330
322
331
- isForDelete := strings .ToLower (o .ForCondition ) == "delete"
332
- if o .WaitForCreation && o .Timeout == 0 {
333
- return fmt .Errorf ("--wait-for-creation requires a timeout value greater than 0" )
334
- }
335
-
336
- if o .WaitForCreation && ! isForDelete {
337
- err := func () error {
338
- for {
339
- select {
340
- case <- ctx .Done ():
341
- return fmt .Errorf ("context deadline is exceeded while waiting for the creation of the resources" )
342
- default :
343
- err := o .ResourceFinder .Do ().Visit (func (info * resource.Info , err error ) error {
344
- // We don't need to do anything after we assure that the resources exist. Because
345
- // actual logic will be incorporated after we wait all the resources' existence.
346
- return nil
347
- })
348
- // It is verified that all the resources exist.
349
- if err == nil {
350
- return nil
351
- }
352
- // We specifically wait for the creation of resources and all the errors
353
- // other than not found means that this is something we cannot handle.
354
- if ! apierrors .IsNotFound (err ) {
355
- return err
356
- }
357
- }
358
- }
359
- }()
360
- if err != nil {
361
- return err
362
- }
363
- }
364
-
365
323
visitCount := 0
366
324
visitFunc := func (info * resource.Info , err error ) error {
367
325
if err != nil {
@@ -380,6 +338,7 @@ func (o *WaitOptions) RunWait() error {
380
338
return err
381
339
}
382
340
visitor := o .ResourceFinder .Do ()
341
+ isForDelete := strings .ToLower (o .ForCondition ) == "delete"
383
342
if visitor , ok := visitor .(* resource.Result ); ok && isForDelete {
384
343
visitor .IgnoreErrors (apierrors .IsNotFound )
385
344
}
0 commit comments