Fix sandbox container snapshotter.

Signed-off-by: Lantao Liu <lantaol@google.com>
This commit is contained in:
Lantao Liu
2017-08-30 18:33:49 +00:00
parent 2aea0388be
commit c4d95aa2c4
6 changed files with 30 additions and 11 deletions

View File

@@ -92,7 +92,10 @@ func (c *criContainerdService) CreateContainer(ctx context.Context, r *runtime.C
}
glog.V(4).Infof("Container spec: %+v", spec)
var opts []containerd.NewContainerOpts
// Set snapshotter before any other options.
opts := []containerd.NewContainerOpts{
containerd.WithSnapshotter(c.snapshotter),
}
// Prepare container rootfs.
if config.GetLinux().GetSecurityContext().GetReadonlyRootfs() {
opts = append(opts, containerd.WithNewSnapshotView(id, image.Image))

View File

@@ -91,7 +91,12 @@ func (c *criContainerdService) PullImage(ctx context.Context, r *runtime.PullIma
})
// TODO(mikebrow): add truncIndex for image id
image, err := c.client.Pull(ctx, ref, containerd.WithPullUnpack, containerd.WithSchema1Conversion, containerd.WithResolver(resolver))
image, err := c.client.Pull(ctx, ref,
containerd.WithPullUnpack,
containerd.WithSchema1Conversion,
containerd.WithResolver(resolver),
containerd.WithPullSnapshotter(c.snapshotter),
)
if err != nil {
return nil, fmt.Errorf("failed to pull image %q: %v", ref, err)
}

View File

@@ -131,10 +131,11 @@ func (c *criContainerdService) RunPodSandbox(ctx context.Context, r *runtime.Run
specOpts = append(specOpts, containerd.WithUserID(uint32(uid.GetValue())))
}
opts := []containerd.NewContainerOpts{
containerd.WithSnapshotter(c.snapshotter),
containerd.WithNewSnapshotView(id, image.Image),
containerd.WithSpec(spec, specOpts...),
containerd.WithContainerLabels(labels),
containerd.WithRuntime(defaultRuntime),
containerd.WithNewSnapshotView(id, image.Image)}
containerd.WithRuntime(defaultRuntime)}
container, err := c.client.NewContainer(ctx, id, opts...)
if err != nil {
return nil, fmt.Errorf("failed to create containerd container: %v", err)

View File

@@ -55,6 +55,8 @@ type criContainerdService struct {
// sandboxImage is the image to use for sandbox container.
// TODO(random-liu): Make this configurable via flag.
sandboxImage string
// snapshotter is the snapshotter to use in containerd.
snapshotter string
// sandboxStore stores all resources associated with sandboxes.
sandboxStore *sandboxstore.Store
// sandboxNameIndex stores all sandbox names and make sure each name
@@ -86,8 +88,14 @@ type criContainerdService struct {
// NewCRIContainerdService returns a new instance of CRIContainerdService
// TODO(random-liu): Add cri-containerd server config to get rid of the long arg list.
func NewCRIContainerdService(containerdEndpoint, rootDir, networkPluginBinDir, networkPluginConfDir,
streamAddress, streamPort string) (CRIContainerdService, error) {
func NewCRIContainerdService(
containerdEndpoint,
containerdSnapshotter,
rootDir,
networkPluginBinDir,
networkPluginConfDir,
streamAddress,
streamPort string) (CRIContainerdService, error) {
// TODO(random-liu): [P2] Recover from runtime state and checkpoint.
client, err := containerd.New(containerdEndpoint, containerd.WithDefaultNamespace(k8sContainerdNamespace))
@@ -99,6 +107,7 @@ func NewCRIContainerdService(containerdEndpoint, rootDir, networkPluginBinDir, n
os: osinterface.RealOS{},
rootDir: rootDir,
sandboxImage: defaultSandboxImage,
snapshotter: containerdSnapshotter,
sandboxStore: sandboxstore.NewStore(),
containerStore: containerstore.NewStore(),
imageStore: imagestore.NewStore(),