Commit Graph

323 Commits

Author SHA1 Message Date
Paul Holzinger 02cdcc4a73 libimage/manifests: LoadFromImage() wrap all errors
All other errors are returned wrapped with the image ID so do the same
when the manifest blobl decoding fails.

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2025-04-09 13:54:30 +02:00
Paul Holzinger bd719bf41b libimage: fix manifest race during listing
I saw a flake in parallel podman testing, podman images can fail if the
manifest was removed at the right time. In general listing should never
be able to fail when another image or manifest is removed in parallel.

Change the logic to convert to manifest and only collect the digests in
the success case and ignore all other errors to make the listing more
robust.

I observed the following error from podman images:
Error: locating image "xxx" for loading instance list: locating image with ID "xxx": image not known

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2025-04-09 13:54:30 +02:00
flouthoc 4b1b30ec19 libimage: remove unnecessary reportResolvedReference
After https://github.com/containers/common/pull/2339 there is no for
this argument so remove this.

Signed-off-by: flouthoc <flouthoc.git@gmail.com>
2025-04-01 07:04:10 -07:00
openshift-merge-bot[bot] d093d6c769 Merge pull request #2389 from kolyshkin/golangci-v2
Switch to golangci-lint v2, cleanup config, fix new linter warnings
2025-03-26 18:08:46 +00:00
Kir Kolyshkin a25e5a56a8 libimage: silence a staticcheck warning
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2025-03-26 09:36:14 -07:00
Kir Kolyshkin 9da372fd2c libimage: apply De Morgan's law
This fixes the following staticcheck warnings:

