sandbox_stop: Call CNI stop before stopping pod infra container
Signed-off-by: Mrunal Patel <mrunalp@gmail.com>
This commit is contained in:
parent
e8c108d415
commit
b487411b65
1 changed files with 13 additions and 3 deletions
|
@ -56,6 +56,9 @@ func (s *Server) StopPodSandbox(ctx context.Context, req *pb.StopPodSandboxReque
|
||||||
for _, c := range containers {
|
for _, c := range containers {
|
||||||
cStatus := s.Runtime().ContainerStatus(c)
|
cStatus := s.Runtime().ContainerStatus(c)
|
||||||
if cStatus.Status != oci.ContainerStateStopped {
|
if cStatus.Status != oci.ContainerStateStopped {
|
||||||
|
if c.ID() == podInfraContainer.ID() {
|
||||||
|
continue
|
||||||
|
}
|
||||||
timeout := int64(10)
|
timeout := int64(10)
|
||||||
if err := s.Runtime().StopContainer(ctx, c, timeout); err != nil {
|
if err := s.Runtime().StopContainer(ctx, c, timeout); err != nil {
|
||||||
return nil, fmt.Errorf("failed to stop container %s in pod sandbox %s: %v", c.Name(), sb.ID(), err)
|
return nil, fmt.Errorf("failed to stop container %s in pod sandbox %s: %v", c.Name(), sb.ID(), err)
|
||||||
|
@ -63,9 +66,6 @@ func (s *Server) StopPodSandbox(ctx context.Context, req *pb.StopPodSandboxReque
|
||||||
if err := s.Runtime().WaitContainerStateStopped(ctx, c, timeout); err != nil {
|
if err := s.Runtime().WaitContainerStateStopped(ctx, c, timeout); err != nil {
|
||||||
return nil, fmt.Errorf("failed to get container 'stopped' status %s in pod sandbox %s: %v", c.Name(), sb.ID(), err)
|
return nil, fmt.Errorf("failed to get container 'stopped' status %s in pod sandbox %s: %v", c.Name(), sb.ID(), err)
|
||||||
}
|
}
|
||||||
if c.ID() == podInfraContainer.ID() {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
if err := s.StorageRuntimeServer().StopContainer(c.ID()); err != nil && errors.Cause(err) != storage.ErrContainerUnknown {
|
if err := s.StorageRuntimeServer().StopContainer(c.ID()); err != nil && errors.Cause(err) != storage.ErrContainerUnknown {
|
||||||
// assume container already umounted
|
// assume container already umounted
|
||||||
logrus.Warnf("failed to stop container %s in pod sandbox %s: %v", c.Name(), sb.ID(), err)
|
logrus.Warnf("failed to stop container %s in pod sandbox %s: %v", c.Name(), sb.ID(), err)
|
||||||
|
@ -77,6 +77,16 @@ func (s *Server) StopPodSandbox(ctx context.Context, req *pb.StopPodSandboxReque
|
||||||
// Clean up sandbox networking and close its network namespace.
|
// Clean up sandbox networking and close its network namespace.
|
||||||
hostNetwork := sb.NetNsPath() == ""
|
hostNetwork := sb.NetNsPath() == ""
|
||||||
s.networkStop(hostNetwork, sb)
|
s.networkStop(hostNetwork, sb)
|
||||||
|
podInfraStatus := s.Runtime().ContainerStatus(podInfraContainer)
|
||||||
|
if podInfraStatus.Status != oci.ContainerStateStopped {
|
||||||
|
timeout := int64(10)
|
||||||
|
if err := s.Runtime().StopContainer(ctx, podInfraContainer, timeout); err != nil {
|
||||||
|
return nil, fmt.Errorf("failed to stop infra container %s in pod sandbox %s: %v", podInfraContainer.Name(), sb.ID(), err)
|
||||||
|
}
|
||||||
|
if err := s.Runtime().WaitContainerStateStopped(ctx, podInfraContainer, timeout); err != nil {
|
||||||
|
return nil, fmt.Errorf("failed to get infra container 'stopped' status %s in pod sandbox %s: %v", podInfraContainer.Name(), sb.ID(), err)
|
||||||
|
}
|
||||||
|
}
|
||||||
if err := sb.NetNsRemove(); err != nil {
|
if err := sb.NetNsRemove(); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue