Use typeurl package for spec types

Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
This commit is contained in:
Michael Crosby 2017-07-05 15:11:59 -07:00
parent f8720382b3
commit a60511d5aa
22 changed files with 163 additions and 264 deletions

View File

@ -72,11 +72,10 @@ type Task struct {
ContainerID string `protobuf:"bytes,2,opt,name=container_id,json=containerId,proto3" json:"container_id,omitempty"`
Pid uint32 `protobuf:"varint,3,opt,name=pid,proto3" json:"pid,omitempty"`
Status Status `protobuf:"varint,4,opt,name=status,proto3,enum=containerd.v1.types.Status" json:"status,omitempty"`
Spec *google_protobuf1.Any `protobuf:"bytes,5,opt,name=spec" json:"spec,omitempty"`
Stdin string `protobuf:"bytes,6,opt,name=stdin,proto3" json:"stdin,omitempty"`
Stdout string `protobuf:"bytes,7,opt,name=stdout,proto3" json:"stdout,omitempty"`
Stderr string `protobuf:"bytes,8,opt,name=stderr,proto3" json:"stderr,omitempty"`
Terminal bool `protobuf:"varint,9,opt,name=terminal,proto3" json:"terminal,omitempty"`
Stdin string `protobuf:"bytes,5,opt,name=stdin,proto3" json:"stdin,omitempty"`
Stdout string `protobuf:"bytes,6,opt,name=stdout,proto3" json:"stdout,omitempty"`
Stderr string `protobuf:"bytes,7,opt,name=stderr,proto3" json:"stderr,omitempty"`
Terminal bool `protobuf:"varint,8,opt,name=terminal,proto3" json:"terminal,omitempty"`
}
func (m *Task) Reset() { *m = Task{} }
@ -155,36 +154,26 @@ func (m *Task) MarshalTo(dAtA []byte) (int, error) {
i++
i = encodeVarintTask(dAtA, i, uint64(m.Status))
}
if m.Spec != nil {
dAtA[i] = 0x2a
i++
i = encodeVarintTask(dAtA, i, uint64(m.Spec.Size()))
n1, err := m.Spec.MarshalTo(dAtA[i:])
if err != nil {
return 0, err
}
i += n1
}
if len(m.Stdin) > 0 {
dAtA[i] = 0x32
dAtA[i] = 0x2a
i++
i = encodeVarintTask(dAtA, i, uint64(len(m.Stdin)))
i += copy(dAtA[i:], m.Stdin)
}
if len(m.Stdout) > 0 {
dAtA[i] = 0x3a
dAtA[i] = 0x32
i++
i = encodeVarintTask(dAtA, i, uint64(len(m.Stdout)))
i += copy(dAtA[i:], m.Stdout)
}
if len(m.Stderr) > 0 {
dAtA[i] = 0x42
dAtA[i] = 0x3a
i++
i = encodeVarintTask(dAtA, i, uint64(len(m.Stderr)))
i += copy(dAtA[i:], m.Stderr)
}
if m.Terminal {
dAtA[i] = 0x48
dAtA[i] = 0x40
i++
if m.Terminal {
dAtA[i] = 1
@ -250,11 +239,11 @@ func (m *Process) MarshalTo(dAtA []byte) (int, error) {
dAtA[i] = 0x22
i++
i = encodeVarintTask(dAtA, i, uint64(m.User.Size()))
n2, err := m.User.MarshalTo(dAtA[i:])
n1, err := m.User.MarshalTo(dAtA[i:])
if err != nil {
return 0, err
}
i += n2
i += n1
}
if len(m.Cwd) > 0 {
dAtA[i] = 0x2a
@ -286,11 +275,11 @@ func (m *Process) MarshalTo(dAtA []byte) (int, error) {
dAtA[i] = 0x4a
i++
i = encodeVarintTask(dAtA, i, uint64(m.RuntimeData.Size()))
n3, err := m.RuntimeData.MarshalTo(dAtA[i:])
n2, err := m.RuntimeData.MarshalTo(dAtA[i:])
if err != nil {
return 0, err
}
i += n3
i += n2
}
if len(m.Stdin) > 0 {
dAtA[i] = 0x52
@ -339,21 +328,21 @@ func (m *User) MarshalTo(dAtA []byte) (int, error) {
i = encodeVarintTask(dAtA, i, uint64(m.Gid))
}
if len(m.AdditionalGids) > 0 {
dAtA5 := make([]byte, len(m.AdditionalGids)*10)
var j4 int
dAtA4 := make([]byte, len(m.AdditionalGids)*10)
var j3 int
for _, num := range m.AdditionalGids {
for num >= 1<<7 {
dAtA5[j4] = uint8(uint64(num)&0x7f | 0x80)
dAtA4[j3] = uint8(uint64(num)&0x7f | 0x80)
num >>= 7
j4++
j3++
}
dAtA5[j4] = uint8(num)
j4++
dAtA4[j3] = uint8(num)
j3++
}
dAtA[i] = 0x1a
i++
i = encodeVarintTask(dAtA, i, uint64(j4))
i += copy(dAtA[i:], dAtA5[:j4])
i = encodeVarintTask(dAtA, i, uint64(j3))
i += copy(dAtA[i:], dAtA4[:j3])
}
return i, nil
}
@ -402,10 +391,6 @@ func (m *Task) Size() (n int) {
if m.Status != 0 {
n += 1 + sovTask(uint64(m.Status))
}
if m.Spec != nil {
l = m.Spec.Size()
n += 1 + l + sovTask(uint64(l))
}
l = len(m.Stdin)
if l > 0 {
n += 1 + l + sovTask(uint64(l))
@ -519,7 +504,6 @@ func (this *Task) String() string {
`ContainerID:` + fmt.Sprintf("%v", this.ContainerID) + `,`,
`Pid:` + fmt.Sprintf("%v", this.Pid) + `,`,
`Status:` + fmt.Sprintf("%v", this.Status) + `,`,
`Spec:` + strings.Replace(fmt.Sprintf("%v", this.Spec), "Any", "google_protobuf1.Any", 1) + `,`,
`Stdin:` + fmt.Sprintf("%v", this.Stdin) + `,`,
`Stdout:` + fmt.Sprintf("%v", this.Stdout) + `,`,
`Stderr:` + fmt.Sprintf("%v", this.Stderr) + `,`,
@ -695,39 +679,6 @@ func (m *Task) Unmarshal(dAtA []byte) error {
}
}
case 5:
if wireType != 2 {
return fmt.Errorf("proto: wrong wireType = %d for field Spec", wireType)
}
var msglen int
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowTask
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
msglen |= (int(b) & 0x7F) << shift
if b < 0x80 {
break
}
}
if msglen < 0 {
return ErrInvalidLengthTask
}
postIndex := iNdEx + msglen
if postIndex > l {
return io.ErrUnexpectedEOF
}
if m.Spec == nil {
m.Spec = &google_protobuf1.Any{}
}
if err := m.Spec.Unmarshal(dAtA[iNdEx:postIndex]); err != nil {
return err
}
iNdEx = postIndex
case 6:
if wireType != 2 {
return fmt.Errorf("proto: wrong wireType = %d for field Stdin", wireType)
}
@ -756,7 +707,7 @@ func (m *Task) Unmarshal(dAtA []byte) error {
}
m.Stdin = string(dAtA[iNdEx:postIndex])
iNdEx = postIndex
case 7:
case 6:
if wireType != 2 {
return fmt.Errorf("proto: wrong wireType = %d for field Stdout", wireType)
}
@ -785,7 +736,7 @@ func (m *Task) Unmarshal(dAtA []byte) error {
}
m.Stdout = string(dAtA[iNdEx:postIndex])
iNdEx = postIndex
case 8:
case 7:
if wireType != 2 {
return fmt.Errorf("proto: wrong wireType = %d for field Stderr", wireType)
}
@ -814,7 +765,7 @@ func (m *Task) Unmarshal(dAtA []byte) error {
}
m.Stderr = string(dAtA[iNdEx:postIndex])
iNdEx = postIndex
case 9:
case 8:
if wireType != 0 {
return fmt.Errorf("proto: wrong wireType = %d for field Terminal", wireType)
}
@ -1482,45 +1433,44 @@ func init() {
}
var fileDescriptorTask = []byte{
// 630 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x52, 0xc1, 0x4e, 0xdb, 0x40,
0x14, 0x8c, 0x1d, 0xe3, 0x24, 0xeb, 0x04, 0xdc, 0x2d, 0x42, 0x26, 0xad, 0x8c, 0xc5, 0xa5, 0x56,
0xa5, 0x3a, 0x6a, 0x38, 0x54, 0xea, 0x0d, 0x48, 0x84, 0xa2, 0x4a, 0x21, 0xda, 0x10, 0xf5, 0x18,
0x2d, 0xd9, 0xad, 0xbb, 0x02, 0xd6, 0x96, 0x77, 0x0d, 0xe5, 0xd6, 0x63, 0xc5, 0x3f, 0x70, 0x6a,
0xfb, 0x0b, 0x3d, 0xf4, 0x0b, 0x38, 0xf6, 0xd8, 0x13, 0x2a, 0xf9, 0x85, 0xfe, 0x40, 0xe5, 0xb5,
0x49, 0x82, 0x14, 0xa4, 0x5e, 0xa2, 0x79, 0x33, 0xa3, 0xf8, 0xbd, 0x99, 0x05, 0x6f, 0x43, 0x26,
0x3f, 0xa6, 0xc7, 0xc1, 0x24, 0x3a, 0x6b, 0x4d, 0x22, 0x2e, 0x31, 0xe3, 0x34, 0x21, 0x8b, 0x10,
0xc7, 0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, 0xfb,
0x34, 0x74, 0x7e, 0x4e, 0x43, 0xe7, 0xd8, 0xb3, 0x83, 0xd8, 0xf9, 0x13, 0x00, 0x00, 0xff, 0xff,
0x1e, 0xcd, 0x9c, 0x52, 0x26, 0x04, 0x00, 0x00,
}

View File

@ -21,11 +21,10 @@ message Task {
string container_id = 2;
uint32 pid = 3;
Status status = 4;
google.protobuf.Any spec = 5;
string stdin = 6;
string stdout = 7;
string stderr = 8;
bool terminal = 9;
string stdin = 5;
string stdout = 6;
string stderr = 7;
bool terminal = 8;
}
message Process {

View File

@ -7,6 +7,7 @@ import (
"log"
"net/http"
"runtime"
"strconv"
"sync"
"time"
@ -31,9 +32,11 @@ import (
imagesservice "github.com/containerd/containerd/services/images"
snapshotservice "github.com/containerd/containerd/services/snapshot"
"github.com/containerd/containerd/snapshot"
"github.com/containerd/containerd/typeurl"
pempty "github.com/golang/protobuf/ptypes/empty"
"github.com/opencontainers/image-spec/identity"
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
specs "github.com/opencontainers/runtime-spec/specs-go"
"github.com/pkg/errors"
"google.golang.org/grpc"
"google.golang.org/grpc/grpclog"
@ -43,6 +46,13 @@ import (
func init() {
// reset the grpc logger so that it does not output in the STDIO of the calling process
grpclog.SetLogger(log.New(ioutil.Discard, "", log.LstdFlags))
// register TypeUrls for commonly marshaled external types
major := strconv.Itoa(specs.VersionMajor)
typeurl.Register(specs.Spec{}, "opencontainers/runtime-spec", major, "Spec")
typeurl.Register(specs.Process{}, "opencontainers/runtime-spec", major, "Process")
typeurl.Register(specs.LinuxResources{}, "opencontainers/runtime-spec", major, "LinuxResources")
typeurl.Register(specs.WindowsResources{}, "opencontainers/runtime-spec", major, "WindowsResources")
}
type clientOpts struct {

View File

@ -10,13 +10,11 @@ import (
"github.com/Sirupsen/logrus"
"github.com/containerd/console"
"github.com/containerd/containerd"
containersapi "github.com/containerd/containerd/api/services/containers/v1"
"github.com/containerd/containerd/api/services/tasks/v1"
"github.com/containerd/containerd/log"
"github.com/containerd/containerd/mount"
"github.com/containerd/containerd/windows"
"github.com/containerd/containerd/windows/hcs"
protobuf "github.com/gogo/protobuf/types"
digest "github.com/opencontainers/go-digest"
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
specs "github.com/opencontainers/runtime-spec/specs-go"
@ -136,25 +134,6 @@ func newContainerSpec(context *cli.Context, config *ocispec.ImageConfig, imageRe
return json.Marshal(rtSpec)
}
func newCreateContainerRequest(context *cli.Context, id, snapshot, image string, spec []byte) (*containersapi.CreateContainerRequest, error) {
create := &containersapi.CreateContainerRequest{
Container: containersapi.Container{
ID: id,
Image: image,
Spec: &protobuf.Any{
TypeUrl: specs.Version,
Value: spec,
},
Runtime: &containersapi.Container_Runtime{
Name: context.String("runtime"),
},
RootFS: snapshot,
},
}
return create, nil
}
func newCreateTaskRequest(context *cli.Context, id, tmpDir string, checkpoint *ocispec.Descriptor, mounts []mount.Mount) (*tasks.CreateTaskRequest, error) {
create := &tasks.CreateTaskRequest{
ContainerID: id,

View File

@ -20,6 +20,7 @@ import (
"github.com/Sirupsen/logrus"
"github.com/containerd/console"
shim "github.com/containerd/containerd/linux/shim/v1"
"github.com/containerd/containerd/typeurl"
protobuf "github.com/gogo/protobuf/types"
google_protobuf "github.com/golang/protobuf/ptypes/empty"
"github.com/opencontainers/runtime-spec/specs-go"
@ -235,10 +236,14 @@ var shimExecCommand = cli.Command{
if err != nil {
return err
}
url, err := typeurl.TypeUrl(specs.Process{})
if err != nil {
return err
}
rq := &shim.ExecProcessRequest{
Spec: &protobuf.Any{
TypeUrl: specs.Version,
TypeUrl: url,
Value: spec,
},
Stdin: context.String("stdin"),

View File

@ -14,11 +14,11 @@ import (
"github.com/containerd/containerd/content"
"github.com/containerd/containerd/errdefs"
"github.com/containerd/containerd/images"
"github.com/gogo/protobuf/proto"
protobuf "github.com/gogo/protobuf/types"
digest "github.com/opencontainers/go-digest"
"github.com/opencontainers/image-spec/identity"
"github.com/opencontainers/image-spec/specs-go/v1"
specs "github.com/opencontainers/runtime-spec/specs-go"
)
func WithCheckpoint(desc v1.Descriptor, rootfsID string) NewContainerOpts {
@ -61,10 +61,11 @@ func WithCheckpoint(desc v1.Descriptor, rootfsID string) NewContainerOpts {
if err != nil {
return err
}
c.Spec = &protobuf.Any{
TypeUrl: specs.Version,
Value: data,
var any protobuf.Any
if err := proto.Unmarshal(data, &any); err != nil {
return err
}
c.Spec = &any
}
}
if rw != nil {

View File

@ -17,7 +17,7 @@ type Container struct {
Labels map[string]string
Image string
Runtime RuntimeInfo
Spec []byte
Spec *types.Any
RootFS string
CreatedAt time.Time
UpdatedAt time.Time

View File

@ -15,7 +15,7 @@ const (
MediaTypeContainerd1CheckpointPreDump = "application/vnd.containerd.container.criu.checkpoint.predump.tar"
MediaTypeContainerd1Resource = "application/vnd.containerd.container.resource.tar"
MediaTypeContainerd1RW = "application/vnd.containerd.container.rw.tar"
MediaTypeContainerd1CheckpointConfig = "application/vnd.containerd.container.checkpoint.config.v1+json"
MediaTypeContainerd1CheckpointConfig = "application/vnd.containerd.container.checkpoint.config.v1+proto"
// Legacy Docker schema1 manifest
MediaTypeDockerSchema1Manifest = "application/vnd.docker.distribution.manifest.v1+prettyjws"
)

View File

@ -6,7 +6,6 @@ import (
"bytes"
"context"
"io"
"io/ioutil"
"os"
"path/filepath"
@ -82,11 +81,6 @@ func (b *bundle) Connect(ctx context.Context, remote bool) (*client.Client, erro
}, opt)
}
// spec returns the spec written to the bundle
func (b *bundle) Spec() ([]byte, error) {
return ioutil.ReadFile(filepath.Join(b.path, configFilename))
}
// Delete deletes the bundle from disk
func (b *bundle) Delete() error {
return os.RemoveAll(b.path)

View File

@ -1,33 +1,20 @@
package runcopts
import (
"path/filepath"
tasks "github.com/containerd/containerd/api/services/tasks/v1"
"github.com/gogo/protobuf/proto"
protobuf "github.com/gogo/protobuf/types"
"github.com/containerd/containerd/typeurl"
)
const URIBase = "types.containerd.io/linux/runc"
func init() {
typeurl.Register(RuncOptions{}, "linux/runc/RuncOptions")
typeurl.Register(CreateOptions{}, "linux/runc/CreateOptions")
typeurl.Register(CheckpointOptions{}, "linux/runc/CheckpointOptions")
}
func WithExit(r *tasks.CheckpointTaskRequest) error {
a, err := marshal(&CheckpointOptions{
a, err := typeurl.MarshalAny(&CheckpointOptions{
Exit: true,
}, "CheckpointOptions")
if err != nil {
return err
}
})
r.Options = a
return nil
}
func marshal(m proto.Message, name string) (*protobuf.Any, error) {
data, err := proto.Marshal(m)
if err != nil {
return nil, err
}
return &protobuf.Any{
TypeUrl: filepath.Join(URIBase, name),
Value: data,
}, nil
return err
}

View File

@ -139,7 +139,7 @@ func (r *Runtime) Create(ctx context.Context, id string, opts runtime.CreateOpts
if err != nil {
return nil, err
}
bundle, err := newBundle(filepath.Join(r.root, namespace), namespace, id, opts.Spec)
bundle, err := newBundle(filepath.Join(r.root, namespace), namespace, id, opts.Spec.Value)
if err != nil {
return nil, err
}
@ -183,7 +183,7 @@ func (r *Runtime) Create(ctx context.Context, id string, opts runtime.CreateOpts
if _, err = s.Create(ctx, sopts); err != nil {
return nil, errors.New(grpc.ErrorDesc(err))
}
t := newTask(id, namespace, opts.Spec, s)
t := newTask(id, namespace, s)
if err := r.tasks.add(ctx, t); err != nil {
return nil, err
}
@ -323,14 +323,9 @@ func (r *Runtime) loadTasks(ctx context.Context, ns string) ([]*Task, error) {
}
continue
}
spec, err := bundle.Spec()
if err != nil {
log.G(ctx).WithError(err).Error("load task spec")
}
o = append(o, &Task{
containerID: id,
shim: s,
spec: spec,
namespace: ns,
})
}

View File

@ -17,16 +17,14 @@ import (
type Task struct {
containerID string
spec []byte
shim *client.Client
namespace string
}
func newTask(id, namespace string, spec []byte, shim *client.Client) *Task {
func newTask(id, namespace string, shim *client.Client) *Task {
return &Task{
containerID: id,
shim: shim,
spec: spec,
namespace: namespace,
}
}
@ -36,7 +34,6 @@ func (t *Task) Info() runtime.TaskInfo {
ID: t.containerID,
ContainerID: t.containerID,
Runtime: pluginID,
Spec: t.spec,
Namespace: t.namespace,
}
}

View File

@ -230,8 +230,11 @@ func readContainer(container *containers.Container, bkt *bolt.Bucket) error {
}
container.Runtime.Options = &any
case string(bucketKeySpec):
container.Spec = make([]byte, len(v))
copy(container.Spec, v)
var any types.Any
if err := proto.Unmarshal(v, &any); err != nil {
return err
}
container.Spec = &any
case string(bucketKeyRootFS):
container.RootFS = string(v)
case string(bucketKeyCreatedAt):
@ -269,10 +272,14 @@ func writeContainer(container *containers.Container, bkt *bolt.Bucket) error {
if err != nil {
return err
}
spec, err := container.Spec.Marshal()
if err != nil {
return err
}
for _, v := range [][2][]byte{
{bucketKeyImage, []byte(container.Image)},
{bucketKeySpec, container.Spec},
{bucketKeySpec, spec},
{bucketKeyRootFS, []byte(container.RootFS)},
{bucketKeyCreatedAt, createdAt},
{bucketKeyUpdatedAt, updatedAt},

View File

@ -2,13 +2,12 @@ package containerd
import (
"context"
"encoding/json"
"syscall"
eventsapi "github.com/containerd/containerd/api/services/events/v1"
"github.com/containerd/containerd/api/services/tasks/v1"
"github.com/containerd/containerd/events"
protobuf "github.com/gogo/protobuf/types"
"github.com/containerd/containerd/typeurl"
specs "github.com/opencontainers/runtime-spec/specs-go"
)
@ -35,7 +34,7 @@ func (p *process) Pid() uint32 {
// Start starts the exec process
func (p *process) Start(ctx context.Context) error {
data, err := json.Marshal(p.spec)
any, err := typeurl.MarshalAny(p.spec)
if err != nil {
return err
}
@ -45,10 +44,7 @@ func (p *process) Start(ctx context.Context) error {
Stdin: p.io.Stdin,
Stdout: p.io.Stdout,
Stderr: p.io.Stderr,
Spec: &protobuf.Any{
TypeUrl: specs.Version,
Value: data,
},
Spec: any,
}
response, err := p.task.client.TaskService().Exec(ctx, request)
if err != nil {

View File

@ -17,7 +17,7 @@ type IO struct {
type CreateOpts struct {
// Spec is the OCI runtime spec
Spec []byte
Spec *types.Any
// Rootfs mounts to perform to gain access to the container's filesystem
Rootfs []mount.Mount
// IO for the container's main process

View File

@ -10,7 +10,6 @@ type TaskInfo struct {
ID string
ContainerID string
Runtime string
Spec []byte
Namespace string
}

View File

@ -3,8 +3,6 @@ package containers
import (
api "github.com/containerd/containerd/api/services/containers/v1"
"github.com/containerd/containerd/containers"
"github.com/gogo/protobuf/types"
specs "github.com/opencontainers/runtime-spec/specs-go"
)
func containersToProto(containers []containers.Container) []api.Container {
@ -26,10 +24,7 @@ func containerToProto(container *containers.Container) api.Container {
Name: container.Runtime.Name,
Options: container.Runtime.Options,
},
Spec: &types.Any{
TypeUrl: specs.Version,
Value: container.Spec,
},
Spec: container.Spec,
RootFS: container.RootFS,
}
}
@ -42,18 +37,12 @@ func containerFromProto(containerpb *api.Container) containers.Container {
Options: containerpb.Runtime.Options,
}
}
var spec []byte
if containerpb.Spec != nil {
spec = containerpb.Spec.Value
}
return containers.Container{
ID: containerpb.ID,
Labels: containerpb.Labels,
Image: containerpb.Image,
Runtime: runtime,
Spec: spec,
Spec: containerpb.Spec,
RootFS: containerpb.RootFS,
}
}

View File

@ -24,9 +24,7 @@ import (
"github.com/containerd/containerd/mount"
"github.com/containerd/containerd/plugin"
"github.com/containerd/containerd/runtime"
protobuf "github.com/gogo/protobuf/types"
google_protobuf "github.com/golang/protobuf/ptypes/empty"
specs "github.com/opencontainers/image-spec/specs-go"
"github.com/pkg/errors"
"golang.org/x/net/context"
"google.golang.org/grpc"
@ -249,10 +247,6 @@ func taskFromContainerd(ctx context.Context, c runtime.Task) (*task.Task, error)
ContainerID: c.Info().ContainerID,
Pid: state.Pid,
Status: status,
Spec: &protobuf.Any{
TypeUrl: specs.Version,
Value: c.Info().Spec,
},
Stdin: state.Stdin,
Stdout: state.Stdout,
Stderr: state.Stderr,
@ -405,7 +399,11 @@ func (s *Service) CloseIO(ctx context.Context, r *api.CloseIORequest) (*google_p
}
func (s *Service) Checkpoint(ctx context.Context, r *api.CheckpointTaskRequest) (*api.CheckpointTaskResponse, error) {
t, err := s.getTask(ctx, r.ContainerID)
container, err := s.getContainer(ctx, r.ContainerID)
if err != nil {
return nil, err
}
t, err := s.getTaskFromContainer(ctx, container)
if err != nil {
return nil, err
}
@ -428,7 +426,11 @@ func (s *Service) Checkpoint(ctx context.Context, r *api.CheckpointTaskRequest)
return nil, err
}
// write the config to the content store
spec := bytes.NewReader(t.Info().Spec)
data, err := container.Spec.Marshal()
if err != nil {
return nil, err
}
spec := bytes.NewReader(data)
specD, err := s.writeContent(ctx, images.MediaTypeContainerd1CheckpointConfig, filepath.Join(image, "spec"), spec)
if err != nil {
return nil, err
@ -472,19 +474,17 @@ func (s *Service) writeContent(ctx context.Context, mediaType, ref string, r io.
}, nil
}
func (s *Service) getContainer(ctx context.Context, id string) (containers.Container, error) {
func (s *Service) getContainer(ctx context.Context, id string) (*containers.Container, error) {
var container containers.Container
if err := s.db.View(func(tx *bolt.Tx) error {
store := metadata.NewContainerStore(tx)
var err error
container, err = store.Get(ctx, id)
return err
}); err != nil {
return containers.Container{}, errdefs.ToGRPC(err)
return nil, errdefs.ToGRPC(err)
}
return container, nil
return &container, nil
}
func (s *Service) getTask(ctx context.Context, id string) (runtime.Task, error) {
@ -492,18 +492,20 @@ func (s *Service) getTask(ctx context.Context, id string) (runtime.Task, error)
if err != nil {
return nil, err
}
return s.getTaskFromContainer(ctx, container)
}
func (s *Service) getTaskFromContainer(ctx context.Context, container *containers.Container) (runtime.Task, error) {
runtime, err := s.getRuntime(container.Runtime.Name)
if err != nil {
return nil, errdefs.ToGRPCf(err, "runtime for task %v", id)
return nil, errdefs.ToGRPCf(err, "runtime for task %s", container.Runtime.Name)
}
t, err := runtime.Get(ctx, id)
t, err := runtime.Get(ctx, container.ID)
if err != nil {
return nil, grpc.Errorf(codes.NotFound, "task %v not found", id)
return nil, grpc.Errorf(codes.NotFound, "task %v not found", container.ID)
}
return t, nil
}
func (s *Service) getRuntime(name string) (runtime.Runtime, error) {

View File

@ -12,7 +12,7 @@ import (
"github.com/containerd/containerd/api/services/containers/v1"
"github.com/containerd/containerd/api/services/tasks/v1"
"github.com/containerd/containerd/images"
protobuf "github.com/gogo/protobuf/types"
"github.com/containerd/containerd/typeurl"
"github.com/opencontainers/image-spec/specs-go/v1"
specs "github.com/opencontainers/runtime-spec/specs-go"
)
@ -275,28 +275,22 @@ func WithImageConfig(ctx context.Context, i Image) SpecOpts {
func WithSpec(spec *specs.Spec) NewContainerOpts {
return func(ctx context.Context, client *Client, c *containers.Container) error {
data, err := json.Marshal(spec)
any, err := typeurl.MarshalAny(spec)
if err != nil {
return err
}
c.Spec = &protobuf.Any{
TypeUrl: spec.Version,
Value: data,
}
c.Spec = any
return nil
}
}
func WithResources(resources *specs.LinuxResources) UpdateTaskOpts {
return func(ctx context.Context, client *Client, r *tasks.UpdateTaskRequest) error {
data, err := json.Marshal(resources)
any, err := typeurl.MarshalAny(resources)
if err != nil {
return err
}
r.Resources = &protobuf.Any{
TypeUrl: specs.Version,
Value: data,
}
r.Resources = any
return nil
}
}

View File

@ -8,7 +8,7 @@ import (
"github.com/containerd/containerd/api/services/containers/v1"
tasks "github.com/containerd/containerd/api/services/tasks/v1"
"github.com/containerd/containerd/images"
protobuf "github.com/gogo/protobuf/types"
"github.com/containerd/containerd/typeurl"
"github.com/opencontainers/image-spec/specs-go/v1"
specs "github.com/opencontainers/runtime-spec/specs-go"
)
@ -77,28 +77,22 @@ func WithTTY(width, height int) SpecOpts {
func WithSpec(spec *specs.Spec) NewContainerOpts {
return func(ctx context.Context, client *Client, c *containers.Container) error {
data, err := json.Marshal(spec)
any, err := typeurl.MarshalAny(spec)
if err != nil {
return err
}
c.Spec = &protobuf.Any{
TypeUrl: spec.Version,
Value: data,
}
c.Spec = any
return nil
}
}
func WithResources(resources *specs.WindowsResources) UpdateTaskOpts {
return func(ctx context.Context, client *Client, r *tasks.UpdateTaskRequest) error {
data, err := json.Marshal(resources)
any, err := typeurl.MarshalAny(resources)
if err != nil {
return err
}
r.Resources = &protobuf.Any{
TypeUrl: specs.Version,
Value: data,
}
r.Resources = any
return nil
}
}

View File

@ -41,7 +41,7 @@ func loadContainers(ctx context.Context, h *hcs.HCS, sendEvent eventCallback) ([
return containers, nil
}
func newContainer(ctx context.Context, h *hcs.HCS, id string, spec RuntimeSpec, io runtime.IO, sendEvent eventCallback) (*container, error) {
func newContainer(ctx context.Context, h *hcs.HCS, id string, spec *RuntimeSpec, io runtime.IO, sendEvent eventCallback) (*container, error) {
cio, err := hcs.NewIO(io.Stdin, io.Stdout, io.Stderr, io.Terminal)
if err != nil {
return nil, err

View File

@ -4,7 +4,6 @@ package windows
import (
"context"
"encoding/json"
"fmt"
"os"
"path/filepath"
@ -15,6 +14,7 @@ import (
"github.com/containerd/containerd/log"
"github.com/containerd/containerd/plugin"
"github.com/containerd/containerd/runtime"
"github.com/containerd/containerd/typeurl"
"github.com/containerd/containerd/windows/hcs"
"github.com/containerd/containerd/windows/pid"
specs "github.com/opencontainers/runtime-spec/specs-go"
@ -34,6 +34,7 @@ func init() {
Type: plugin.RuntimePlugin,
Init: New,
})
typeurl.Register(RuntimeSpec{}, "windows/Spec")
}
func New(ic *plugin.InitContext) (interface{}, error) {
@ -107,11 +108,11 @@ func (r *Runtime) ID() string {
}
func (r *Runtime) Create(ctx context.Context, id string, opts runtime.CreateOpts) (runtime.Task, error) {
var rtSpec RuntimeSpec
if err := json.Unmarshal(opts.Spec, &rtSpec); err != nil {
return nil, errors.Wrap(err, "failed to unmarshal oci spec")
v, err := typeurl.UnmarshalAny(opts.Spec)
if err != nil {
return nil, err
}
rtSpec := v.(*RuntimeSpec)
ctr, err := newContainer(ctx, r.hcs, id, rtSpec, opts.IO, r.sendEvent)
if err != nil {
return nil, err