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:
parent
97712c8ad7
commit
4ccb7aa221
2
pull.go
2
pull.go
@ -81,7 +81,7 @@ func (c *Client) Pull(ctx context.Context, ref string, opts ...RemoteOpt) (_ Ima
|
|||||||
if wrapper == nil {
|
if wrapper == nil {
|
||||||
return unpackWrapper(h)
|
return unpackWrapper(h)
|
||||||
}
|
}
|
||||||
return wrapper(unpackWrapper(h))
|
return unpackWrapper(wrapper(h))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
19
unpacker.go
19
unpacker.go
@ -22,6 +22,7 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
"time"
|
"time"
|
||||||
@ -41,6 +42,11 @@ import (
|
|||||||
"golang.org/x/sync/semaphore"
|
"golang.org/x/sync/semaphore"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
inheritedLabelsPrefix = "containerd.io/snapshot/"
|
||||||
|
labelSnapshotRef = "containerd.io/snapshot.ref"
|
||||||
|
)
|
||||||
|
|
||||||
type unpacker struct {
|
type unpacker struct {
|
||||||
updateCh chan ocispec.Descriptor
|
updateCh chan ocispec.Descriptor
|
||||||
snapshotter string
|
snapshotter string
|
||||||
@ -113,9 +119,16 @@ EachLayer:
|
|||||||
return errors.Wrapf(err, "failed to stat snapshot %s", chainID)
|
return errors.Wrapf(err, "failed to stat snapshot %s", chainID)
|
||||||
}
|
}
|
||||||
|
|
||||||
labelOpt := snapshots.WithLabels(map[string]string{
|
// filters the provided annotations by removing any key which isn't a snapshot
|
||||||
"containerd.io/snapshot.ref": chainID,
|
// 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 (
|
var (
|
||||||
key string
|
key string
|
||||||
|
Loading…
Reference in New Issue
Block a user