Support sandboxed shims shutdown
Signed-off-by: Maksym Pavlenko <pavlenko.maksym@gmail.com>
This commit is contained in:
parent
d65269fda0
commit
a4d5c3e5cb
@ -178,7 +178,7 @@ var removeCommand = cli.Command{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
err = sandbox.Delete(ctx)
|
err = sandbox.Shutdown(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.G(ctx).WithError(err).Errorf("failed to shutdown sandbox %s", id)
|
log.G(ctx).WithError(err).Errorf("failed to shutdown sandbox %s", id)
|
||||||
continue
|
continue
|
||||||
|
@ -26,7 +26,7 @@ import (
|
|||||||
"github.com/containerd/containerd/log"
|
"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)
|
sandbox, err := c.sandboxStore.Get(sandboxID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if !errdefs.IsNotFound(err) {
|
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.
|
// 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)
|
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.
|
// 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
|
||||||
}
|
}
|
||||||
|
@ -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)
|
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)
|
return nil, fmt.Errorf("failed to delete sandbox %q: %w", id, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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) {
|
func (p *pauseService) PingSandbox(ctx context.Context, req *api.PingRequest) (*api.PingResponse, error) {
|
||||||
return &api.PingResponse{}, nil
|
return &api.PingResponse{}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (p *pauseService) ShutdownSandbox(ctx context.Context, request *api.ShutdownSandboxRequest) (*api.ShutdownSandboxResponse, error) {
|
||||||
|
return &api.ShutdownSandboxResponse{}, nil
|
||||||
|
}
|
||||||
|
17
sandbox.go
17
sandbox.go
@ -46,8 +46,8 @@ type Sandbox interface {
|
|||||||
Stop(ctx context.Context) error
|
Stop(ctx context.Context) error
|
||||||
// Wait blocks until sandbox process exits.
|
// Wait blocks until sandbox process exits.
|
||||||
Wait(ctx context.Context) (<-chan ExitStatus, error)
|
Wait(ctx context.Context) (<-chan ExitStatus, error)
|
||||||
// Delete removes sandbox from the metadata store.
|
// Shutdown removes sandbox from the metadata store and shutdowns shim instance.
|
||||||
Delete(ctx context.Context) error
|
Shutdown(ctx context.Context) error
|
||||||
}
|
}
|
||||||
|
|
||||||
type sandboxClient struct {
|
type sandboxClient struct {
|
||||||
@ -121,11 +121,16 @@ func (s *sandboxClient) Stop(ctx context.Context) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *sandboxClient) Delete(ctx context.Context) error {
|
func (s *sandboxClient) Shutdown(ctx context.Context) error {
|
||||||
if _, err := s.client.SandboxController().Delete(ctx, s.ID()); err != nil {
|
if _, err := s.client.SandboxController().Shutdown(ctx, s.ID()); err != nil {
|
||||||
return err
|
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
|
// NewSandbox creates new sandbox client
|
||||||
|
@ -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
|
// 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).
|
// gather metadata about current sandbox state (status, uptime, resource use, etc).
|
||||||
Status(ctx context.Context, sandboxID string, verbose bool) (*sandbox.ControllerStatusResponse, error)
|
Status(ctx context.Context, sandboxID string, verbose bool) (*sandbox.ControllerStatusResponse, error)
|
||||||
// Delete deletes and cleans all tasks and sandbox instance.
|
// Shutdown deletes and cleans all tasks and sandbox instance.
|
||||||
Delete(ctx context.Context, sandboxID string) (*sandbox.ControllerDeleteResponse, error)
|
Shutdown(ctx context.Context, sandboxID string) (*sandbox.ControllerShutdownResponse, error)
|
||||||
}
|
}
|
||||||
|
@ -63,8 +63,8 @@ func (s *remoteSandboxController) Stop(ctx context.Context, sandboxID string) (*
|
|||||||
return resp, nil
|
return resp, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *remoteSandboxController) Delete(ctx context.Context, sandboxID string) (*api.ControllerDeleteResponse, error) {
|
func (s *remoteSandboxController) Shutdown(ctx context.Context, sandboxID string) (*api.ControllerShutdownResponse, error) {
|
||||||
resp, err := s.client.Delete(ctx, &api.ControllerDeleteRequest{SandboxID: sandboxID})
|
resp, err := s.client.Shutdown(ctx, &api.ControllerShutdownRequest{SandboxID: sandboxID})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errdefs.FromGRPC(err)
|
return nil, errdefs.FromGRPC(err)
|
||||||
}
|
}
|
||||||
|
@ -154,12 +154,22 @@ func (c *controllerLocal) Stop(ctx context.Context, in *api.ControllerStopReques
|
|||||||
return &api.ControllerStopResponse{}, nil
|
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 {
|
if err := c.shims.Delete(ctx, in.SandboxID); err != nil {
|
||||||
return nil, errdefs.ToGRPC(fmt.Errorf("failed to delete sandbox shim: %w", err))
|
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) {
|
func (c *controllerLocal) Wait(ctx context.Context, in *api.ControllerWaitRequest, opts ...grpc.CallOption) (*api.ControllerWaitResponse, error) {
|
||||||
|
@ -94,7 +94,7 @@ func (s *controllerService) Status(ctx context.Context, req *api.ControllerStatu
|
|||||||
return s.local.Status(ctx, req)
|
return s.local.Status(ctx, req)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *controllerService) Delete(ctx context.Context, req *api.ControllerDeleteRequest) (*api.ControllerDeleteResponse, error) {
|
func (s *controllerService) Shutdown(ctx context.Context, req *api.ControllerShutdownRequest) (*api.ControllerShutdownResponse, error) {
|
||||||
log.G(ctx).WithField("req", req).Debug("delete sandbox")
|
log.G(ctx).WithField("req", req).Debug("shutdown sandbox")
|
||||||
return s.local.Delete(ctx, req)
|
return s.local.Shutdown(ctx, req)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user