Skip to content

Commit 7aff8e4

Browse files
authored
Merge pull request #603 from BigVan/support_overlaybd
Add overlaybd support
2 parents 540dbd4 + 2be1cd9 commit 7aff8e4

File tree

1 file changed

+23
-6
lines changed

1 file changed

+23
-6
lines changed

pkg/imgutil/imgutil.go

+23-6
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import (
3030
"github.com/containerd/containerd/platforms"
3131
refdocker "github.com/containerd/containerd/reference/docker"
3232
"github.com/containerd/containerd/remotes"
33+
"github.com/containerd/containerd/snapshots"
3334
"github.com/containerd/imgcrypt"
3435
"github.com/containerd/imgcrypt/images/encryption"
3536
"github.com/containerd/nerdctl/pkg/idutil/imagewalker"
@@ -47,7 +48,7 @@ type EnsuredImage struct {
4748
Image containerd.Image
4849
ImageConfig ocispec.ImageConfig
4950
Snapshotter string
50-
Remote bool // true for stargz
51+
Remote bool // true for stargz or overlaybd
5152
}
5253

5354
// PullMode is either one of "always", "missing", "never"
@@ -74,7 +75,7 @@ func GetExistingImage(ctx context.Context, client *containerd.Client, snapshotte
7475
Image: image,
7576
ImageConfig: *imgConfig,
7677
Snapshotter: snapshotter,
77-
Remote: isStargz(snapshotter),
78+
Remote: isStargz(snapshotter) || isOverlaybd(snapshotter),
7879
}
7980
if unpacked, err := image.IsUnpacked(ctx, snapshotter); err == nil && !unpacked {
8081
if err := image.Unpack(ctx, snapshotter); err != nil {
@@ -107,7 +108,6 @@ func EnsureImage(ctx context.Context, client *containerd.Client, stdout, stderr
107108
default:
108109
return nil, fmt.Errorf("unexpected pull mode: %q", mode)
109110
}
110-
111111
if mode != "always" && len(ocispecPlatforms) == 1 {
112112
res, err := GetExistingImage(ctx, client, snapshotter, rawRef, ocispecPlatforms[0])
113113
if err == nil {
@@ -198,14 +198,13 @@ func PullImage(ctx context.Context, client *containerd.Client, stdout, stderr io
198198
unpackB = len(ocispecPlatforms) == 1
199199
}
200200

201-
var sgz bool
201+
var sgz, overlaybd bool
202202
if unpackB {
203203
logrus.Debugf("The image will be unpacked for platform %q, snapshotter %q.", ocispecPlatforms[0], snapshotter)
204204
imgcryptPayload := imgcrypt.Payload{}
205205
imgcryptUnpackOpt := encryption.WithUnpackConfigApplyOpts(encryption.WithDecryptedUnpack(&imgcryptPayload))
206206
config.RemoteOpts = append(config.RemoteOpts,
207207
containerd.WithPullUnpack,
208-
containerd.WithPullSnapshotter(snapshotter),
209208
containerd.WithUnpackOpts([]containerd.UnpackOpt{imgcryptUnpackOpt}))
210209

211210
sgz = isStargz(snapshotter)
@@ -216,6 +215,20 @@ func PullImage(ctx context.Context, client *containerd.Client, stdout, stderr io
216215
containerd.WithImageHandlerWrapper(source.AppendDefaultLabelsHandlerWrapper(ref, 10*1024*1024)),
217216
)
218217
}
218+
overlaybd = isOverlaybd(snapshotter)
219+
if overlaybd {
220+
snlabel := map[string]string{"containerd.io/snapshot/image-ref": ref}
221+
logrus.Debugf("append remote opts: %s", snlabel)
222+
223+
config.RemoteOpts = append(
224+
config.RemoteOpts,
225+
containerd.WithPullSnapshotter(snapshotter, snapshots.WithLabels(snlabel)),
226+
)
227+
} else {
228+
config.RemoteOpts = append(
229+
config.RemoteOpts,
230+
containerd.WithPullSnapshotter(snapshotter))
231+
}
219232
} else {
220233
logrus.Debugf("The image will not be unpacked. Platforms=%v.", ocispecPlatforms)
221234
}
@@ -232,7 +245,7 @@ func PullImage(ctx context.Context, client *containerd.Client, stdout, stderr io
232245
Image: containerdImage,
233246
ImageConfig: *imgConfig,
234247
Snapshotter: snapshotter,
235-
Remote: sgz,
248+
Remote: (sgz || overlaybd),
236249
}
237250
return res, nil
238251

@@ -248,6 +261,10 @@ func isStargz(sn string) bool {
248261
return true
249262
}
250263

264+
func isOverlaybd(sn string) bool {
265+
return sn == "overlaybd"
266+
}
267+
251268
func getImageConfig(ctx context.Context, image containerd.Image) (*ocispec.ImageConfig, error) {
252269
desc, err := image.Config(ctx)
253270
if err != nil {

0 commit comments

Comments
 (0)