@@ -34,6 +34,10 @@ import (
3434 bolt "go.etcd.io/bbolt"
3535)
3636
37+ const (
38+ inheritedLabelsPrefix = "containerd.io/snapshot/"
39+ )
40+
3741type snapshotter struct {
3842 snapshots.Snapshotter
3943 name string
@@ -338,12 +342,14 @@ func (s *snapshotter) createSnapshot(ctx context.Context, key, parent string, re
338342 return err
339343 }
340344
345+ inheritedOpt := snapshots .WithLabels (filterInheritedLabels (base .Labels ))
346+
341347 // TODO: Consider doing this outside of transaction to lessen
342348 // metadata lock time
343349 if readonly {
344- m , err = s .Snapshotter .View (ctx , bkey , bparent )
350+ m , err = s .Snapshotter .View (ctx , bkey , bparent , inheritedOpt )
345351 } else {
346- m , err = s .Snapshotter .Prepare (ctx , bkey , bparent )
352+ m , err = s .Snapshotter .Prepare (ctx , bkey , bparent , inheritedOpt )
347353 }
348354 return err
349355 }); err != nil {
@@ -445,9 +451,11 @@ func (s *snapshotter) Commit(ctx context.Context, name, key string, opts ...snap
445451 return err
446452 }
447453
454+ inheritedOpt := snapshots .WithLabels (filterInheritedLabels (base .Labels ))
455+
448456 // TODO: Consider doing this outside of transaction to lessen
449457 // metadata lock time
450- return s .Snapshotter .Commit (ctx , nameKey , bkey )
458+ return s .Snapshotter .Commit (ctx , nameKey , bkey , inheritedOpt )
451459 })
452460
453461}
@@ -761,3 +769,19 @@ func (s *snapshotter) pruneBranch(ctx context.Context, node *treeNode) error {
761769func (s * snapshotter ) Close () error {
762770 return s .Snapshotter .Close ()
763771}
772+
773+ // filterInheritedLabels filters the provided labels by removing any key which doesn't have
774+ // a prefix of "containerd.io/snapshot/".
775+ func filterInheritedLabels (labels map [string ]string ) map [string ]string {
776+ if labels == nil {
777+ return nil
778+ }
779+
780+ filtered := make (map [string ]string )
781+ for k , v := range labels {
782+ if strings .HasPrefix (k , inheritedLabelsPrefix ) {
783+ filtered [k ] = v
784+ }
785+ }
786+ return filtered
787+ }
0 commit comments