Skip to content

Commit

Permalink
Merge pull request #1520 from vrothberg/bz-2216700
Browse files Browse the repository at this point in the history
layer tree: be more resilient
  • Loading branch information
openshift-merge-robot authored Jun 23, 2023
2 parents 6eebb37 + 97961a6 commit 3273ac8
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions libimage/layer_tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package libimage

import (
"context"
"errors"

"github.com/containers/storage"
ociv1 "github.com/opencontainers/image-spec/specs-go/v1"
Expand Down Expand Up @@ -31,6 +32,9 @@ func (t *layerTree) node(layerID string) *layerNode {
}

// toOCI returns an OCI image for the specified image.
//
// WARNING: callers are responsible for handling cases where the target image
// has been removed and need to check for `storage.ErrImageUnknown`.
func (t *layerTree) toOCI(ctx context.Context, i *Image) (*ociv1.Image, error) {
var err error
oci, exists := t.ociCache[i.ID()]
Expand Down Expand Up @@ -155,6 +159,9 @@ func (t *layerTree) children(ctx context.Context, parent *Image, all bool) ([]*I
parentID := parent.ID()
parentOCI, err := t.toOCI(ctx, parent)
if err != nil {
if errors.Is(err, storage.ErrImageUnknown) {
return nil, nil
}
return nil, err
}

Expand All @@ -165,6 +172,9 @@ func (t *layerTree) children(ctx context.Context, parent *Image, all bool) ([]*I
}
childOCI, err := t.toOCI(ctx, child)
if err != nil {
if errors.Is(err, storage.ErrImageUnknown) {
return false, nil
}
return false, err
}
// History check.
Expand Down Expand Up @@ -255,6 +265,9 @@ func (t *layerTree) parent(ctx context.Context, child *Image) (*Image, error) {
childID := child.ID()
childOCI, err := t.toOCI(ctx, child)
if err != nil {
if errors.Is(err, storage.ErrImageUnknown) {
return nil, nil
}
return nil, err
}

Expand All @@ -268,6 +281,9 @@ func (t *layerTree) parent(ctx context.Context, child *Image) (*Image, error) {
}
emptyOCI, err := t.toOCI(ctx, empty)
if err != nil {
if errors.Is(err, storage.ErrImageUnknown) {
return nil, nil
}
return nil, err
}
// History check.
Expand Down Expand Up @@ -300,6 +316,9 @@ func (t *layerTree) parent(ctx context.Context, child *Image) (*Image, error) {
}
parentOCI, err := t.toOCI(ctx, parent)
if err != nil {
if errors.Is(err, storage.ErrImageUnknown) {
return nil, nil
}
return nil, err
}
// History check.
Expand Down

0 comments on commit 3273ac8

Please sign in to comment.