Support sandboxed shims shutdown

Signed-off-by: Maksym Pavlenko <pavlenko.maksym@gmail.com>
This commit is contained in:
Maksym Pavlenko 2022-12-14 18:22:52 -08:00
parent d65269fda0
commit a4d5c3e5cb
9 changed files with 39 additions and 20 deletions

View File

@ -178,7 +178,7 @@ var removeCommand = cli.Command{
}
}
err = sandbox.Delete(ctx)
err = sandbox.Shutdown(ctx)
if err != nil {
log.G(ctx).WithError(err).Errorf("failed to shutdown sandbox %s", id)
continue

View File

@ -26,7 +26,7 @@ import (
"github.com/containerd/containerd/log"
)
func (c *Controller) Delete(ctx context.Context, sandboxID string) (*api.ControllerDeleteResponse, error) {
func (c *Controller) Shutdown(ctx context.Context, sandboxID string) (*api.ControllerShutdownResponse, error) {
sandbox, err := c.sandboxStore.Get(sandboxID)
if err != nil {
if !errdefs.IsNotFound(err) {
@ -34,7 +34,7 @@ func (c *Controller) Delete(ctx context.Context, sandboxID string) (*api.Control
}
// Do not return error if the id doesn't exist.
log.G(ctx).Tracef("Sandbox controller Delete called for sandbox %q that does not exist", sandboxID)
return &api.ControllerDeleteResponse{}, nil
return &api.ControllerShutdownResponse{}, nil
}
// Cleanup the sandbox root directories.
@ -58,5 +58,5 @@ func (c *Controller) Delete(ctx context.Context, sandboxID string) (*api.Control
}
}
return &api.ControllerDeleteResponse{}, nil
return &api.ControllerShutdownResponse{}, nil
}

View File

@ -86,7 +86,7 @@ func (c *criService) RemovePodSandbox(ctx context.Context, r *runtime.RemovePodS
return nil, fmt.Errorf("failed to get sandbox controller: %w", err)
}
if _, err := controller.Delete(ctx, id); err != nil && !errdefs.IsNotFound(err) {
if _, err := controller.Shutdown(ctx, id); err != nil && !errdefs.IsNotFound(err) {
return nil, fmt.Errorf("failed to delete sandbox %q: %w", id, err)
}

View File

@ -92,3 +92,7 @@ func (p *pauseService) SandboxStatus(ctx context.Context, req *api.SandboxStatus
func (p *pauseService) PingSandbox(ctx context.Context, req *api.PingRequest) (*api.PingResponse, error) {
return &api.PingResponse{}, nil
}
func (p *pauseService) ShutdownSandbox(ctx context.Context, request *api.ShutdownSandboxRequest) (*api.ShutdownSandboxResponse, error) {
return &api.ShutdownSandboxResponse{}, nil
}

View File

@ -46,8 +46,8 @@ type Sandbox interface {
Stop(ctx context.Context) error
// Wait blocks until sandbox process exits.
Wait(ctx context.Context) (<-chan ExitStatus, error)
// Delete removes sandbox from the metadata store.
Delete(ctx context.Context) error
// Shutdown removes sandbox from the metadata store and shutdowns shim instance.
Shutdown(ctx context.Context) error
}
type sandboxClient struct {
@ -121,11 +121,16 @@ func (s *sandboxClient) Stop(ctx context.Context) error {
return nil
}
func (s *sandboxClient) Delete(ctx context.Context) error {
if _, err := s.client.SandboxController().Delete(ctx, s.ID()); err != nil {
return err
func (s *sandboxClient) Shutdown(ctx context.Context) error {
if _, err := s.client.SandboxController().Shutdown(ctx, s.ID()); err != nil {
return fmt.Errorf("failed to shutdown sandbox: %w", err)
}
return s.client.SandboxStore().Delete(ctx, s.ID())
if err := s.client.SandboxStore().Delete(ctx, s.ID()); err != nil {
return fmt.Errorf("failed to delete sandbox from store: %w", err)
}
return nil
}
// NewSandbox creates new sandbox client

View File

@ -37,6 +37,6 @@ type Controller interface {
// Status will query sandbox process status. It is heavier than Ping call and must be used whenever you need to
// gather metadata about current sandbox state (status, uptime, resource use, etc).
Status(ctx context.Context, sandboxID string, verbose bool) (*sandbox.ControllerStatusResponse, error)
// Delete deletes and cleans all tasks and sandbox instance.
Delete(ctx context.Context, sandboxID string) (*sandbox.ControllerDeleteResponse, error)
// Shutdown deletes and cleans all tasks and sandbox instance.
Shutdown(ctx context.Context, sandboxID string) (*sandbox.ControllerShutdownResponse, error)
}

View File

@ -63,8 +63,8 @@ func (s *remoteSandboxController) Stop(ctx context.Context, sandboxID string) (*
return resp, nil
}
func (s *remoteSandboxController) Delete(ctx context.Context, sandboxID string) (*api.ControllerDeleteResponse, error) {
resp, err := s.client.Delete(ctx, &api.ControllerDeleteRequest{SandboxID: sandboxID})
func (s *remoteSandboxController) Shutdown(ctx context.Context, sandboxID string) (*api.ControllerShutdownResponse, error) {
resp, err := s.client.Shutdown(ctx, &api.ControllerShutdownRequest{SandboxID: sandboxID})
if err != nil {
return nil, errdefs.FromGRPC(err)
}

View File

@ -154,12 +154,22 @@ func (c *controllerLocal) Stop(ctx context.Context, in *api.ControllerStopReques
return &api.ControllerStopResponse{}, nil
}
func (c *controllerLocal) Delete(ctx context.Context, in *api.ControllerDeleteRequest, opts ...grpc.CallOption) (*api.ControllerDeleteResponse, error) {
func (c *controllerLocal) Shutdown(ctx context.Context, in *api.ControllerShutdownRequest, opts ...grpc.CallOption) (*api.ControllerShutdownResponse, error) {
svc, err := c.getSandbox(ctx, in.SandboxID)
if err != nil {
return nil, err
}
_, err = svc.ShutdownSandbox(ctx, &runtimeAPI.ShutdownSandboxRequest{SandboxID: in.SandboxID})
if err != nil {
return nil, errdefs.ToGRPC(fmt.Errorf("failed to shutdown sandbox: %w", err))
}
if err := c.shims.Delete(ctx, in.SandboxID); err != nil {
return nil, errdefs.ToGRPC(fmt.Errorf("failed to delete sandbox shim: %w", err))
}
return &api.ControllerDeleteResponse{}, nil
return &api.ControllerShutdownResponse{}, nil
}
func (c *controllerLocal) Wait(ctx context.Context, in *api.ControllerWaitRequest, opts ...grpc.CallOption) (*api.ControllerWaitResponse, error) {

View File

@ -94,7 +94,7 @@ func (s *controllerService) Status(ctx context.Context, req *api.ControllerStatu
return s.local.Status(ctx, req)
}
func (s *controllerService) Delete(ctx context.Context, req *api.ControllerDeleteRequest) (*api.ControllerDeleteResponse, error) {
log.G(ctx).WithField("req", req).Debug("delete sandbox")
return s.local.Delete(ctx, req)
func (s *controllerService) Shutdown(ctx context.Context, req *api.ControllerShutdownRequest) (*api.ControllerShutdownResponse, error) {
log.G(ctx).WithField("req", req).Debug("shutdown sandbox")
return s.local.Shutdown(ctx, req)
}