diff options
Diffstat (limited to 'libpod/image')
-rw-r--r-- | libpod/image/docker_registry_options.go | 2 | ||||
-rw-r--r-- | libpod/image/errors.go | 2 | ||||
-rw-r--r-- | libpod/image/filters.go | 2 | ||||
-rw-r--r-- | libpod/image/image.go | 19 | ||||
-rw-r--r-- | libpod/image/image_test.go | 13 | ||||
-rw-r--r-- | libpod/image/layer_tree.go | 23 | ||||
-rw-r--r-- | libpod/image/prune.go | 8 | ||||
-rw-r--r-- | libpod/image/pull.go | 19 | ||||
-rw-r--r-- | libpod/image/search.go | 2 | ||||
-rw-r--r-- | libpod/image/utils.go | 6 |
10 files changed, 55 insertions, 41 deletions
diff --git a/libpod/image/docker_registry_options.go b/libpod/image/docker_registry_options.go index 835473a1f..0a2a375ae 100644 --- a/libpod/image/docker_registry_options.go +++ b/libpod/image/docker_registry_options.go @@ -6,7 +6,7 @@ import ( "github.com/containers/buildah/pkg/parse" "github.com/containers/image/v5/docker/reference" "github.com/containers/image/v5/types" - podmanVersion "github.com/containers/podman/v2/version" + podmanVersion "github.com/containers/podman/v3/version" ) // DockerRegistryOptions encapsulates settings that affect how we connect or diff --git a/libpod/image/errors.go b/libpod/image/errors.go index 3f58b1c6a..49f841bf4 100644 --- a/libpod/image/errors.go +++ b/libpod/image/errors.go @@ -1,7 +1,7 @@ package image import ( - "github.com/containers/podman/v2/libpod/define" + "github.com/containers/podman/v3/libpod/define" ) var ( diff --git a/libpod/image/filters.go b/libpod/image/filters.go index 4aff0a7b5..37d3cb6a5 100644 --- a/libpod/image/filters.go +++ b/libpod/image/filters.go @@ -8,7 +8,7 @@ import ( "strings" "time" - "github.com/containers/podman/v2/pkg/inspect" + "github.com/containers/podman/v3/pkg/inspect" "github.com/pkg/errors" "github.com/sirupsen/logrus" ) diff --git a/libpod/image/image.go b/libpod/image/image.go index d732aecfe..265178ad5 100644 --- a/libpod/image/image.go +++ b/libpod/image/image.go @@ -29,12 +29,12 @@ import ( "github.com/containers/image/v5/transports" "github.com/containers/image/v5/transports/alltransports" "github.com/containers/image/v5/types" - "github.com/containers/podman/v2/libpod/define" - "github.com/containers/podman/v2/libpod/driver" - "github.com/containers/podman/v2/libpod/events" - "github.com/containers/podman/v2/pkg/inspect" - "github.com/containers/podman/v2/pkg/registries" - "github.com/containers/podman/v2/pkg/util" + "github.com/containers/podman/v3/libpod/define" + "github.com/containers/podman/v3/libpod/driver" + "github.com/containers/podman/v3/libpod/events" + "github.com/containers/podman/v3/pkg/inspect" + "github.com/containers/podman/v3/pkg/registries" + "github.com/containers/podman/v3/pkg/util" "github.com/containers/storage" digest "github.com/opencontainers/go-digest" ociv1 "github.com/opencontainers/image-spec/specs-go/v1" @@ -143,7 +143,7 @@ func (ir *Runtime) NewFromLocal(name string) (*Image, error) { // New creates a new image object where the image could be local // or remote -func (ir *Runtime) New(ctx context.Context, name, signaturePolicyPath, authfile string, writer io.Writer, dockeroptions *DockerRegistryOptions, signingoptions SigningOptions, label *string, pullType util.PullType) (*Image, error) { +func (ir *Runtime) New(ctx context.Context, name, signaturePolicyPath, authfile string, writer io.Writer, dockeroptions *DockerRegistryOptions, signingoptions SigningOptions, label *string, pullType util.PullType, progress chan types.ProgressProperties) (*Image, error) { span, _ := opentracing.StartSpanFromContext(ctx, "newImage") span.SetTag("type", "runtime") defer span.Finish() @@ -162,7 +162,7 @@ func (ir *Runtime) New(ctx context.Context, name, signaturePolicyPath, authfile if signaturePolicyPath == "" { signaturePolicyPath = ir.SignaturePolicyPath } - imageName, err := ir.pullImageFromHeuristicSource(ctx, name, writer, authfile, signaturePolicyPath, signingoptions, dockeroptions, &retry.RetryOptions{MaxRetry: maxRetry}, label) + imageName, err := ir.pullImageFromHeuristicSource(ctx, name, writer, authfile, signaturePolicyPath, signingoptions, dockeroptions, &retry.RetryOptions{MaxRetry: maxRetry}, label, progress) if err != nil { return nil, err } @@ -323,7 +323,7 @@ func (ir *Runtime) LoadAllImagesFromDockerArchive(ctx context.Context, fileName } defer goal.cleanUp() - imageNames, err := ir.doPullImage(ctx, sc, goal, writer, SigningOptions{}, &DockerRegistryOptions{}, &retry.RetryOptions{}, nil) + imageNames, err := ir.doPullImage(ctx, sc, goal, writer, SigningOptions{}, &DockerRegistryOptions{}, &retry.RetryOptions{}, nil, nil) if err != nil { return nil, err } @@ -1688,7 +1688,6 @@ func (i *Image) GetConfigBlob(ctx context.Context) (*manifest.Schema2Image, erro return nil, errors.Wrapf(err, "unable to parse image blob for %s", i.ID()) } return &blob, nil - } // GetHealthCheck returns a HealthConfig for an image. This function only works with diff --git a/libpod/image/image_test.go b/libpod/image/image_test.go index 2704b8baf..3e6e7b9db 100644 --- a/libpod/image/image_test.go +++ b/libpod/image/image_test.go @@ -7,8 +7,8 @@ import ( "os" "testing" - "github.com/containers/podman/v2/libpod/events" - "github.com/containers/podman/v2/pkg/util" + "github.com/containers/podman/v3/libpod/events" + "github.com/containers/podman/v3/pkg/util" "github.com/containers/storage" "github.com/containers/storage/pkg/reexec" "github.com/opencontainers/go-digest" @@ -66,7 +66,6 @@ func makeLocalMatrix(b, bg *Image) []localImageTest { l = append(l, busybox, busyboxGlibc) return l - } func TestMain(m *testing.M) { @@ -95,9 +94,9 @@ func TestImage_NewFromLocal(t *testing.T) { ir, err := NewImageRuntimeFromOptions(so) assert.NoError(t, err) ir.Eventer = events.NewNullEventer() - bb, err := ir.New(context.Background(), "docker.io/library/busybox:latest", "", "", writer, nil, SigningOptions{}, nil, util.PullImageMissing) + bb, err := ir.New(context.Background(), "docker.io/library/busybox:latest", "", "", writer, nil, SigningOptions{}, nil, util.PullImageMissing, nil) assert.NoError(t, err) - bbglibc, err := ir.New(context.Background(), "docker.io/library/busybox:glibc", "", "", writer, nil, SigningOptions{}, nil, util.PullImageMissing) + bbglibc, err := ir.New(context.Background(), "docker.io/library/busybox:glibc", "", "", writer, nil, SigningOptions{}, nil, util.PullImageMissing, nil) assert.NoError(t, err) tm := makeLocalMatrix(bb, bbglibc) @@ -141,7 +140,7 @@ func TestImage_New(t *testing.T) { // Iterate over the names and delete the image // after the pull for _, img := range names { - newImage, err := ir.New(context.Background(), img, "", "", writer, nil, SigningOptions{}, nil, util.PullImageMissing) + newImage, err := ir.New(context.Background(), img, "", "", writer, nil, SigningOptions{}, nil, util.PullImageMissing, nil) assert.NoError(t, err) assert.NotEqual(t, newImage.ID(), "") err = newImage.Remove(context.Background(), false) @@ -170,7 +169,7 @@ func TestImage_MatchRepoTag(t *testing.T) { ir, err := NewImageRuntimeFromOptions(so) assert.NoError(t, err) ir.Eventer = events.NewNullEventer() - newImage, err := ir.New(context.Background(), "busybox", "", "", os.Stdout, nil, SigningOptions{}, nil, util.PullImageMissing) + newImage, err := ir.New(context.Background(), "busybox", "", "", os.Stdout, nil, SigningOptions{}, nil, util.PullImageMissing, nil) assert.NoError(t, err) err = newImage.TagImage("foo:latest") assert.NoError(t, err) diff --git a/libpod/image/layer_tree.go b/libpod/image/layer_tree.go index 18101575e..aa3084449 100644 --- a/libpod/image/layer_tree.go +++ b/libpod/image/layer_tree.go @@ -4,7 +4,7 @@ import ( "context" ociv1 "github.com/opencontainers/image-spec/specs-go/v1" - "github.com/pkg/errors" + "github.com/sirupsen/logrus" ) // layerTree is an internal representation of local layers. @@ -84,7 +84,12 @@ func (ir *Runtime) layerTree() (*layerTree, error) { } node, exists := tree.nodes[topLayer] if !exists { - return nil, errors.Errorf("top layer %s of image %s not found in layer tree", img.TopLayer(), img.ID()) + // Note: erroring out in this case has turned out having been a + // mistake. Users may not be able to recover, so we're now + // throwing a warning to guide them to resolve the issue and + // turn the errors non-fatal. + logrus.Warnf("Top layer %s of image %s not found in layer tree. The storage may be corrupted, consider running `podman system reset`.", topLayer, img.ID()) + continue } node.images = append(node.images, img) } @@ -107,7 +112,12 @@ func (t *layerTree) children(ctx context.Context, parent *Image, all bool) ([]st parentNode, exists := t.nodes[parent.TopLayer()] if !exists { - return nil, errors.Errorf("layer not found in layer tree: %q", parent.TopLayer()) + // Note: erroring out in this case has turned out having been a + // mistake. Users may not be able to recover, so we're now + // throwing a warning to guide them to resolve the issue and + // turn the errors non-fatal. + logrus.Warnf("Layer %s not found in layer. The storage may be corrupted, consider running `podman system reset`.", parent.TopLayer()) + return children, nil } parentID := parent.ID() @@ -177,7 +187,12 @@ func (t *layerTree) parent(ctx context.Context, child *Image) (*Image, error) { node, exists := t.nodes[child.TopLayer()] if !exists { - return nil, errors.Errorf("layer not found in layer tree: %q", child.TopLayer()) + // Note: erroring out in this case has turned out having been a + // mistake. Users may not be able to recover, so we're now + // throwing a warning to guide them to resolve the issue and + // turn the errors non-fatal. + logrus.Warnf("Layer %s not found in layer. The storage may be corrupted, consider running `podman system reset`.", child.TopLayer()) + return nil, nil } childOCI, err := t.toOCI(ctx, child) diff --git a/libpod/image/prune.go b/libpod/image/prune.go index 587c99333..d6ae5feaf 100644 --- a/libpod/image/prune.go +++ b/libpod/image/prune.go @@ -5,9 +5,9 @@ import ( "strings" "time" - "github.com/containers/podman/v2/libpod/events" - "github.com/containers/podman/v2/pkg/domain/entities/reports" - "github.com/containers/podman/v2/pkg/timetype" + "github.com/containers/podman/v3/libpod/events" + "github.com/containers/podman/v3/pkg/domain/entities/reports" + "github.com/containers/podman/v3/pkg/timetype" "github.com/containers/storage" "github.com/pkg/errors" "github.com/sirupsen/logrus" @@ -52,7 +52,6 @@ func generatePruneFilterFuncs(filter, filterValue string) (ImageFilter, error) { } return false }, nil - } return nil, nil } @@ -170,7 +169,6 @@ func (ir *Runtime) PruneImages(ctx context.Context, all bool, filter []string) ( Size: uint64(imgSize), }) } - } return preports, nil } diff --git a/libpod/image/pull.go b/libpod/image/pull.go index 996b5995a..c5fafc25d 100644 --- a/libpod/image/pull.go +++ b/libpod/image/pull.go @@ -6,6 +6,7 @@ import ( "io" "path/filepath" "strings" + "time" "github.com/containers/common/pkg/retry" cp "github.com/containers/image/v5/copy" @@ -19,9 +20,9 @@ import ( "github.com/containers/image/v5/transports" "github.com/containers/image/v5/transports/alltransports" "github.com/containers/image/v5/types" - "github.com/containers/podman/v2/libpod/events" - "github.com/containers/podman/v2/pkg/errorhandling" - "github.com/containers/podman/v2/pkg/registries" + "github.com/containers/podman/v3/libpod/events" + "github.com/containers/podman/v3/pkg/errorhandling" + "github.com/containers/podman/v3/pkg/registries" "github.com/opentracing/opentracing-go" "github.com/pkg/errors" "github.com/sirupsen/logrus" @@ -241,7 +242,7 @@ func toLocalImageName(imageName string) string { // pullImageFromHeuristicSource pulls an image based on inputName, which is heuristically parsed and may involve configured registries. // Use pullImageFromReference if the source is known precisely. -func (ir *Runtime) pullImageFromHeuristicSource(ctx context.Context, inputName string, writer io.Writer, authfile, signaturePolicyPath string, signingOptions SigningOptions, dockerOptions *DockerRegistryOptions, retryOptions *retry.RetryOptions, label *string) ([]string, error) { +func (ir *Runtime) pullImageFromHeuristicSource(ctx context.Context, inputName string, writer io.Writer, authfile, signaturePolicyPath string, signingOptions SigningOptions, dockerOptions *DockerRegistryOptions, retryOptions *retry.RetryOptions, label *string, progress chan types.ProgressProperties) ([]string, error) { span, _ := opentracing.StartSpanFromContext(ctx, "pullImageFromHeuristicSource") defer span.Finish() @@ -275,7 +276,7 @@ func (ir *Runtime) pullImageFromHeuristicSource(ctx context.Context, inputName s } } defer goal.cleanUp() - return ir.doPullImage(ctx, sc, *goal, writer, signingOptions, dockerOptions, retryOptions, label) + return ir.doPullImage(ctx, sc, *goal, writer, signingOptions, dockerOptions, retryOptions, label, progress) } // pullImageFromReference pulls an image from a types.imageReference. @@ -294,7 +295,7 @@ func (ir *Runtime) pullImageFromReference(ctx context.Context, srcRef types.Imag return nil, errors.Wrapf(err, "error determining pull goal for image %q", transports.ImageName(srcRef)) } defer goal.cleanUp() - return ir.doPullImage(ctx, sc, *goal, writer, signingOptions, dockerOptions, retryOptions, nil) + return ir.doPullImage(ctx, sc, *goal, writer, signingOptions, dockerOptions, retryOptions, nil, nil) } func cleanErrorMessage(err error) string { @@ -304,7 +305,7 @@ func cleanErrorMessage(err error) string { } // doPullImage is an internal helper interpreting pullGoal. Almost everyone should call one of the callers of doPullImage instead. -func (ir *Runtime) doPullImage(ctx context.Context, sc *types.SystemContext, goal pullGoal, writer io.Writer, signingOptions SigningOptions, dockerOptions *DockerRegistryOptions, retryOptions *retry.RetryOptions, label *string) ([]string, error) { +func (ir *Runtime) doPullImage(ctx context.Context, sc *types.SystemContext, goal pullGoal, writer io.Writer, signingOptions SigningOptions, dockerOptions *DockerRegistryOptions, retryOptions *retry.RetryOptions, label *string, progress chan types.ProgressProperties) ([]string, error) { span, _ := opentracing.StartSpanFromContext(ctx, "doPullImage") defer span.Finish() @@ -328,6 +329,10 @@ func (ir *Runtime) doPullImage(ctx context.Context, sc *types.SystemContext, goa for _, imageInfo := range goal.refPairs { copyOptions := getCopyOptions(sc, writer, dockerOptions, nil, signingOptions, "", nil) copyOptions.SourceCtx.SystemRegistriesConfPath = systemRegistriesConfPath // FIXME: Set this more globally. Probably no reason not to have it in every types.SystemContext, and to compute the value just once in one place. + if progress != nil { + copyOptions.Progress = progress + copyOptions.ProgressInterval = time.Second + } // Print the following statement only when pulling from a docker or atomic registry if writer != nil && (imageInfo.srcRef.Transport().Name() == DockerTransport || imageInfo.srcRef.Transport().Name() == AtomicTransport) { if _, err := io.WriteString(writer, fmt.Sprintf("Trying to pull %s...\n", imageInfo.image)); err != nil { diff --git a/libpod/image/search.go b/libpod/image/search.go index c5799219a..714551e6e 100644 --- a/libpod/image/search.go +++ b/libpod/image/search.go @@ -10,7 +10,7 @@ import ( "github.com/containers/image/v5/docker" "github.com/containers/image/v5/transports/alltransports" "github.com/containers/image/v5/types" - sysreg "github.com/containers/podman/v2/pkg/registries" + sysreg "github.com/containers/podman/v3/pkg/registries" "github.com/pkg/errors" "github.com/sirupsen/logrus" "golang.org/x/sync/semaphore" diff --git a/libpod/image/utils.go b/libpod/image/utils.go index 5e7fed5c6..0b4264112 100644 --- a/libpod/image/utils.go +++ b/libpod/image/utils.go @@ -11,7 +11,7 @@ import ( "github.com/containers/image/v5/docker/reference" "github.com/containers/image/v5/signature" "github.com/containers/image/v5/types" - "github.com/containers/podman/v2/libpod/define" + "github.com/containers/podman/v3/libpod/define" "github.com/containers/storage" "github.com/pkg/errors" ) @@ -45,7 +45,6 @@ func findImageInRepotags(search imageParts, images []*Image) (*storage.Image, er } } if len(candidates) == 0 { - return nil, errors.Wrapf(define.ErrNoSuchImage, "unable to find a name and tag match for %s in repotags", searchName) } @@ -75,9 +74,8 @@ func findImageInRepotags(search imageParts, images []*Image) (*storage.Image, er } if rwImageCnt > 1 { return nil, errors.Wrapf(define.ErrMultipleImages, "found multiple read/write images %s", strings.Join(keys, ",")) - } else { - return nil, errors.Wrapf(define.ErrMultipleImages, "found multiple read/only images %s", strings.Join(keys, ",")) } + return nil, errors.Wrapf(define.ErrMultipleImages, "found multiple read/only images %s", strings.Join(keys, ",")) } return candidates[0].image.image, nil } |