Skip to content

Commit

Permalink
c8d/push: Retry with a single manifest if no platform requested
Browse files Browse the repository at this point in the history
When no platform was requested and pushing whole index failed, fallback
to pushing a platform-specific manifest with a best candidate (if it's
possible to choose one).

Signed-off-by: Paweł Gronowski <[email protected]>
  • Loading branch information
vvoland committed May 20, 2024
1 parent 4947d72 commit 9e5950a
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions daemon/containerd/image_push.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,12 @@ func (i *ImageService) pushRef(ctx context.Context, targetRef reference.Named, p
return errdefs.NotFound(fmt.Errorf("tag does not exist: %s", reference.FamiliarString(targetRef)))
}

target, err := i.getPushDescriptor(ctx, img, platform)
if err != nil {
return err
target := img.Target
if platform != nil {
target, err = i.getPushDescriptor(ctx, img, platform)
if err != nil {
return err
}
}

store := i.content
Expand Down Expand Up @@ -163,8 +166,19 @@ func (i *ImageService) pushRef(ctx context.Context, targetRef reference.Named, p
}

err = remotes.PushContent(ctx, pusher, target, store, limiter, platforms.All, handlerWrapper)
if err != nil {
if containerdimages.IsIndexType(target.MediaType) && cerrdefs.IsNotFound(err) {
if err != nil && containerdimages.IsIndexType(target.MediaType) {
if cerrdefs.IsNotFound(err) && platform == nil {
// If push failed because of a missing content, no specific platform was requested
// and the target is an index, select a platform-specific manifest to push instead.
target, err = i.getPushDescriptor(ctx, img, nil)
if err != nil {
return err
}

err = remotes.PushContent(ctx, pusher, target, store, limiter, platforms.All, handlerWrapper)
}

if err != nil && cerrdefs.IsNotFound(err) {
return errdefs.NotFound(fmt.Errorf(
"missing content: %w\n"+
"Note: You're trying to push a manifest list/index which "+
Expand Down

0 comments on commit 9e5950a

Please sign in to comment.