@@ -58,6 +58,7 @@ const (
58
58
labelOverlayBDBlobWritable = "containerd.io/snapshot/overlaybd.writable"
59
59
labelKeyAccelerationLayer = "containerd.io/snapshot/overlaybd/acceleration-layer"
60
60
labelBuildLayerFrom = "containerd.io/snapshot/overlaybd/build.layer-from"
61
+ labelKeyZFileConfig = "containerd.io/snapshot/overlaybd/zfile-config"
61
62
labelDistributionSource = "containerd.io/distribution.source"
62
63
)
63
64
70
71
convContentNameFormat = convSnapshotNameFormat
71
72
)
72
73
74
+ type ZFileConfig struct {
75
+ Algorithm string `json:"algorithm"`
76
+ BlockSize int `json:"blockSize"`
77
+ }
78
+
73
79
type ImageConvertor interface {
74
80
Convert (ctx context.Context , srcManifest ocispec.Manifest , fsType string ) (ocispec.Descriptor , error )
75
81
}
@@ -187,21 +193,23 @@ func (loader *contentLoader) Load(ctx context.Context, cs content.Store) (l laye
187
193
188
194
type overlaybdConvertor struct {
189
195
ImageConvertor
190
- cs content.Store
191
- sn snapshots.Snapshotter
192
- remote bool
193
- fetcher remotes.Fetcher
194
- pusher remotes.Pusher
195
- db * sql.DB
196
- host string
197
- repo string
196
+ cs content.Store
197
+ sn snapshots.Snapshotter
198
+ remote bool
199
+ fetcher remotes.Fetcher
200
+ pusher remotes.Pusher
201
+ db * sql.DB
202
+ host string
203
+ repo string
204
+ zfileCfg ZFileConfig
198
205
}
199
206
200
- func NewOverlaybdConvertor (ctx context.Context , cs content.Store , sn snapshots.Snapshotter , resolver remotes.Resolver , ref string , dbstr string ) (ImageConvertor , error ) {
207
+ func NewOverlaybdConvertor (ctx context.Context , cs content.Store , sn snapshots.Snapshotter , resolver remotes.Resolver , ref string , dbstr string , zfileCfg ZFileConfig ) (ImageConvertor , error ) {
201
208
c := & overlaybdConvertor {
202
- cs : cs ,
203
- sn : sn ,
204
- remote : false ,
209
+ cs : cs ,
210
+ sn : sn ,
211
+ remote : false ,
212
+ zfileCfg : zfileCfg ,
205
213
}
206
214
var err error
207
215
if dbstr != "" {
@@ -505,6 +513,13 @@ func (c *overlaybdConvertor) convertLayers(ctx context.Context, srcDescs []ocisp
505
513
labelOverlayBDBlobFsType : fsType ,
506
514
}),
507
515
}
516
+ cfgStr , err := json .Marshal (c .zfileCfg )
517
+ if err != nil {
518
+ return nil , err
519
+ }
520
+ opts = append (opts , snapshots .WithLabels (map [string ]string {
521
+ labelKeyZFileConfig : string (cfgStr ),
522
+ }))
508
523
lastParentID , err = c .applyOCIV1LayerInZfile (ctx , lastParentID , desc , opts , nil )
509
524
if err != nil {
510
525
return nil , err
@@ -606,7 +621,7 @@ func (c *overlaybdConvertor) applyOCIV1LayerInZfile(
606
621
}
607
622
608
623
commitID := fmt .Sprintf (convSnapshotNameFormat , digester .Digest ())
609
- if err = c .sn .Commit (ctx , commitID , key ); err != nil {
624
+ if err = c .sn .Commit (ctx , commitID , key , snOpts ... ); err != nil {
610
625
if ! errdefs .IsAlreadyExists (err ) {
611
626
return emptyString , err
612
627
}
@@ -638,11 +653,13 @@ func (wc *writeCountWrapper) Write(p []byte) (n int, err error) {
638
653
639
654
// NOTE: based on https://github.com/containerd/containerd/blob/v1.6.8/images/converter/converter.go#L29-L71
640
655
type options struct {
641
- fsType string
642
- dbstr string
643
- imgRef string
644
- resolver remotes.Resolver
645
- client * containerd.Client
656
+ fsType string
657
+ dbstr string
658
+ imgRef string
659
+ algorithm string
660
+ blockSize int
661
+ resolver remotes.Resolver
662
+ client * containerd.Client
646
663
}
647
664
648
665
type Option func (o * options ) error
@@ -668,6 +685,20 @@ func WithImageRef(imgRef string) Option {
668
685
}
669
686
}
670
687
688
+ func WithAlgorithm (algorithm string ) Option {
689
+ return func (o * options ) error {
690
+ o .algorithm = algorithm
691
+ return nil
692
+ }
693
+ }
694
+
695
+ func WithBlockSize (blockSize int ) Option {
696
+ return func (o * options ) error {
697
+ o .blockSize = blockSize
698
+ return nil
699
+ }
700
+ }
701
+
671
702
func WithResolver (resolver remotes.Resolver ) Option {
672
703
return func (o * options ) error {
673
704
o .resolver = resolver
@@ -703,8 +734,11 @@ func IndexConvertFunc(opts ...Option) converter.ConvertFunc {
703
734
if err != nil {
704
735
return nil , errors .Wrapf (err , "failed to read manifest" )
705
736
}
706
-
707
- c , err := NewOverlaybdConvertor (ctx , cs , sn , copts .resolver , imgRef , copts .dbstr )
737
+ zfileCfg := ZFileConfig {
738
+ Algorithm : copts .algorithm ,
739
+ BlockSize : copts .blockSize ,
740
+ }
741
+ c , err := NewOverlaybdConvertor (ctx , cs , sn , copts .resolver , imgRef , copts .dbstr , zfileCfg )
708
742
if err != nil {
709
743
return nil , err
710
744
}
0 commit comments