remove duplicated sandbox to proto func
Signed-off-by: Jin Dong <djdongjin95@gmail.com>
This commit is contained in:
@@ -24,11 +24,9 @@ import (
|
||||
"github.com/containerd/containerd/api/types"
|
||||
"github.com/containerd/containerd/v2/core/mount"
|
||||
"github.com/containerd/containerd/v2/core/sandbox"
|
||||
"github.com/containerd/containerd/v2/pkg/protobuf"
|
||||
"github.com/containerd/errdefs"
|
||||
"github.com/containerd/typeurl/v2"
|
||||
imagespec "github.com/opencontainers/image-spec/specs-go/v1"
|
||||
"google.golang.org/protobuf/types/known/anypb"
|
||||
)
|
||||
|
||||
// remoteSandboxController is a low level GRPC client for containerd's sandbox controller service
|
||||
@@ -48,20 +46,14 @@ func (s *remoteSandboxController) Create(ctx context.Context, sandboxInfo sandbo
|
||||
for _, opt := range opts {
|
||||
opt(&options)
|
||||
}
|
||||
apiSandbox, err := toAPISandbox(sandboxInfo)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = s.client.Create(ctx, &api.ControllerCreateRequest{
|
||||
SandboxID: sandboxInfo.ID,
|
||||
Rootfs: mount.ToProto(options.Rootfs),
|
||||
Options: &anypb.Any{
|
||||
TypeUrl: options.Options.GetTypeUrl(),
|
||||
Value: options.Options.GetValue(),
|
||||
},
|
||||
apiSandbox := sandbox.ToProto(&sandboxInfo)
|
||||
_, err := s.client.Create(ctx, &api.ControllerCreateRequest{
|
||||
SandboxID: sandboxInfo.ID,
|
||||
Rootfs: mount.ToProto(options.Rootfs),
|
||||
Options: typeurl.MarshalProto(options.Options),
|
||||
NetnsPath: options.NetNSPath,
|
||||
Annotations: options.Annotations,
|
||||
Sandbox: &apiSandbox,
|
||||
Sandbox: apiSandbox,
|
||||
})
|
||||
if err != nil {
|
||||
return errdefs.FromGRPC(err)
|
||||
@@ -189,15 +181,12 @@ func (s *remoteSandboxController) Metrics(ctx context.Context, sandboxID string)
|
||||
func (s *remoteSandboxController) Update(
|
||||
ctx context.Context,
|
||||
sandboxID string,
|
||||
sandbox sandbox.Sandbox,
|
||||
sb sandbox.Sandbox,
|
||||
fields ...string) error {
|
||||
apiSandbox, err := toAPISandbox(sandbox)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = s.client.Update(ctx, &api.ControllerUpdateRequest{
|
||||
apiSandbox := sandbox.ToProto(&sb)
|
||||
_, err := s.client.Update(ctx, &api.ControllerUpdateRequest{
|
||||
SandboxID: sandboxID,
|
||||
Sandbox: &apiSandbox,
|
||||
Sandbox: apiSandbox,
|
||||
Fields: fields,
|
||||
})
|
||||
if err != nil {
|
||||
@@ -205,35 +194,3 @@ func (s *remoteSandboxController) Update(
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func toAPISandbox(sb sandbox.Sandbox) (types.Sandbox, error) {
|
||||
options, err := typeurl.MarshalAnyToProto(sb.Runtime.Options)
|
||||
if err != nil {
|
||||
return types.Sandbox{}, err
|
||||
}
|
||||
spec, err := typeurl.MarshalAnyToProto(sb.Spec)
|
||||
if err != nil {
|
||||
return types.Sandbox{}, err
|
||||
}
|
||||
extensions := make(map[string]*anypb.Any)
|
||||
for k, v := range sb.Extensions {
|
||||
pb, err := typeurl.MarshalAnyToProto(v)
|
||||
if err != nil {
|
||||
return types.Sandbox{}, err
|
||||
}
|
||||
extensions[k] = pb
|
||||
}
|
||||
return types.Sandbox{
|
||||
SandboxID: sb.ID,
|
||||
Runtime: &types.Sandbox_Runtime{
|
||||
Name: sb.Runtime.Name,
|
||||
Options: options,
|
||||
},
|
||||
Spec: spec,
|
||||
Labels: sb.Labels,
|
||||
CreatedAt: protobuf.ToTimestamp(sb.CreatedAt),
|
||||
UpdatedAt: protobuf.ToTimestamp(sb.UpdatedAt),
|
||||
Extensions: extensions,
|
||||
Sandboxer: sb.Sandboxer,
|
||||
}, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user