Skip to content

Commit 287a45b

Browse files
committed
[nydus] Add annotation to indicate empty layer
Set the annotation`containerd.io/snapshot/nydus-empty-layer: "true"` on the empty layer that's added in the OCI image. Just to be able to find it easily.
1 parent 7413411 commit 287a45b

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

pkg/driver/nydus/nydus.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ const (
5757
annotationSourceDigest = "containerd.io/snapshot/nydus-source-digest"
5858
// annotationSourceReference indicates the source OCI image reference name.
5959
annotationSourceReference = "containerd.io/snapshot/nydus-source-reference"
60+
// annotationEmptyLayer indicates that the layer is an empty layer added by nydus that won't change the final image's content.
61+
annotationEmptyLayer = "containerd.io/snapshot/nydus-empty-layer"
6062
// annotationFsVersion indicates the fs version (rafs v5/v6) of nydus image.
6163
annotationFsVersion = "containerd.io/snapshot/nydus-fs-version"
6264
// annotationBuilderVersion indicates the nydus builder (nydus-image) version.
@@ -487,9 +489,10 @@ func PrependEmptyLayer(ctx context.Context, cs content.Store, manifestDesc ocisp
487489
}
488490
emptyDescriptorBytes := generateDockerEmptyLayer()
489491
emptyDescriptor := ocispec.Descriptor{
490-
MediaType: emptyLayerMediaType,
491-
Digest: digest.FromBytes(emptyDescriptorBytes),
492-
Size: int64(len(emptyDescriptorBytes)),
492+
Annotations: map[string]string{annotationEmptyLayer: "true"},
493+
MediaType: emptyLayerMediaType,
494+
Digest: digest.FromBytes(emptyDescriptorBytes),
495+
Size: int64(len(emptyDescriptorBytes)),
493496
}
494497

495498
manifest.Layers = append([]ocispec.Descriptor{emptyDescriptor}, manifest.Layers...)

pkg/driver/nydus/nydus_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,7 @@ func verifyPrependResults(ctx context.Context, t *testing.T, cs content.Store, o
257257
expectedEmptyDigest := "sha256:4f4fb700ef54461cfa02571ae0db9a0dc1e0cdb5577484a6d75e68dc38e8acc1"
258258
assert.Equal(t, expectedEmptyDigest, emptyLayer.Digest.String(), "empty layer digest should match expected")
259259
assert.Equal(t, int64(32), emptyLayer.Size, "empty layer size should be 32 bytes")
260+
assert.Equal(t, "true", emptyLayer.Annotations[annotationEmptyLayer], "empty layer annotation should be set to true")
260261

261262
// Verify media types based on the original manifest type
262263
var expectedEmptyLayerMediaType, expectedconfigDescriptorMediaType string

0 commit comments

Comments
 (0)