Skip to content

Commit

Permalink
nydusify: add fs-version annotation
Browse files Browse the repository at this point in the history
Add an annotation to the image manifest for detecting the bootstrap fs
version without reading the magic number from bootstrap.

fix dragonflyoss#496

Signed-off-by: Qi Wang <wangqi@linux.alibaba.com>
  • Loading branch information
yawqi committed Jun 15, 2022
1 parent 3d3ac61 commit ae23437
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 2 deletions.
2 changes: 2 additions & 0 deletions contrib/nydusify/pkg/cache/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ func (cache *Cache) recordToLayer(record *Record) (*ocispec.Descriptor, *ocispec
Size: record.NydusBootstrapDesc.Size,
Annotations: map[string]string{
utils.LayerAnnotationNydusBootstrap: "true",
utils.LayerAnnotationNydusFsVersion: cache.opt.Version,
utils.LayerAnnotationNydusSourceChainID: record.SourceChainID.String(),
// Use the annotation to record bootstrap layer DiffID.
utils.LayerAnnotationUncompressed: record.NydusBootstrapDiffID.String(),
Expand Down Expand Up @@ -230,6 +231,7 @@ func (cache *Cache) layerToRecord(layer *ocispec.Descriptor) *Record {
Size: layer.Size,
Annotations: map[string]string{
utils.LayerAnnotationNydusBootstrap: "true",
utils.LayerAnnotationNydusFsVersion: cache.opt.Version,
utils.LayerAnnotationUncompressed: uncompressedDigestStr,
},
}
Expand Down
2 changes: 2 additions & 0 deletions contrib/nydusify/pkg/cache/cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ func makeBootstrapLayer(id int64, hasBlob bool) ocispec.Descriptor {
Size: id,
Annotations: map[string]string{
utils.LayerAnnotationNydusBootstrap: "true",
utils.LayerAnnotationNydusFsVersion: "6",
utils.LayerAnnotationNydusSourceChainID: digest.FromString("chain-" + idStr).String(),
utils.LayerAnnotationUncompressed: digest.FromString("bootstrap-uncompressed-" + idStr).String(),
},
Expand Down Expand Up @@ -76,6 +77,7 @@ func testWithBackend(t *testing.T, _backend backend.Backend) {
MaxRecords: 3,
DockerV2Format: false,
Backend: _backend,
FsVersion: "6",
})
assert.Nil(t, err)

Expand Down
1 change: 1 addition & 0 deletions contrib/nydusify/pkg/converter/converter.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,7 @@ func (cvt *Converter) convert(ctx context.Context) (retErr error) {
forcePush: cvt.BackendForcePush,
alignedChunk: cvt.BackendAlignedChunk,
referenceBlobs: blobLayers,
fsVersion: cvt.FsVersion,
}
parentBuildLayer = buildLayer
buildLayers = append(buildLayers, buildLayer)
Expand Down
5 changes: 3 additions & 2 deletions contrib/nydusify/pkg/converter/layer.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ type buildLayer struct {
backend backend.Backend
forcePush bool
alignedChunk bool

referenceBlobs []ocispec.Descriptor
fsVersion string
referenceBlobs []ocispec.Descriptor
}

// parseSourceMount parses mounts object returned by the Mount method in
Expand Down Expand Up @@ -159,6 +159,7 @@ func (layer *buildLayer) pushBootstrap(ctx context.Context) (*ocispec.Descriptor
// DiffID of layer defined in OCI spec
utils.LayerAnnotationUncompressed: uncompressedDigest.String(),
utils.LayerAnnotationNydusBootstrap: "true",
utils.LayerAnnotationNydusFsVersion: layer.fsVersion,
},
}
if len(layer.referenceBlobs) > 0 {
Expand Down
1 change: 1 addition & 0 deletions contrib/nydusify/pkg/converter/manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@ func (mm *manifestManager) Push(ctx context.Context, buildLayers []*buildLayer)
utils.LayerAnnotationNydusBlobIDs: true,
utils.LayerAnnotationNydusReferenceBlobIDs: true,
utils.LayerAnnotationNydusBootstrap: true,
utils.LayerAnnotationNydusFsVersion: true,
}
for idx, desc := range layers {
layerDiffID := digest.Digest(desc.Annotations[utils.LayerAnnotationUncompressed])
Expand Down
1 change: 1 addition & 0 deletions contrib/nydusify/pkg/utils/constant.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const (
LayerAnnotationNydusBlobSize = "containerd.io/snapshot/nydus-blob-size"
LayerAnnotationNydusBlobIDs = "containerd.io/snapshot/nydus-blob-ids"
LayerAnnotationNydusBootstrap = "containerd.io/snapshot/nydus-bootstrap"
LayerAnnotationNydusFsVersion = "containerd.io/snapshot/nydus-fs-version"
LayerAnnotationNydusSourceChainID = "containerd.io/snapshot/nydus-source-chainid"

LayerAnnotationNydusReferenceBlobIDs = "containerd.io/snapshot/nydus-reference-blob-ids"
Expand Down

0 comments on commit ae23437

Please sign in to comment.