-
Notifications
You must be signed in to change notification settings - Fork 75
copy: add InstancePlatforms field for platform-based filtering #656
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
aguidirh
wants to merge
1
commit into
containers:main
Choose a base branch
from
aguidirh:sparse-manifest-platforms-pr1938
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+125
−4
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,6 +6,7 @@ import ( | |
| "testing" | ||
|
|
||
| digest "github.com/opencontainers/go-digest" | ||
| imgspecv1 "github.com/opencontainers/image-spec/specs-go/v1" | ||
| "github.com/stretchr/testify/assert" | ||
| "github.com/stretchr/testify/require" | ||
| internalManifest "go.podman.io/image/v5/internal/manifest" | ||
|
|
@@ -170,3 +171,77 @@ func convertInstanceCopyToSimplerInstanceCopy(copies []instanceCopy) []simplerIn | |
| } | ||
| return res | ||
| } | ||
|
|
||
| // TestDetermineSpecificImages tests the platform-based and digest-based instance selection | ||
| func TestDetermineSpecificImages(t *testing.T) { | ||
| validManifest, err := os.ReadFile(filepath.Join("..", "internal", "manifest", "testdata", "ociv1.image.index.json")) | ||
| require.NoError(t, err) | ||
| list, err := internalManifest.ListFromBlob(validManifest, internalManifest.GuessMIMEType(validManifest)) | ||
| require.NoError(t, err) | ||
|
|
||
| // Digests from ociv1.image.index.json | ||
| ppc64leDigest := digest.Digest("sha256:e692418e4cbaf90ca69d05a66403747baa33ee08806650b51fab815ad7fc331f") | ||
| amd64Digest := digest.Digest("sha256:5b0bcabd1ed22e9fb1310cf6c2dec7cdef19f0ad69efa1f392e94a4333501270") | ||
|
|
||
| tests := []struct { | ||
| name string | ||
| instances []digest.Digest | ||
| instancePlatforms []imgspecv1.Platform | ||
| expectedSize int | ||
| expectedDigests []digest.Digest | ||
| expectError bool | ||
| }{ | ||
| { | ||
| name: "PlatformOnly", | ||
| instancePlatforms: []imgspecv1.Platform{ | ||
| {OS: "linux", Architecture: "ppc64le"}, | ||
| }, | ||
| expectedSize: 1, | ||
| expectedDigests: []digest.Digest{ppc64leDigest}, | ||
| }, | ||
| { | ||
| name: "DigestOnly", | ||
| instances: []digest.Digest{amd64Digest}, | ||
| expectedSize: 1, | ||
| expectedDigests: []digest.Digest{amd64Digest}, | ||
| }, | ||
| { | ||
| name: "Combined", | ||
| instances: []digest.Digest{ppc64leDigest}, | ||
| instancePlatforms: []imgspecv1.Platform{ | ||
| {OS: "linux", Architecture: "amd64"}, | ||
| }, | ||
| expectedSize: 2, | ||
| expectedDigests: []digest.Digest{ppc64leDigest, amd64Digest}, | ||
| }, | ||
| { | ||
| name: "NonExistentPlatform", | ||
| instancePlatforms: []imgspecv1.Platform{ | ||
| {OS: "linux", Architecture: "arm64"}, | ||
| }, | ||
| expectError: true, | ||
| }, | ||
| } | ||
|
|
||
| for _, tt := range tests { | ||
| t.Run(tt.name, func(t *testing.T) { | ||
| options := &Options{ | ||
| Instances: tt.instances, | ||
| InstancePlatforms: tt.instancePlatforms, | ||
| } | ||
| specificImages, err := determineSpecificImages(options, list) | ||
|
|
||
| if tt.expectError { | ||
| assert.Error(t, err) | ||
| assert.Contains(t, err.Error(), "choosing instance for platform") | ||
| return | ||
| } | ||
|
|
||
| require.NoError(t, err) | ||
| assert.Equal(t, tt.expectedSize, specificImages.Size()) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This can probably use |
||
| for _, expectedDigest := range tt.expectedDigests { | ||
| assert.True(t, specificImages.Contains(expectedDigest)) | ||
| } | ||
| }) | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hum… we have multi-compression images (where there is a gzip instance and a zstd instance for the same platform). This would only copy one of the instances.
OTOH a trivial “does the instance match the required
Platformvalue” check might copy too much, because a v1 variant requirement would match a v1,v2,v3 instances.