mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-07-03 02:26:37 +00:00
containerd-shim-kata-v2: add the service Delete support
Add the Delete api support to delete a stopped container or pod. Signed-off-by: fupan <lifupan@gmail.com>
This commit is contained in:
parent
fd18b2289d
commit
a0e6456455
49
containerd-shim-v2/delete.go
Normal file
49
containerd-shim-v2/delete.go
Normal file
@ -0,0 +1,49 @@
|
||||
// Copyright (c) 2018 HyperHQ Inc.
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
|
||||
package containerdshim
|
||||
|
||||
import (
|
||||
"context"
|
||||
"path"
|
||||
|
||||
"github.com/containerd/containerd/mount"
|
||||
"github.com/kata-containers/runtime/pkg/katautils"
|
||||
vc "github.com/kata-containers/runtime/virtcontainers"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
func deleteContainer(ctx context.Context, s *service, c *container) error {
|
||||
|
||||
status, err := s.sandbox.StatusContainer(c.id)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if status.State.State != vc.StateStopped {
|
||||
_, err = s.sandbox.StopContainer(c.id)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
_, err = s.sandbox.DeleteContainer(c.id)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Run post-stop OCI hooks.
|
||||
if err := katautils.PostStopHooks(ctx, *c.spec, s.sandbox.ID(), c.bundle); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
rootfs := path.Join(c.bundle, "rootfs")
|
||||
if err := mount.UnmountAll(rootfs, 0); err != nil {
|
||||
logrus.WithError(err).Warn("failed to cleanup rootfs mount")
|
||||
}
|
||||
|
||||
delete(s.containers, c.id)
|
||||
|
||||
return nil
|
||||
}
|
@ -313,7 +313,39 @@ func (s *service) Start(ctx context.Context, r *taskAPI.StartRequest) (*taskAPI.
|
||||
|
||||
// Delete the initial process and container
|
||||
func (s *service) Delete(ctx context.Context, r *taskAPI.DeleteRequest) (*taskAPI.DeleteResponse, error) {
|
||||
return nil, errdefs.ErrNotImplemented
|
||||
s.Lock()
|
||||
defer s.Unlock()
|
||||
|
||||
c, err := s.getContainer(r.ID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if r.ExecID == "" {
|
||||
err = deleteContainer(ctx, s, c)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &taskAPI.DeleteResponse{
|
||||
ExitStatus: c.exit,
|
||||
ExitedAt: c.time,
|
||||
Pid: s.pid,
|
||||
}, nil
|
||||
}
|
||||
//deal with the exec case
|
||||
execs, err := c.getExec(r.ExecID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
delete(c.execs, r.ExecID)
|
||||
|
||||
return &taskAPI.DeleteResponse{
|
||||
ExitStatus: uint32(execs.exitCode),
|
||||
ExitedAt: execs.exitTime,
|
||||
Pid: s.pid,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// Exec an additional process inside the container
|
||||
|
Loading…
Reference in New Issue
Block a user