mirror of
https://github.com/goharbor/harbor.git
synced 2025-02-27 17:21:58 +01:00
subject: fix missing media type recognition for nydus (#19453)
Nydus images are compatible with both docker scheme v2 and OCI image spec v1 types of config media type: - application/vnd.oci.image.config.v1+json - application/vnd.docker.container.image.v1+json The patch fixes the media type recognition on the accessory type check. Signed-off-by: Yan Song <yansong.ys@antgroup.com> Co-authored-by: MinerYang <yminer@vmware.com>
This commit is contained in:
parent
d030ab216b
commit
13f4fca96e
@ -129,7 +129,7 @@ func Middleware() func(http.Handler) http.Handler {
|
|||||||
}
|
}
|
||||||
accData.Type = model.TypeSubject
|
accData.Type = model.TypeSubject
|
||||||
switch mf.Config.MediaType {
|
switch mf.Config.MediaType {
|
||||||
case schema2.MediaTypeImageConfig:
|
case ocispec.MediaTypeImageConfig, schema2.MediaTypeImageConfig:
|
||||||
if isNydusImage(mf) {
|
if isNydusImage(mf) {
|
||||||
accData.Type = model.TypeNydusAccelerator
|
accData.Type = model.TypeNydusAccelerator
|
||||||
}
|
}
|
||||||
|
@ -9,6 +9,7 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/docker/distribution/manifest/schema2"
|
||||||
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
|
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
|
||||||
"github.com/stretchr/testify/suite"
|
"github.com/stretchr/testify/suite"
|
||||||
|
|
||||||
@ -253,76 +254,81 @@ func (suite *MiddlewareTestSuite) TestSubjectDup() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (suite *MiddlewareTestSuite) TestIsNydusImage() {
|
func (suite *MiddlewareTestSuite) TestIsNydusImage() {
|
||||||
mf := `{
|
makeManifest := func(configType string) string {
|
||||||
"schemaVersion": 2,
|
return fmt.Sprintf(`{
|
||||||
"mediaType": "application/vnd.docker.distribution.manifest.v2+json",
|
"schemaVersion": 2,
|
||||||
"config": {
|
"mediaType": "application/vnd.docker.distribution.manifest.v2+json",
|
||||||
"mediaType": "application/vnd.docker.container.image.v1+json",
|
"config": {
|
||||||
"digest": "sha256:e314d79415361272a5ff6919ce70eb1d82ae55641ff60dcd8286b731cae2b5e7",
|
"mediaType": "%s",
|
||||||
"size": 3322
|
"digest": "sha256:e314d79415361272a5ff6919ce70eb1d82ae55641ff60dcd8286b731cae2b5e7",
|
||||||
},
|
"size": 3322
|
||||||
"layers": [
|
},
|
||||||
{
|
"layers": [
|
||||||
"mediaType": "application/vnd.oci.image.layer.nydus.blob.v1",
|
{
|
||||||
"digest": "sha256:bce0a563197a6aae0044f2063bf95f43bb956640b374fbdf0886cbc6926e2b7c",
|
"mediaType": "application/vnd.oci.image.layer.nydus.blob.v1",
|
||||||
"size": 3440759,
|
"digest": "sha256:bce0a563197a6aae0044f2063bf95f43bb956640b374fbdf0886cbc6926e2b7c",
|
||||||
"annotations": {
|
"size": 3440759,
|
||||||
"containerd.io/snapshot/nydus-blob": "true"
|
"annotations": {
|
||||||
}
|
"containerd.io/snapshot/nydus-blob": "true"
|
||||||
},
|
}
|
||||||
{
|
},
|
||||||
"mediaType": "application/vnd.oci.image.layer.nydus.blob.v1",
|
{
|
||||||
"digest": "sha256:7dedc3aaf7177a1d6792efcf1eae1305033fbac8dc48eb0caf49373b5d21475f",
|
"mediaType": "application/vnd.oci.image.layer.nydus.blob.v1",
|
||||||
"size": 337049,
|
"digest": "sha256:7dedc3aaf7177a1d6792efcf1eae1305033fbac8dc48eb0caf49373b5d21475f",
|
||||||
"annotations": {
|
"size": 337049,
|
||||||
"containerd.io/snapshot/nydus-blob": "true"
|
"annotations": {
|
||||||
}
|
"containerd.io/snapshot/nydus-blob": "true"
|
||||||
},
|
}
|
||||||
{
|
},
|
||||||
"mediaType": "application/vnd.oci.image.layer.nydus.blob.v1",
|
{
|
||||||
"digest": "sha256:f6bf79efcfc89f657b9705ef9ed77659e413e355efac8c6d3eea49d908c9218a",
|
"mediaType": "application/vnd.oci.image.layer.nydus.blob.v1",
|
||||||
"size": 5810244,
|
"digest": "sha256:f6bf79efcfc89f657b9705ef9ed77659e413e355efac8c6d3eea49d908c9218a",
|
||||||
"annotations": {
|
"size": 5810244,
|
||||||
"containerd.io/snapshot/nydus-blob": "true"
|
"annotations": {
|
||||||
}
|
"containerd.io/snapshot/nydus-blob": "true"
|
||||||
},
|
}
|
||||||
{
|
},
|
||||||
"mediaType": "application/vnd.oci.image.layer.nydus.blob.v1",
|
{
|
||||||
"digest": "sha256:35c290e1471c2f546ba7ca8eb47b334c0234e6a2d2b274c54fe96e016c1913c7",
|
"mediaType": "application/vnd.oci.image.layer.nydus.blob.v1",
|
||||||
"size": 7936,
|
"digest": "sha256:35c290e1471c2f546ba7ca8eb47b334c0234e6a2d2b274c54fe96e016c1913c7",
|
||||||
"annotations": {
|
"size": 7936,
|
||||||
"containerd.io/snapshot/nydus-blob": "true"
|
"annotations": {
|
||||||
}
|
"containerd.io/snapshot/nydus-blob": "true"
|
||||||
},
|
}
|
||||||
{
|
},
|
||||||
"mediaType": "application/vnd.oci.image.layer.nydus.blob.v1",
|
{
|
||||||
"digest": "sha256:1f168a347d1c654776644b331e631c3a1208699e2f608e29d8e3fd74e5fd99e8",
|
"mediaType": "application/vnd.oci.image.layer.nydus.blob.v1",
|
||||||
"size": 7728,
|
"digest": "sha256:1f168a347d1c654776644b331e631c3a1208699e2f608e29d8e3fd74e5fd99e8",
|
||||||
"annotations": {
|
"size": 7728,
|
||||||
"containerd.io/snapshot/nydus-blob": "true"
|
"annotations": {
|
||||||
}
|
"containerd.io/snapshot/nydus-blob": "true"
|
||||||
},
|
}
|
||||||
{
|
},
|
||||||
"mediaType": "application/vnd.docker.image.rootfs.diff.tar.gzip",
|
{
|
||||||
"digest": "sha256:86211e9295fabea433b7186ddfa6fd31af048a2f6fe3cf8d747b6f7ea39c0ea6",
|
"mediaType": "application/vnd.docker.image.rootfs.diff.tar.gzip",
|
||||||
"size": 35092,
|
"digest": "sha256:86211e9295fabea433b7186ddfa6fd31af048a2f6fe3cf8d747b6f7ea39c0ea6",
|
||||||
"annotations": {
|
"size": 35092,
|
||||||
"containerd.io/snapshot/nydus-bootstrap": "true",
|
"annotations": {
|
||||||
"containerd.io/snapshot/nydus-fs-version": "6"
|
"containerd.io/snapshot/nydus-bootstrap": "true",
|
||||||
}
|
"containerd.io/snapshot/nydus-fs-version": "6"
|
||||||
}
|
}
|
||||||
],
|
}
|
||||||
"subject": {
|
],
|
||||||
"mediaType": "application/vnd.docker.distribution.manifest.v2+json",
|
"subject": {
|
||||||
"digest": "sha256:f4d532d482a050a3bb02886be6d6deda9c22cf8df44b1465f04c8648ee573a70",
|
"mediaType": "application/vnd.docker.distribution.manifest.v2+json",
|
||||||
"size": 1363
|
"digest": "sha256:f4d532d482a050a3bb02886be6d6deda9c22cf8df44b1465f04c8648ee573a70",
|
||||||
}
|
"size": 1363
|
||||||
}`
|
}
|
||||||
|
}`, configType)
|
||||||
|
}
|
||||||
manifest := &ocispec.Manifest{}
|
manifest := &ocispec.Manifest{}
|
||||||
err := json.Unmarshal([]byte(mf), manifest)
|
err := json.Unmarshal([]byte(makeManifest(ocispec.MediaTypeImageConfig)), manifest)
|
||||||
suite.Nil(err)
|
suite.Nil(err)
|
||||||
suite.True(isNydusImage(manifest))
|
suite.True(isNydusImage(manifest))
|
||||||
|
|
||||||
|
err = json.Unmarshal([]byte(makeManifest(schema2.MediaTypeImageConfig)), manifest)
|
||||||
|
suite.Nil(err)
|
||||||
|
suite.True(isNydusImage(manifest))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestMiddlewareTestSuite(t *testing.T) {
|
func TestMiddlewareTestSuite(t *testing.T) {
|
||||||
|
Loading…
Reference in New Issue
Block a user