Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add overlaybd support #603

Merged
merged 1 commit into from
Dec 9, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 23 additions & 6 deletions pkg/imgutil/imgutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
"github.com/containerd/containerd/platforms"
refdocker "github.com/containerd/containerd/reference/docker"
"github.com/containerd/containerd/remotes"
"github.com/containerd/containerd/snapshots"
"github.com/containerd/imgcrypt"
"github.com/containerd/imgcrypt/images/encryption"
"github.com/containerd/nerdctl/pkg/idutil/imagewalker"
Expand All @@ -47,7 +48,7 @@ type EnsuredImage struct {
Image containerd.Image
ImageConfig ocispec.ImageConfig
Snapshotter string
Remote bool // true for stargz
Remote bool // true for stargz or overlaybd
}

// PullMode is either one of "always", "missing", "never"
Expand All @@ -74,7 +75,7 @@ func GetExistingImage(ctx context.Context, client *containerd.Client, snapshotte
Image: image,
ImageConfig: *imgConfig,
Snapshotter: snapshotter,
Remote: isStargz(snapshotter),
Remote: isStargz(snapshotter) || isOverlaybd(snapshotter),
}
if unpacked, err := image.IsUnpacked(ctx, snapshotter); err == nil && !unpacked {
if err := image.Unpack(ctx, snapshotter); err != nil {
Expand Down Expand Up @@ -107,7 +108,6 @@ func EnsureImage(ctx context.Context, client *containerd.Client, stdout, stderr
default:
return nil, fmt.Errorf("unexpected pull mode: %q", mode)
}

if mode != "always" && len(ocispecPlatforms) == 1 {
res, err := GetExistingImage(ctx, client, snapshotter, rawRef, ocispecPlatforms[0])
if err == nil {
Expand Down Expand Up @@ -196,14 +196,13 @@ func PullImage(ctx context.Context, client *containerd.Client, stdout, stderr io
unpackB = len(ocispecPlatforms) == 1
}

var sgz bool
var sgz, overlaybd bool
if unpackB {
logrus.Debugf("The image will be unpacked for platform %q, snapshotter %q.", ocispecPlatforms[0], snapshotter)
imgcryptPayload := imgcrypt.Payload{}
imgcryptUnpackOpt := encryption.WithUnpackConfigApplyOpts(encryption.WithDecryptedUnpack(&imgcryptPayload))
config.RemoteOpts = append(config.RemoteOpts,
containerd.WithPullUnpack,
containerd.WithPullSnapshotter(snapshotter),
containerd.WithUnpackOpts([]containerd.UnpackOpt{imgcryptUnpackOpt}))

sgz = isStargz(snapshotter)
Expand All @@ -214,6 +213,20 @@ func PullImage(ctx context.Context, client *containerd.Client, stdout, stderr io
containerd.WithImageHandlerWrapper(source.AppendDefaultLabelsHandlerWrapper(ref, 10*1024*1024)),
)
}
overlaybd = isOverlaybd(snapshotter)
if overlaybd {
snlabel := map[string]string{"containerd.io/snapshot/image-ref": ref}
logrus.Debugf("append remote opts: %s", snlabel)

config.RemoteOpts = append(
config.RemoteOpts,
containerd.WithPullSnapshotter(snapshotter, snapshots.WithLabels(snlabel)),
)
} else {
config.RemoteOpts = append(
config.RemoteOpts,
containerd.WithPullSnapshotter(snapshotter))
}
} else {
logrus.Debugf("The image will not be unpacked. Platforms=%v.", ocispecPlatforms)
}
Expand All @@ -230,7 +243,7 @@ func PullImage(ctx context.Context, client *containerd.Client, stdout, stderr io
Image: containerdImage,
ImageConfig: *imgConfig,
Snapshotter: snapshotter,
Remote: sgz,
Remote: (sgz || overlaybd),
}
return res, nil

Expand All @@ -246,6 +259,10 @@ func isStargz(sn string) bool {
return true
}

func isOverlaybd(sn string) bool {
return sn == "overlaybd"
}

func getImageConfig(ctx context.Context, image containerd.Image) (*ocispec.ImageConfig, error) {
desc, err := image.Config(ctx)
if err != nil {
Expand Down