Containerd client integration
This commit: 1) Replaces the usage of containerd GRPC APIs with the containerd client for all operations related to containerd. 2) Updated containerd to v1.0alpha4+ 3) Updated runc to v1.0.0 Signed-off-by: Abhinandan Prativadi <abhi@docker.com>
This commit is contained in:
@@ -17,14 +17,11 @@ limitations under the License.
|
||||
package server
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/containerd/containerd"
|
||||
"github.com/containerd/containerd/containers"
|
||||
prototypes "github.com/gogo/protobuf/types"
|
||||
"github.com/golang/glog"
|
||||
imagespec "github.com/opencontainers/image-spec/specs-go/v1"
|
||||
"github.com/opencontainers/runc/libcontainer/devices"
|
||||
@@ -94,29 +91,15 @@ func (c *criContainerdService) CreateContainer(ctx context.Context, r *runtime.C
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to generate container %q spec: %v", id, err)
|
||||
}
|
||||
rawSpec, err := json.Marshal(spec)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to marshal oci spec %+v: %v", spec, err)
|
||||
}
|
||||
glog.V(4).Infof("Container spec: %+v", spec)
|
||||
|
||||
var opts []containerd.NewContainerOpts
|
||||
// Prepare container rootfs.
|
||||
if config.GetLinux().GetSecurityContext().GetReadonlyRootfs() {
|
||||
if _, err := c.snapshotService.View(ctx, id, image.ChainID); err != nil {
|
||||
return nil, fmt.Errorf("failed to view container rootfs %q: %v", image.ChainID, err)
|
||||
}
|
||||
opts = append(opts, containerd.WithNewSnapshotView(id, image.Image))
|
||||
} else {
|
||||
if _, err := c.snapshotService.Prepare(ctx, id, image.ChainID); err != nil {
|
||||
return nil, fmt.Errorf("failed to prepare container rootfs %q: %v", image.ChainID, err)
|
||||
}
|
||||
opts = append(opts, containerd.WithNewSnapshot(id, image.Image))
|
||||
}
|
||||
defer func() {
|
||||
if retErr != nil {
|
||||
if err := c.snapshotService.Remove(ctx, id); err != nil {
|
||||
glog.Errorf("Failed to remove container snapshot %q: %v", id, err)
|
||||
}
|
||||
}
|
||||
}()
|
||||
meta.ImageRef = image.ID
|
||||
|
||||
// Create container root directory.
|
||||
@@ -135,29 +118,22 @@ func (c *criContainerdService) CreateContainer(ctx context.Context, r *runtime.C
|
||||
}
|
||||
}()
|
||||
|
||||
// Create containerd container.
|
||||
if _, err = c.containerService.Create(ctx, containers.Container{
|
||||
ID: id,
|
||||
// TODO(random-liu): Checkpoint metadata into container labels.
|
||||
Image: image.ID,
|
||||
Runtime: containers.RuntimeInfo{Name: defaultRuntime},
|
||||
Spec: &prototypes.Any{
|
||||
TypeUrl: runtimespec.Version,
|
||||
Value: rawSpec,
|
||||
},
|
||||
RootFS: id,
|
||||
}); err != nil {
|
||||
opts = append(opts, containerd.WithSpec(spec), containerd.WithRuntime(defaultRuntime))
|
||||
var cntr containerd.Container
|
||||
if cntr, err = c.client.NewContainer(ctx, id, opts...); err != nil {
|
||||
return nil, fmt.Errorf("failed to create containerd container: %v", err)
|
||||
}
|
||||
defer func() {
|
||||
if retErr != nil {
|
||||
if err := c.containerService.Delete(ctx, id); err != nil {
|
||||
if err := cntr.Delete(ctx, containerd.WithSnapshotCleanup); err != nil {
|
||||
glog.Errorf("Failed to delete containerd container %q: %v", id, err)
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
container, err := containerstore.NewContainer(meta, containerstore.Status{CreatedAt: time.Now().UnixNano()})
|
||||
container, err := containerstore.NewContainer(meta,
|
||||
containerstore.Status{CreatedAt: time.Now().UnixNano()},
|
||||
containerstore.WithContainer(cntr))
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to create internal container object for %q: %v",
|
||||
id, err)
|
||||
|
Reference in New Issue
Block a user