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