@@ -308,41 +308,56 @@ func (r *REST) Update(ctx apirequest.Context, tagName string, objInfo rest.Updat
308
308
309
309
// Delete removes a tag from a stream. `id` is of the format <stream name>:<tag>.
310
310
// The associated image that the tag points to is *not* deleted.
311
- // The tag history remains intact and is not deleted .
311
+ // The tag history is removed .
312
312
func (r * REST ) Delete (ctx apirequest.Context , id string , options * metav1.DeleteOptions ) (runtime.Object , bool , error ) {
313
313
name , tag , err := nameAndTag (id )
314
314
if err != nil {
315
315
return nil , false , err
316
316
}
317
317
318
- stream , err := r .imageStreamRegistry .GetImageStream (ctx , name , & metav1.GetOptions {})
319
- if err != nil {
320
- return nil , false , err
321
- }
318
+ for i := 10 ; i > 0 ; i -- {
319
+ stream , err := r .imageStreamRegistry .GetImageStream (ctx , name , & metav1.GetOptions {})
320
+ if err != nil {
321
+ return nil , false , err
322
+ }
323
+ if options != nil {
324
+ if pre := options .Preconditions ; pre != nil {
325
+ if pre .UID != nil && * pre .UID != stream .UID {
326
+ return nil , false , kapierrors .NewConflict (imageapi .Resource ("imagestreamtags" ), id , fmt .Errorf ("the UID precondition was not met" ))
327
+ }
328
+ }
329
+ }
322
330
323
- notFound := true
331
+ notFound := true
324
332
325
- // Try to delete the status tag
326
- if _ , ok := stream .Status .Tags [tag ]; ok {
327
- delete (stream .Status .Tags , tag )
328
- notFound = false
329
- }
333
+ // Try to delete the status tag
334
+ if _ , ok := stream .Status .Tags [tag ]; ok {
335
+ delete (stream .Status .Tags , tag )
336
+ notFound = false
337
+ }
330
338
331
- // Try to delete the spec tag
332
- if _ , ok := stream .Spec .Tags [tag ]; ok {
333
- delete (stream .Spec .Tags , tag )
334
- notFound = false
335
- }
339
+ // Try to delete the spec tag
340
+ if _ , ok := stream .Spec .Tags [tag ]; ok {
341
+ delete (stream .Spec .Tags , tag )
342
+ notFound = false
343
+ }
336
344
337
- if notFound {
338
- return nil , false , kapierrors .NewNotFound (imageapi .Resource ("imagestreamtags" ), tag )
339
- }
345
+ if notFound {
346
+ return nil , false , kapierrors .NewNotFound (imageapi .Resource ("imagestreamtags" ), id )
347
+ }
340
348
341
- if _ , err = r .imageStreamRegistry .UpdateImageStream (ctx , stream ); err != nil {
342
- return nil , false , fmt .Errorf ("cannot remove tag from image stream: %v" , err )
349
+ _ , err = r .imageStreamRegistry .UpdateImageStream (ctx , stream )
350
+ if kapierrors .IsConflict (err ) {
351
+ continue
352
+ }
353
+ if err != nil && ! kapierrors .IsNotFound (err ) {
354
+ return nil , false , err
355
+ }
356
+ return & metav1.Status {Status : metav1 .StatusSuccess }, true , nil
343
357
}
344
-
345
- return & metav1.Status {Status : metav1 .StatusSuccess }, true , nil
358
+ // We tried to update resource, but we kept conflicting. Inform the client that we couldn't complete
359
+ // the operation but that they may try again.
360
+ return nil , false , kapierrors .NewServerTimeout (imageapi .Resource ("imagestreamtags" ), "delete" , 2 )
346
361
}
347
362
348
363
// imageFor retrieves the most recent image for a tag in a given imageStreem.
0 commit comments