Skip to content

Commit b5192d8

Browse files
authored
Merge branch 'main' into fricounet/upstream/index-detect
Signed-off-by: Baptiste Girard-Carrabin <[email protected]>
2 parents fb0aac1 + e44c981 commit b5192d8

File tree

5 files changed

+65
-8
lines changed

5 files changed

+65
-8
lines changed

pkg/backend/s3.go

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,16 +38,18 @@ type S3Backend struct {
3838
accessKeySecret string
3939
accessKeyID string
4040
forcePush bool
41+
checksumAlgorithm types.ChecksumAlgorithm
4142
}
4243

4344
type S3Config struct {
44-
AccessKeyID string `json:"access_key_id,omitempty"`
45-
AccessKeySecret string `json:"access_key_secret,omitempty"`
46-
Endpoint string `json:"endpoint,omitempty"`
47-
Scheme string `json:"scheme,omitempty"`
48-
BucketName string `json:"bucket_name,omitempty"`
49-
Region string `json:"region,omitempty"`
50-
ObjectPrefix string `json:"object_prefix,omitempty"`
45+
AccessKeyID string `json:"access_key_id,omitempty"`
46+
AccessKeySecret string `json:"access_key_secret,omitempty"`
47+
Endpoint string `json:"endpoint,omitempty"`
48+
Scheme string `json:"scheme,omitempty"`
49+
BucketName string `json:"bucket_name,omitempty"`
50+
Region string `json:"region,omitempty"`
51+
ObjectPrefix string `json:"object_prefix,omitempty"`
52+
ChecksumAlgorithm *string `json:"checksum_algorithm,omitempty"`
5153
}
5254

5355
func newS3Backend(rawConfig []byte, forcePush bool) (*S3Backend, error) {
@@ -67,6 +69,22 @@ func newS3Backend(rawConfig []byte, forcePush bool) (*S3Backend, error) {
6769
return nil, fmt.Errorf("invalid S3 configuration: missing 'bucket_name' or 'region'")
6870
}
6971

72+
var checksumAlgorithm types.ChecksumAlgorithm
73+
if cfg.ChecksumAlgorithm == nil {
74+
// Default to CRC32 checksum
75+
checksumAlgorithm = types.ChecksumAlgorithmCrc32
76+
} else if *cfg.ChecksumAlgorithm != "" {
77+
for _, algorithm := range checksumAlgorithm.Values() {
78+
if string(algorithm) == *cfg.ChecksumAlgorithm {
79+
checksumAlgorithm = algorithm
80+
break
81+
}
82+
}
83+
if checksumAlgorithm == "" {
84+
return nil, fmt.Errorf("invalid checksum algorithm: %s, supported algorithms: %v", *cfg.ChecksumAlgorithm, checksumAlgorithm.Values())
85+
}
86+
}
87+
7088
return &S3Backend{
7189
objectPrefix: cfg.ObjectPrefix,
7290
bucketName: cfg.BucketName,
@@ -75,6 +93,7 @@ func newS3Backend(rawConfig []byte, forcePush bool) (*S3Backend, error) {
7593
accessKeySecret: cfg.AccessKeySecret,
7694
accessKeyID: cfg.AccessKeyID,
7795
forcePush: forcePush,
96+
checksumAlgorithm: checksumAlgorithm,
7897
}, nil
7998
}
8099

@@ -144,7 +163,7 @@ func (b *S3Backend) Push(ctx context.Context, cs content.Store, desc ocispec.Des
144163
Bucket: aws.String(b.bucketName),
145164
Key: aws.String(blobObjectKey),
146165
Body: reader,
147-
ChecksumAlgorithm: types.ChecksumAlgorithmCrc32,
166+
ChecksumAlgorithm: b.checksumAlgorithm,
148167
}); err != nil {
149168
return errors.Wrap(err, "push blob to s3 backend")
150169
}

pkg/backend/s3_test.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ package backend
99
import (
1010
"reflect"
1111
"testing"
12+
13+
"github.com/aws/aws-sdk-go-v2/service/s3/types"
1214
)
1315

1416
func Test_newS3Backend(t *testing.T) {
@@ -42,6 +44,32 @@ func Test_newS3Backend(t *testing.T) {
4244
region: "us-east-1",
4345
accessKeySecret: "minio123",
4446
accessKeyID: "minio",
47+
checksumAlgorithm: types.ChecksumAlgorithmCrc32,
48+
},
49+
wantErr: false,
50+
},
51+
{
52+
name: "test2, set checksum algorithm",
53+
args: args{
54+
rawConfig: []byte(`{
55+
"endpoint": "localhost:9000",
56+
"scheme": "http",
57+
"bucket_name": "nydus",
58+
"region": "us-east-1",
59+
"object_prefix": "path/to/my-registry/",
60+
"access_key_id": "minio",
61+
"access_key_secret": "minio123",
62+
"checksum_algorithm": "SHA256"
63+
}`),
64+
},
65+
want: &S3Backend{
66+
objectPrefix: "path/to/my-registry/",
67+
bucketName: "nydus",
68+
endpointWithScheme: "http://localhost:9000",
69+
region: "us-east-1",
70+
accessKeySecret: "minio123",
71+
accessKeyID: "minio",
72+
checksumAlgorithm: types.ChecksumAlgorithmSha256,
4573
},
4674
wantErr: false,
4775
},

pkg/converter/constant.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ package converter
99
const (
1010
ManifestOSFeatureNydus = "nydus.remoteimage.v1"
1111
ManifestArtifactTypeNydus = "application/vnd.nydus.image.manifest.v1+json"
12+
ManifestConfigNydus = "application/vnd.nydus.image.config.v1+json"
1213
MediaTypeNydusBlob = "application/vnd.oci.image.layer.nydus.blob.v1"
1314
BootstrapFileNameInLayer = "image/image.boot"
1415

pkg/converter/convert_unix.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1041,6 +1041,12 @@ func convertManifest(ctx context.Context, cs content.Store, oldDesc ocispec.Desc
10411041
if err != nil {
10421042
return nil, errors.Wrap(err, "write image config")
10431043
}
1044+
// When manifests are merged, we need to put a special value for the config mediaType.
1045+
// This values must be one that containerd doesn't understand to ensure it doesn't try tu pull the nydus image
1046+
// but use the OCI one instead. And then if the nydus-snapshotter is used, it can pull the nydus image instead.
1047+
if opt.MergeManifest {
1048+
newConfigDesc.MediaType = ManifestConfigNydus
1049+
}
10441050
manifest.Config = *newConfigDesc
10451051
// Update the config gc label
10461052
manifestLabels[configGCLabelKey] = newConfigDesc.Digest.String()

pkg/converter/types.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,9 @@ type MergeOption struct {
127127
Encrypt Encrypter
128128
// AppendFiles specifies the files that need to be appended to the bootstrap layer.
129129
AppendFiles []File
130+
// MergeManifest indicates that the resulting nydus manifest will be merged with the original
131+
// OCI one into a single index manifest.
132+
MergeManifest bool
130133
}
131134

132135
type UnpackOption struct {

0 commit comments

Comments
 (0)