> libimage/image.go:463:5: QF1001: could apply De Morgan's law (staticcheck)
> 	if !(referencedBy == "" || numNames == 1) {
> 	   ^
> libimage/normalize.go:33:5: QF1001: could apply De Morgan's law (staticcheck)
> 	if !(strings.ContainsAny(registry, ".:") || registry == "localhost") {
> 	   ^
> libimage/search.go:220:6: QF1001: could apply De Morgan's law (staticcheck)
> 		if !(filterMatchesAutomatedFilter(&options.Filter, results[i]) && filterMatchesOfficialFilter(&options.Filter, results[i]) && filterMatchesStarFilter(&options.Filter, results[i])) {
> 		   ^

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2025-03-26 09:36:14 -07:00
Paul Holzinger c3ea738e31 libimage: fix one copyToStorage error message
ImageReference is an interface and we generally have no idea about the
underlying layout here and if that can be printed as string. In case of
the docker transport we get:
{{{docker.io library/busybox} latest} %!s(bool=false)}

That is clearly wrong and confusing, instead use transports.ImageName()
which is the recommended way to refer to images in the UI.

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2025-03-26 13:35:17 +01:00
openshift-merge-bot[bot] c3a3c62b3f Merge pull request #2374 from giuseppe/look-mountpoint-in-mapped-layers
image: look for mountpoint in mapped layers too
2025-03-26 10:12:58 +00:00
Daniel J Walsh 9e1bb4b047 When checking IsDangling make sure image is not in manifest list
Currently when we run podman image prune or podman images --filter
dangling

It is pruning images that are in a local manifest. These images are
not dangling because they are currently in use by a named manifest list.

You can create this situation simply by doing

echo "from scratch" > /tmp/Containerfile
id=$(podman build /tmp)
podman manifest create test $id
podman image prune --force
podman image exists $id

Will return an error since the image was pruned.  Now the local manifest
test is broken.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2025-03-21 14:53:41 -04:00
flouthoc 8e2888e726 copier: modify newCopier for golangci-lint
Fix linter error
```
Error: libimage/copier.go:180:51: `(*Runtime).newCopier` - `reportResolvedReference` always receives `nil` (unparam)
```

Signed-off-by: flouthoc <flouthoc.git@gmail.com>
2025-03-20 13:38:06 -07:00
flouthoc 2146c492dc pull,load: use *Image instead of re-resolving via name
Following commit fixes a `race` condition in `libimage` because in `Pull(`
after performing `copy` from remote sources it agains attempts to resolve
image via `LookupImage`, any operation between `copy` and `LookupImage` can remove
`name` from the recently pulled image. Causing race in builds.

This issue was discoverd while working on PR https://github.com/containers/buildah/pull/5971
```
buildah build -t test --jobs=2 --skip-unused-stages=false .
```

Containerfile
```
FROM quay.io/jitesoft/alpine
RUN arch
FROM --platform=linux/arm64 quay.io/jitesoft/alpine AS foreign
```

Following commit also addresses the commit 88f60eeeb3
by performing the neccessary refactor.

No functional change in public exposed API, exisiting tests should pass as-is.
[NO NEW TESTS NEEDED]

Signed-off-by: flouthoc <flouthoc.git@gmail.com>
2025-03-20 13:37:59 -07:00
Giuseppe Scrivano d537c8a226 image: look for mountpoint in mapped layers too
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2025-03-20 19:21:51 +01:00
Paul Holzinger e3d6a28822 libimage: rework DiskUsage() to count layers
The old implementation only counted full images when sharing content
between them. That is wrong, the store is layer based. We can have two
images with no parent image that shares layers.

As such get rid of the image tree that only is able to walk child/parent
images. Instead we actually walk all layers now and correctly notice
when they are shared.

To this this correctly, first convert all layers to map so we can look
them up by ID. And add missing size information if needed. Then we walk
all images layers and count how often each layers is used. Then walk
again but this time we know if the layer size must be shared or not so
we can actually acount things correctly.

Fixes: containers/podman#24452
Fixes: https://issues.redhat.com/browse/RHEL-29641

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2025-03-10 12:16:22 +01:00
Miloslav Trmač 904e85e7f7 Add a missing .Close()
The underlying implementation does not do anything, so purely
for consistency.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2025-02-28 20:16:31 +01:00
Miloslav Trmač 0ebdf967d6 Use UnparsedInstance.Manifest instead of ImageSource.GetManifest
... to validate that the manifests match expected digests, if any.

Do this everywhere, even where we read local storage which is
mostly trusted, because it is cheap enough and being consistent
makes it less likely for the code to be copied into other
contexts where the sources are not trusted.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2025-02-28 20:16:28 +01:00
Paul Holzinger 40adf482cb fix issues reported by usetesting
In particular rework the tmpdir test to use two seperate runs so we can
correctl use t.Setenv() so it cleans up at the right moment.

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2025-02-14 11:50:50 +01:00
Paul Holzinger 04b578ae9a fix issues reported by errcheck
Mainly type casting issues. I ignored some of them where I don't think
it can fail or when it is in tests where we would notice anyway.

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2025-02-14 11:50:50 +01:00
James Hewitt 5709b01001 Only reset compression if its not valid
If we reset the default compression method, force compression no longer works.

Signed-off-by: James Hewitt <james.hewitt@uk.ibm.com>
2024-11-29 17:55:58 +00:00
Paul Holzinger 79e7aadc50 libimage tests: try to avoid docker.io images
These images can and will change at any time and thus can break our CI
without any external changes which is very bad. The TestPush test is
failing because it expects two not one image as it converts from docker
to oci on push. However the upstream docker.io/library/alpine was
switched to an oci image thus the test started failing as the local
storage now has the same id and just stores two different tags for the
same image.

Switch to our own controlled quay.io images where possible. This is
neither complete nor do I fully understand the tests here. I did a quick
search and replace and will see what works or not.

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2024-11-19 18:50:55 +01:00
Miloslav Trmač f05e2cf05e Reliably return the correct image ID from pull
Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2024-11-05 19:42:11 +01:00
Miloslav Trmač d90a20404b Improve image ID lookup for pulled images
- Use the image's repo, not just the digest, to be more precise
  when zstd:chunked ambiguities are involved
- Remove the multi-platform lookup code, it is never used

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2024-10-18 22:13:44 +02:00
Miloslav Trmač 7daccce4dc Only return one image ID (/name?) from copySingleImageFromRegistry
... because we now never return more than one.

Should not change behavior.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2024-10-18 22:13:44 +02:00
Miloslav Trmač 810971b184 Only return one image ID from imagesIDForManifest
There's no benefit in returning multiple matches;
we ideally want to return exactly the image we pulled,
but even if that were hard, returning multiple guesses
is not what the user asked for.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2024-10-18 22:10:53 +02:00
Miloslav Trmač 486404691b Don't fall back if imagesIDsForManifest fails
If we can't find the image we have just pulled by digest, the image
was probably already removed, and returning candidate.Value
could only possibly point at a _different_ image with the same
tag.

Instead, fail immediately.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2024-10-18 22:10:53 +02:00
Miloslav Trmač 88f60eeeb3 Add a FIXME about unstable name lookups
Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2024-10-18 22:10:53 +02:00
Brent Baude 3c70899eda Export Copier to support OCI artifacts
To support OCI artifacts in Podman, we need to export the Copier type
and create an exported constructor (NewCopier).  Additionally, the
actual copy and close methods are now exported.

Signed-off-by: Brent Baude <bbaude@redhat.com>
2024-09-23 12:31:57 -05:00
Brent Baude 39e5b339ec Revert "Export portions of Copier"
This reverts commit 76e87a92ce.

Signed-off-by: Brent Baude <bbaude@redhat.com>
2024-09-23 09:58:53 -05:00
openshift-merge-bot[bot] 5217cfc4e2 Merge pull request #2091 from nalind/manifest-convert
libimage.Image: add ConvertToManifestList()
2024-09-20 12:50:42 +00:00
openshift-merge-bot[bot] 677297be51 Merge pull request #2164 from baude/exportCopierNew
Export portions of Copier
2024-09-20 12:47:56 +00:00
Brent Baude 11ea8396fd Add ImageListSelection to copier options
For artifact support, the copier needs to get all tags; as such, we need
to pass in the correct value for ImageListSelection.

Signed-off-by: Brent Baude <bbaude@redhat.com>
2024-09-19 13:42:38 -05:00
Brent Baude 76e87a92ce Export portions of Copier
To support artifact handling, we need to export some of the methods for
copier. The Copy and Close method have been exported.  In addition, a
new constructor that is exported was created so we could introduce a
different SystemContext for artifacts.

Signed-off-by: Brent Baude <bbaude@redhat.com>
2024-09-19 13:32:10 -05:00
Paul Holzinger 805e7ae406 update golangci-lint to 1.60.3
Contains fixes for new linters, removed depracted and removed linters
from the config.

Most notably because we use go 1.22 now we can get rid of the copy for
loop vars[1]. Also as of the go 1..2 we can use the new int range syntax
in for loops the new intrange linter checks that.

[1] https://go.dev/blog/loopvar-preview

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2024-09-03 15:57:02 +02:00
Jan Rodák 946dc49677 Improve runtime.layerTree method to be consistent
Signed-off-by: Jan Rodák <hony.com@seznam.cz>
2024-08-28 16:00:59 +02:00
Jan Rodák bb78342714 Refactor Image filter
Signed-off-by: Jan Rodák <hony.com@seznam.cz>
2024-08-28 15:59:32 +02:00
Jan Rodák 6b1528f145 Add ListImagesByNames and change the ListImages API
Signed-off-by: Jan Rodák <hony.com@seznam.cz>
2024-08-28 15:19:53 +02:00
Jan Rodák e5b4d28057 Create test for ListImages methode
Signed-off-by: Jan Rodák <hony.com@seznam.cz>
2024-08-28 11:48:28 +02:00
Jan Rodák 0a959160bb Fix SA1019: replace deprecated github.com/containerd/containerd/platforms with github.com/containerd/platforms
Signed-off-by: Jan Rodák <hony.com@seznam.cz>

Vendor containerd/platforms

Signed-off-by: Jan Rodák <hony.com@seznam.cz>
2024-08-22 09:51:42 +02:00
Matt Heon 197e4def96 Use SystemContext when creating manifest references
Instead of passing a nil system context when adding to a manifest
list, use a valid one, ensuring that settings like auth and TLS
verification are passed along and respected.

Fixes https://github.com/containers/podman/issues/23410

Signed-off-by: Matt Heon <mheon@redhat.com>
2024-07-31 08:08:10 -04:00
Paul Holzinger 0bb0fcdefc libimage: recommend podman system check over reset
podman system reset nukes everything which makes not a great suggestion.
Now that we have the podman system check recommend that instead as it
actually checks the storage for corruption and might be able to repair
it.

This is important because as it turns out this warning can pop up even
in totally normal circumstances as there is a race between image and
layer listing[1]. And even if that get fixed the check command will be
the better suggestion.

[1] https://github.com/containers/podman/issues/23331

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2024-07-23 10:43:24 +02:00
Nalin Dahyabhai 6629f78ed0 libimage/manifests.list.Reference(): use defined constants
Instead of just writing a lot of the OCI layout using magic strings and
names, use constants provided by the image-spec.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2024-07-18 14:35:59 -04:00
Nalin Dahyabhai b989b38d1d libimage.Image: add ConvertToManifestList()
Add libimage.Image.ConvertToManifestList(), which will convert an image
to a manifest list if it isn't already possible to use it as one.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2024-07-18 14:35:59 -04:00
Nalin Dahyabhai 2f425b1cdf AddArtifactOptions: reformat godoc
Reformat the godoc for the AddArtifactOptions type so that it gets
wrapped correctly.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2024-07-17 14:54:16 -04:00
Daniel J Walsh 1602e53b32 Display same error as split
Partial fix for https://github.com/containers/podman/issues/23120

Working on a fix for this crash, but want same error to come back as
non-remote case.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2024-07-15 16:18:07 -04:00
Nalin Dahyabhai 7aa2fce6f3 Make the definition of LookupReferenceFunc unconditional
Move the definition of our LookupReferenceFunc type alias to a file that
isn't conditionally compiled.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2024-07-15 10:24:02 -04:00
Paul Holzinger f3f39c4c05 replace k8s.gcr.io with registry.k8s.io
We see issues in CI where we fail to pull from k8s.gcr.io. As k8s uses a
new registry URL migrate to that[1] and hope it fixes the issues.

[1] https://kubernetes.io/blog/2023/02/06/k8s-gcr-io-freeze-announcement/

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2024-06-18 11:37:12 +02:00
openshift-merge-bot[bot] 902d1c7d46 Merge pull request #2045 from nalind/clear-variant
libimage.ManifestList.AnnotateInstance(): allow clearing variant values
2024-06-06 13:08:39 +00:00
Nalin Dahyabhai 3393aeef9c Remove nil checks before calling slices.Clone/maps.Clone
Both slices.Clone() and maps.Clone() return `nil` when passed `nil`, so
we don't need to check for a `nil` pointer before calling them.

Imports that used the golang.org/x/exp versions of the maps and slices
packages can now use the versions in the standard library, since we
require Go 1.21.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2024-06-05 17:59:22 -04:00
Nalin Dahyabhai c13fc2cbfe libimage.ManifestList.AnnotateInstance(): allow clearing variant values
When AnnotateInstance() is given a non-empty Architecture value, set the
Variant value to the one that was passed in along with it, even if that
value is empty.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2024-06-05 17:45:28 -04:00
Nalin Dahyabhai 66b682ea98 libimage/manifests.list.Add(): preserve artifactType when all=true
When asked to add all of the entries from one index to another, don't
forget to carry over the artifactType.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2024-05-28 11:03:09 -04:00
Daniel J Walsh 9293f7178d Fix spelling mistake
Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2024-05-27 06:14:44 -04:00