Skip to content

Commit f3ca235

Browse files
Merge pull request #19534 from smarterclayton/retry_delete
Allow imagestreamtag delete to retry conflicts
2 parents 6170b3d + 1d56b84 commit f3ca235

File tree

1 file changed

+38
-23
lines changed
  • pkg/image/registry/imagestreamtag

1 file changed

+38
-23
lines changed

pkg/image/registry/imagestreamtag/rest.go

+38-23
Original file line numberDiff line numberDiff line change
@@ -308,41 +308,56 @@ func (r *REST) Update(ctx apirequest.Context, tagName string, objInfo rest.Updat
308308

309309
// Delete removes a tag from a stream. `id` is of the format <stream name>:<tag>.
310310
// 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.
312312
func (r *REST) Delete(ctx apirequest.Context, id string, options *metav1.DeleteOptions) (runtime.Object, bool, error) {
313313
name, tag, err := nameAndTag(id)
314314
if err != nil {
315315
return nil, false, err
316316
}
317317

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+
}
322330

323-
notFound := true
331+
notFound := true
324332

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+
}
330338

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+
}
336344

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+
}
340348

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
343357
}
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)
346361
}
347362

348363
// imageFor retrieves the most recent image for a tag in a given imageStreem.

0 commit comments

Comments
 (0)