Skip to content

Commit

Permalink
list: ListUpdate add Platform field
Browse files Browse the repository at this point in the history
`c/image` uses `Instance(` API to get the required details of an
instance while performing replication `Platform` of instance is needed
hence `ListUpdate` must include platform.

Needed by: containers#1987

Signed-off-by: Aditya R <[email protected]>
  • Loading branch information
flouthoc committed Jul 7, 2023
1 parent 1b8551e commit 7494bfa
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 0 deletions.
7 changes: 7 additions & 0 deletions internal/manifest/docker_schema2_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,13 @@ func (list *Schema2ListPublic) Instance(instanceDigest digest.Digest) (ListUpdat
Digest: manifest.Digest,
Size: manifest.Size,
MediaType: manifest.MediaType,
platform: imgspecv1.Platform{
OS: manifest.Platform.OS,
Architecture: manifest.Platform.Architecture,
OSVersion: manifest.Platform.OSVersion,
OSFeatures: manifest.Platform.OSFeatures,
Variant: manifest.Platform.Variant,
},
}, nil
}
}
Expand Down
2 changes: 2 additions & 0 deletions internal/manifest/docker_schema2_list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ func TestSchema2ListEditInstances(t *testing.T) {
require.NoError(t, err)
assert.Equal(t, "something", instance.MediaType)
assert.Equal(t, int64(32), instance.Size)
// platform must match with instance platform set in `v2list.manifest.json` for the first instance
assert.Equal(t, imgspecv1.Platform{Architecture: "ppc64le", OS: "linux", OSVersion: "", OSFeatures: []string(nil), Variant: ""}, instance.GetPlatform())

// Create a fresh list
list, err = ListFromBlob(validManifest, GuessMIMEType(validManifest))
Expand Down
6 changes: 6 additions & 0 deletions internal/manifest/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,12 @@ type ListUpdate struct {
Digest digest.Digest
Size int64
MediaType string
platform imgspecv1.Platform // stores platform for the instance, read-only field
}

// Allows to access private read-only field `platform`.
func (listUpdate ListUpdate) GetPlatform() imgspecv1.Platform {
return listUpdate.platform
}

type ListOp int
Expand Down
1 change: 1 addition & 0 deletions internal/manifest/oci_index.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ func (index *OCI1IndexPublic) Instance(instanceDigest digest.Digest) (ListUpdate
Digest: manifest.Digest,
Size: manifest.Size,
MediaType: manifest.MediaType,
platform: *manifest.Platform,
}, nil
}
}
Expand Down
2 changes: 2 additions & 0 deletions internal/manifest/oci_index_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ func TestOCI1EditInstances(t *testing.T) {
require.NoError(t, err)
assert.Equal(t, "something", instance.MediaType)
assert.Equal(t, int64(32), instance.Size)
// platform must match with what was set in `ociv1.image.index.json` for the first instance
assert.Equal(t, imgspecv1.Platform{Architecture: "ppc64le", OS: "linux", OSVersion: "", OSFeatures: []string(nil), Variant: ""}, instance.GetPlatform())

// Create a fresh list
list, err = ListFromBlob(validManifest, GuessMIMEType(validManifest))
Expand Down

0 comments on commit 7494bfa

Please sign in to comment.