Merge pull request #9903 from abel-von/add-update-resource-only
sandbox: Add Update API for sandbox controller
This commit is contained in:
@@ -336,6 +336,14 @@ func (c *controllerLocal) Metrics(ctx context.Context, sandboxID string) (*types
|
||||
return resp.Metrics, nil
|
||||
}
|
||||
|
||||
func (c *controllerLocal) Update(
|
||||
ctx context.Context,
|
||||
sandboxID string,
|
||||
sandbox sandbox.Sandbox,
|
||||
fields ...string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *controllerLocal) getSandbox(ctx context.Context, id string) (runtimeAPI.TTRPCSandboxService, error) {
|
||||
shim, err := c.shims.Get(ctx, id)
|
||||
if err != nil {
|
||||
|
||||
@@ -26,6 +26,7 @@ import (
|
||||
|
||||
eventtypes "github.com/containerd/containerd/api/events"
|
||||
api "github.com/containerd/containerd/api/services/sandbox/v1"
|
||||
"github.com/containerd/containerd/api/types"
|
||||
"github.com/containerd/containerd/v2/core/events"
|
||||
"github.com/containerd/containerd/v2/core/sandbox"
|
||||
"github.com/containerd/containerd/v2/pkg/protobuf"
|
||||
@@ -34,6 +35,7 @@ import (
|
||||
"github.com/containerd/log"
|
||||
"github.com/containerd/plugin"
|
||||
"github.com/containerd/plugin/registry"
|
||||
"github.com/containerd/typeurl/v2"
|
||||
)
|
||||
|
||||
func init() {
|
||||
@@ -98,7 +100,13 @@ func (s *controllerService) Create(ctx context.Context, req *api.ControllerCreat
|
||||
if err != nil {
|
||||
return nil, errdefs.ToGRPC(err)
|
||||
}
|
||||
err = ctrl.Create(ctx, sandbox.Sandbox{ID: req.GetSandboxID()}, sandbox.WithOptions(req.GetOptions()))
|
||||
var sb sandbox.Sandbox
|
||||
if req.Sandbox != nil {
|
||||
sb = fromAPISandbox(req.Sandbox)
|
||||
} else {
|
||||
sb = sandbox.Sandbox{ID: req.GetSandboxID()}
|
||||
}
|
||||
err = ctrl.Create(ctx, sb, sandbox.WithOptions(req.GetOptions()))
|
||||
if err != nil {
|
||||
return &api.ControllerCreateResponse{}, errdefs.ToGRPC(err)
|
||||
}
|
||||
@@ -224,3 +232,45 @@ func (s *controllerService) Metrics(ctx context.Context, req *api.ControllerMetr
|
||||
Metrics: metrics,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (s *controllerService) Update(
|
||||
ctx context.Context,
|
||||
req *api.ControllerUpdateRequest) (*api.ControllerUpdateResponse, error) {
|
||||
log.G(ctx).WithField("req", req).Debug("sandbox update resource")
|
||||
ctrl, err := s.getController(req.Sandboxer)
|
||||
if err != nil {
|
||||
return nil, errdefs.ToGRPC(err)
|
||||
}
|
||||
if req.Sandbox == nil {
|
||||
return nil, fmt.Errorf("sandbox can not be nil")
|
||||
}
|
||||
err = ctrl.Update(ctx, req.SandboxID, fromAPISandbox(req.Sandbox), req.Fields...)
|
||||
if err != nil {
|
||||
return &api.ControllerUpdateResponse{}, errdefs.ToGRPC(err)
|
||||
}
|
||||
return &api.ControllerUpdateResponse{}, nil
|
||||
}
|
||||
|
||||
func fromAPISandbox(sb *types.Sandbox) sandbox.Sandbox {
|
||||
var runtime sandbox.RuntimeOpts
|
||||
if sb.Runtime != nil {
|
||||
runtime = sandbox.RuntimeOpts{
|
||||
Name: sb.Runtime.Name,
|
||||
Options: sb.Runtime.Options,
|
||||
}
|
||||
}
|
||||
extensions := make(map[string]typeurl.Any)
|
||||
for k, v := range sb.Extensions {
|
||||
extensions[k] = v
|
||||
}
|
||||
return sandbox.Sandbox{
|
||||
ID: sb.SandboxID,
|
||||
Runtime: runtime,
|
||||
Spec: sb.Spec,
|
||||
Labels: sb.Labels,
|
||||
CreatedAt: protobuf.FromTimestamp(sb.CreatedAt),
|
||||
UpdatedAt: protobuf.FromTimestamp(sb.UpdatedAt),
|
||||
Extensions: extensions,
|
||||
Sandboxer: sb.Sandboxer,
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user