Use typeurl package for spec types
Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user