Skip to content

Commit

Permalink
Merge pull request #1672 from lcarva/EC-674
Browse files Browse the repository at this point in the history
Handle Index Images with no-platoform manifests
  • Loading branch information
lcarva authored Jun 6, 2024
2 parents 0862dbe + b9ff969 commit 6948321
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
10 changes: 8 additions & 2 deletions internal/applicationsnapshot/input.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,9 +221,15 @@ func expandImageIndex(ctx context.Context, snap *app.SnapshotSpec) {

// The image is an image index and accessible so remove the image index itself and add index manifests
components = components[:len(components)-1]
for _, manifest := range indexManifest.Manifests {
for i, manifest := range indexManifest.Manifests {
var arch string
if manifest.Platform != nil && manifest.Platform.Architecture != "" {
arch = manifest.Platform.Architecture
} else {
arch = fmt.Sprintf("noarch-%d", i)
}
archComponent := component
archComponent.Name = fmt.Sprintf("%s-%s-%s", component.Name, manifest.Digest, manifest.Platform.Architecture)
archComponent.Name = fmt.Sprintf("%s-%s-%s", component.Name, manifest.Digest, arch)
archComponent.ContainerImage = fmt.Sprintf("%s@%s", ref.Context().Name(), manifest.Digest)
components = append(components, archComponent)
}
Expand Down
13 changes: 11 additions & 2 deletions internal/applicationsnapshot/input_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,12 @@ func TestExpandImageIndex(t *testing.T) {
Platform: &v1.Platform{Architecture: "arm64"},
Digest: v1.Hash{Algorithm: "sha256", Hex: "digest2"},
},
{
MediaType: types.OCIManifestSchema1,
// No Platform since that's an optional attribute:
// https://github.com/opencontainers/image-spec/blob/main/image-index.md
Digest: v1.Hash{Algorithm: "sha256", Hex: "digest3"},
},
},
}, nil)

Expand All @@ -270,20 +276,23 @@ func TestExpandImageIndex(t *testing.T) {
}

expandImageIndex(ctx, snap)
assert.True(t, len(snap.Components) == 2, "Image Index itself should be removed and be replaced by individual image manifests")
assert.True(t, len(snap.Components) == 3, "Image Index itself should be removed and be replaced by individual image manifests")

amd64Image, arm64Image := false, false
amd64Image, arm64Image, noarchImage := false, false, false
for _, archImage := range snap.Components {
switch {
case strings.Contains(archImage.Name, "some-image-name-sha256:digest1-amd64"):
amd64Image = true
case strings.Contains(archImage.Name, "some-image-name-sha256:digest2-arm64"):
arm64Image = true
case strings.Contains(archImage.Name, "some-image-name-sha256:digest3-noarch-2"):
noarchImage = true
}
}

assert.True(t, amd64Image, "An amd64 image should be present in the component")
assert.True(t, arm64Image, "An arm64 image should be present in the component")
assert.True(t, noarchImage, "A noarch image should be present in the component")
}

func TestExpandImageImage_Errors(t *testing.T) {
Expand Down

0 comments on commit 6948321

Please sign in to comment.