diff options
Diffstat (limited to 'libpod/image')
-rw-r--r-- | libpod/image/filters.go | 6 | ||||
-rw-r--r-- | libpod/image/image.go | 5 | ||||
-rw-r--r-- | libpod/image/image_test.go | 8 | ||||
-rw-r--r-- | libpod/image/prune.go | 6 | ||||
-rw-r--r-- | libpod/image/pull.go | 2 | ||||
-rw-r--r-- | libpod/image/search.go | 10 |
6 files changed, 16 insertions, 21 deletions
diff --git a/libpod/image/filters.go b/libpod/image/filters.go index 747eba165..9d99fb344 100644 --- a/libpod/image/filters.go +++ b/libpod/image/filters.go @@ -102,8 +102,8 @@ func ReferenceFilter(ctx context.Context, referenceFilter string) ResultFilter { } } -// IdFilter allows you to filter by image Id -func IdFilter(idFilter string) ResultFilter { +// IDFilter allows you to filter by image Id +func IDFilter(idFilter string) ResultFilter { return func(i *Image) bool { return i.ID() == idFilter } @@ -172,7 +172,7 @@ func (ir *Runtime) createFilterFuncs(filters []string, img *Image) ([]ResultFilt case "reference": filterFuncs = append(filterFuncs, ReferenceFilter(ctx, splitFilter[1])) case "id": - filterFuncs = append(filterFuncs, IdFilter(splitFilter[1])) + filterFuncs = append(filterFuncs, IDFilter(splitFilter[1])) default: return nil, errors.Errorf("invalid filter %s ", splitFilter[0]) } diff --git a/libpod/image/image.go b/libpod/image/image.go index 60787b826..1101e35dc 100644 --- a/libpod/image/image.go +++ b/libpod/image/image.go @@ -172,8 +172,6 @@ func (ir *Runtime) New(ctx context.Context, name, signaturePolicyPath, authfile // LoadFromArchiveReference creates a new image object for images pulled from a tar archive and the like (podman load) // This function is needed because it is possible for a tar archive to have multiple tags for one image func (ir *Runtime) LoadFromArchiveReference(ctx context.Context, srcRef types.ImageReference, signaturePolicyPath string, writer io.Writer) ([]*Image, error) { - var newImages []*Image - if signaturePolicyPath == "" { signaturePolicyPath = ir.SignaturePolicyPath } @@ -182,6 +180,7 @@ func (ir *Runtime) LoadFromArchiveReference(ctx context.Context, srcRef types.Im return nil, errors.Wrapf(err, "unable to pull %s", transports.ImageName(srcRef)) } + newImages := make([]*Image, 0, len(imageNames)) for _, name := range imageNames { newImage, err := ir.NewFromLocal(name) if err != nil { @@ -475,11 +474,11 @@ func (ir *Runtime) GetRWImages() ([]*Image, error) { // getImages retrieves all images present in storage func (ir *Runtime) getImages(rwOnly bool) ([]*Image, error) { - var newImages []*Image images, err := ir.store.Images() if err != nil { return nil, err } + newImages := make([]*Image, 0, len(images)) for _, i := range images { if rwOnly && i.ReadOnly { continue diff --git a/libpod/image/image_test.go b/libpod/image/image_test.go index 3cd368cdc..74067853e 100644 --- a/libpod/image/image_test.go +++ b/libpod/image/image_test.go @@ -44,7 +44,7 @@ func cleanup(workdir string, ir *Runtime) { } } -func makeLocalMatrix(b, bg *Image) ([]localImageTest, error) { +func makeLocalMatrix(b, bg *Image) []localImageTest { var l []localImageTest // busybox busybox := localImageTest{ @@ -65,7 +65,7 @@ func makeLocalMatrix(b, bg *Image) ([]localImageTest, error) { busyboxGlibc.names = bbGlibcNames l = append(l, busybox, busyboxGlibc) - return l, nil + return l } @@ -100,9 +100,7 @@ func TestImage_NewFromLocal(t *testing.T) { bbglibc, err := ir.New(context.Background(), "docker.io/library/busybox:glibc", "", "", writer, nil, SigningOptions{}, nil, util.PullImageMissing) assert.NoError(t, err) - tm, err := makeLocalMatrix(bb, bbglibc) - assert.NoError(t, err) - + tm := makeLocalMatrix(bb, bbglibc) for _, image := range tm { // tag our images err = image.img.TagImage(image.taggedName) diff --git a/libpod/image/prune.go b/libpod/image/prune.go index 3b4ea74c4..518795173 100644 --- a/libpod/image/prune.go +++ b/libpod/image/prune.go @@ -104,10 +104,7 @@ func (ir *Runtime) GetPruneImages(ctx context.Context, all bool, filterFuncs []I // PruneImages prunes dangling and optionally all unused images from the local // image store func (ir *Runtime) PruneImages(ctx context.Context, all bool, filter []string) ([]string, error) { - var ( - prunedCids []string - filterFuncs []ImageFilter - ) + filterFuncs := make([]ImageFilter, 0, len(filter)) for _, f := range filter { filterSplit := strings.SplitN(f, "=", 2) if len(filterSplit) < 2 { @@ -125,6 +122,7 @@ func (ir *Runtime) PruneImages(ctx context.Context, all bool, filter []string) ( if err != nil { return nil, errors.Wrap(err, "unable to get images to prune") } + prunedCids := make([]string, 0, len(pruneImages)) for _, p := range pruneImages { repotags, err := p.RepoTags() if err != nil { diff --git a/libpod/image/pull.go b/libpod/image/pull.go index 6b4c40ba2..24909a59a 100644 --- a/libpod/image/pull.go +++ b/libpod/image/pull.go @@ -366,7 +366,7 @@ func (ir *Runtime) pullGoalFromPossiblyUnqualifiedName(inputName string) (*pullG if err != nil { return nil, err } - var refPairs []pullRefPair + refPairs := make([]pullRefPair, 0, len(searchRegistries)) for _, registry := range searchRegistries { ref, err := decomposedImage.referenceWithRegistry(registry) if err != nil { diff --git a/libpod/image/search.go b/libpod/image/search.go index fd29dac45..f8d45d576 100644 --- a/libpod/image/search.go +++ b/libpod/image/search.go @@ -93,8 +93,8 @@ func SearchImages(term string, options SearchOptions) ([]SearchResult, error) { searchImageInRegistryHelper := func(index int, registry string) { defer sem.Release(1) defer wg.Done() - searchOutput, err := searchImageInRegistry(term, registry, options) - data[index] = searchOutputData{data: searchOutput, err: err} + searchOutput := searchImageInRegistry(term, registry, options) + data[index] = searchOutputData{data: searchOutput} } ctx := context.Background() @@ -131,7 +131,7 @@ func getRegistries(registry string) ([]string, error) { return registries, nil } -func searchImageInRegistry(term string, registry string, options SearchOptions) ([]SearchResult, error) { +func searchImageInRegistry(term string, registry string, options SearchOptions) []SearchResult { // Max number of queries by default is 25 limit := maxQueries if options.Limit > 0 { @@ -147,7 +147,7 @@ func searchImageInRegistry(term string, registry string, options SearchOptions) results, err := docker.SearchRegistry(context.TODO(), sc, registry, term, limit) if err != nil { logrus.Errorf("error searching registry %q: %v", registry, err) - return []SearchResult{}, nil + return []SearchResult{} } index := registry arr := strings.Split(registry, ".") @@ -201,7 +201,7 @@ func searchImageInRegistry(term string, registry string, options SearchOptions) } paramsArr = append(paramsArr, params) } - return paramsArr, nil + return paramsArr } // ParseSearchFilter turns the filter into a SearchFilter that can be used for |