mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-07-04 19:16:23 +00:00
Merge pull request #1723 from lifupan/fixcleanup
fix the issue of hypervisor process is killed by kubelet
This commit is contained in:
commit
7b9a9ffb79
@ -6,7 +6,6 @@
|
|||||||
package containerdshim
|
package containerdshim
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"sync"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/containerd/containerd/api/types/task"
|
"github.com/containerd/containerd/api/types/task"
|
||||||
@ -31,7 +30,6 @@ type container struct {
|
|||||||
stderr string
|
stderr string
|
||||||
bundle string
|
bundle string
|
||||||
cType vc.ContainerType
|
cType vc.ContainerType
|
||||||
mu sync.Mutex
|
|
||||||
exit uint32
|
exit uint32
|
||||||
status task.Status
|
status task.Status
|
||||||
terminal bool
|
terminal bool
|
||||||
|
@ -17,7 +17,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func deleteContainer(ctx context.Context, s *service, c *container) error {
|
func deleteContainer(ctx context.Context, s *service, c *container) error {
|
||||||
|
if !c.cType.IsSandbox() {
|
||||||
status, err := s.sandbox.StatusContainer(c.id)
|
status, err := s.sandbox.StatusContainer(c.id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -29,10 +29,10 @@ func deleteContainer(ctx context.Context, s *service, c *container) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = s.sandbox.DeleteContainer(c.id)
|
if _, err = s.sandbox.DeleteContainer(c.id); err != nil {
|
||||||
if err != nil {
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Run post-stop OCI hooks.
|
// Run post-stop OCI hooks.
|
||||||
if err := katautils.PostStopHooks(ctx, *c.spec, s.sandbox.ID(), c.bundle); err != nil {
|
if err := katautils.PostStopHooks(ctx, *c.spec, s.sandbox.ID(), c.bundle); err != nil {
|
||||||
|
@ -431,29 +431,12 @@ func (s *service) Delete(ctx context.Context, r *taskAPI.DeleteRequest) (_ *task
|
|||||||
}
|
}
|
||||||
|
|
||||||
if r.ExecID == "" {
|
if r.ExecID == "" {
|
||||||
err = deleteContainer(ctx, s, c)
|
if err = deleteContainer(ctx, s, c); err != nil {
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Take care of the use case where it is a sandbox.
|
|
||||||
// Right after the container representing the sandbox has
|
|
||||||
// been deleted, let's make sure we stop and delete the
|
|
||||||
// sandbox.
|
|
||||||
if c.cType.IsSandbox() {
|
|
||||||
if err = s.sandbox.Stop(); err != nil {
|
|
||||||
logrus.WithField("sandbox", s.sandbox.ID()).Error("failed to stop sandbox")
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
if err = s.sandbox.Delete(); err != nil {
|
|
||||||
logrus.WithField("sandbox", s.sandbox.ID()).Error("failed to delete sandbox")
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
s.send(&eventstypes.TaskDelete{
|
s.send(&eventstypes.TaskDelete{
|
||||||
ContainerID: s.id,
|
ContainerID: c.id,
|
||||||
Pid: s.pid,
|
Pid: s.pid,
|
||||||
ExitStatus: c.exit,
|
ExitStatus: c.exit,
|
||||||
ExitedAt: c.exitTime,
|
ExitedAt: c.exitTime,
|
||||||
@ -677,6 +660,20 @@ func (s *service) Kill(ctx context.Context, r *taskAPI.KillRequest) (_ *ptypes.E
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// According to CRI specs, kubelet will call StopPodSandbox()
|
||||||
|
// at least once before calling RemovePodSandbox, and this call
|
||||||
|
// is idempotent, and must not return an error if all relevant
|
||||||
|
// resources have already been reclaimed. And in that call it will
|
||||||
|
// send a SIGKILL signal first to try to stop the container, thus
|
||||||
|
// once the container has terminated, here should ignore this signal
|
||||||
|
// and return directly.
|
||||||
|
if signum == syscall.SIGKILL || signum == syscall.SIGTERM {
|
||||||
|
if c.status == task.StatusStopped {
|
||||||
|
logrus.WithField("sandbox", s.sandbox.ID()).WithField("Container", c.id).Debug("Container has already been stopped")
|
||||||
|
return empty, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
processID := c.id
|
processID := c.id
|
||||||
if r.ExecID != "" {
|
if r.ExecID != "" {
|
||||||
execs, err := c.getExec(r.ExecID)
|
execs, err := c.getExec(r.ExecID)
|
||||||
|
@ -42,23 +42,41 @@ func wait(s *service, c *container, execID string) (int32, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
timeStamp := time.Now()
|
timeStamp := time.Now()
|
||||||
c.mu.Lock()
|
|
||||||
|
s.mu.Lock()
|
||||||
if execID == "" {
|
if execID == "" {
|
||||||
|
// Take care of the use case where it is a sandbox.
|
||||||
|
// Right after the container representing the sandbox has
|
||||||
|
// been deleted, let's make sure we stop and delete the
|
||||||
|
// sandbox.
|
||||||
|
|
||||||
|
if c.cType.IsSandbox() {
|
||||||
|
if err = s.sandbox.Stop(); err != nil {
|
||||||
|
logrus.WithField("sandbox", s.sandbox.ID()).Error("failed to stop sandbox")
|
||||||
|
}
|
||||||
|
|
||||||
|
if err = s.sandbox.Delete(); err != nil {
|
||||||
|
logrus.WithField("sandbox", s.sandbox.ID()).Error("failed to delete sandbox")
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if _, err = s.sandbox.StopContainer(c.id); err != nil {
|
||||||
|
logrus.WithError(err).WithField("container", c.id).Warn("stop container failed")
|
||||||
|
}
|
||||||
|
}
|
||||||
c.status = task.StatusStopped
|
c.status = task.StatusStopped
|
||||||
c.exit = uint32(ret)
|
c.exit = uint32(ret)
|
||||||
c.exitTime = timeStamp
|
c.exitTime = timeStamp
|
||||||
|
|
||||||
|
c.exitCh <- uint32(ret)
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
execs.status = task.StatusStopped
|
execs.status = task.StatusStopped
|
||||||
execs.exitCode = ret
|
execs.exitCode = ret
|
||||||
execs.exitTime = timeStamp
|
execs.exitTime = timeStamp
|
||||||
}
|
|
||||||
c.mu.Unlock()
|
|
||||||
|
|
||||||
if execID == "" {
|
|
||||||
c.exitCh <- uint32(ret)
|
|
||||||
} else {
|
|
||||||
execs.exitCh <- uint32(ret)
|
execs.exitCh <- uint32(ret)
|
||||||
}
|
}
|
||||||
|
s.mu.Unlock()
|
||||||
|
|
||||||
go cReap(s, int(ret), c.id, execID, timeStamp)
|
go cReap(s, int(ret), c.id, execID, timeStamp)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user