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:
imeoer 2023-10-18 21:53:13 -05:00 committed by GitHub
parent d030ab216b
commit 13f4fca96e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 73 additions and 67 deletions

View File

@ -129,7 +129,7 @@ func Middleware() func(http.Handler) http.Handler {
}
accData.Type = model.TypeSubject
switch mf.Config.MediaType {
case schema2.MediaTypeImageConfig:
case ocispec.MediaTypeImageConfig, schema2.MediaTypeImageConfig:
if isNydusImage(mf) {
accData.Type = model.TypeNydusAccelerator
}

View File

@ -9,6 +9,7 @@ import (
"testing"
"time"
"github.com/docker/distribution/manifest/schema2"
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
"github.com/stretchr/testify/suite"
@ -253,11 +254,12 @@ func (suite *MiddlewareTestSuite) TestSubjectDup() {
}
func (suite *MiddlewareTestSuite) TestIsNydusImage() {
mf := `{
makeManifest := func(configType string) string {
return fmt.Sprintf(`{
"schemaVersion": 2,
"mediaType": "application/vnd.docker.distribution.manifest.v2+json",
"config": {
"mediaType": "application/vnd.docker.container.image.v1+json",
"mediaType": "%s",
"digest": "sha256:e314d79415361272a5ff6919ce70eb1d82ae55641ff60dcd8286b731cae2b5e7",
"size": 3322
},
@ -317,12 +319,16 @@ func (suite *MiddlewareTestSuite) TestIsNydusImage() {
"digest": "sha256:f4d532d482a050a3bb02886be6d6deda9c22cf8df44b1465f04c8648ee573a70",
"size": 1363
}
}`
}`, configType)
}
manifest := &ocispec.Manifest{}
err := json.Unmarshal([]byte(mf), manifest)
err := json.Unmarshal([]byte(makeManifest(ocispec.MediaTypeImageConfig)), manifest)
suite.Nil(err)
suite.True(isNydusImage(manifest))
err = json.Unmarshal([]byte(makeManifest(schema2.MediaTypeImageConfig)), manifest)
suite.Nil(err)
suite.True(isNydusImage(manifest))
}
func TestMiddlewareTestSuite(t *testing.T) {