Enable to propagate necessary information to snapshotter during unpack

Though containerd gives ChainID to backend snapshotters during unpack for
searching snapshots to be skipped downloading the contents, ChainID isn't enough
for some snapshotters which require additional information of layers.
Some examples are remote snapshotters which is based on stargz filesystem
(requires image-related information to query the contents to docker registry)
and those which is based on CernVM-FS (requires manifest digest, etc. for
providing squashed rootfs).

This commit solves this issue by enabling a handler to inject additional
information of layers to snapshotters during unpack.

Signed-off-by: Kohei Tokunaga <ktokunaga.mail@gmail.com>
This commit is contained in:
Kohei Tokunaga 2019-12-23 10:39:40 +09:00
parent 97712c8ad7
commit 4ccb7aa221
2 changed files with 17 additions and 4 deletions

View File

@ -81,7 +81,7 @@ func (c *Client) Pull(ctx context.Context, ref string, opts ...RemoteOpt) (_ Ima
if wrapper == nil {
return unpackWrapper(h)
}
return wrapper(unpackWrapper(h))
return unpackWrapper(wrapper(h))
}
}

View File

@ -22,6 +22,7 @@ import (
"encoding/json"
"fmt"
"math/rand"
"strings"
"sync"
"sync/atomic"
"time"
@ -41,6 +42,11 @@ import (
"golang.org/x/sync/semaphore"
)
const (
inheritedLabelsPrefix = "containerd.io/snapshot/"
labelSnapshotRef = "containerd.io/snapshot.ref"
)
type unpacker struct {
updateCh chan ocispec.Descriptor
snapshotter string
@ -113,9 +119,16 @@ EachLayer:
return errors.Wrapf(err, "failed to stat snapshot %s", chainID)
}
labelOpt := snapshots.WithLabels(map[string]string{
"containerd.io/snapshot.ref": chainID,
})
// filters the provided annotations by removing any key which isn't a snapshot
// label. Snapshot labels have a prefix of "containerd.io/snapshot/".
labels := make(map[string]string)
for k, v := range desc.Annotations {
if strings.HasPrefix(k, inheritedLabelsPrefix) {
labels[k] = v
}
}
labels[labelSnapshotRef] = chainID
labelOpt := snapshots.WithLabels(labels)
var (
key string