Teardown sandbox network after stop.

Signed-off-by: Lantao Liu <lantaol@google.com>
This commit is contained in:
Lantao Liu 2018-12-14 15:52:17 -08:00
parent afb12d728c
commit fbab182e5e

View File

@ -42,9 +42,8 @@ func (c *criService) StopPodSandbox(ctx context.Context, r *runtime.StopPodSandb
id := sandbox.ID id := sandbox.ID
// Stop all containers inside the sandbox. This terminates the container forcibly, // Stop all containers inside the sandbox. This terminates the container forcibly,
// and container may still be so production should not rely on this behavior. // and container may still be created, so production should not rely on this behavior.
// TODO(random-liu): Delete the sandbox container before this after permanent network namespace // TODO(random-liu): Introduce a state in sandbox to avoid future container creation.
// is introduced, so that no container will be started after that.
containers := c.containerStore.List() containers := c.containerStore.List()
for _, container := range containers { for _, container := range containers {
if container.SandboxID != id { if container.SandboxID != id {
@ -57,6 +56,17 @@ func (c *criService) StopPodSandbox(ctx context.Context, r *runtime.StopPodSandb
} }
} }
if err := c.unmountSandboxFiles(id, sandbox.Config); err != nil {
return nil, errors.Wrap(err, "failed to unmount sandbox files")
}
// Only stop sandbox container when it's running.
if sandbox.Status.Get().State == sandboxstore.StateReady {
if err := c.stopSandboxContainer(ctx, sandbox); err != nil {
return nil, errors.Wrapf(err, "failed to stop sandbox container %q", id)
}
}
// Teardown network for sandbox. // Teardown network for sandbox.
if sandbox.NetNS != nil { if sandbox.NetNS != nil {
netNSPath := sandbox.NetNSPath netNSPath := sandbox.NetNSPath
@ -77,16 +87,6 @@ func (c *criService) StopPodSandbox(ctx context.Context, r *runtime.StopPodSandb
logrus.Infof("TearDown network for sandbox %q successfully", id) logrus.Infof("TearDown network for sandbox %q successfully", id)
if err := c.unmountSandboxFiles(id, sandbox.Config); err != nil {
return nil, errors.Wrap(err, "failed to unmount sandbox files")
}
// Only stop sandbox container when it's running.
if sandbox.Status.Get().State == sandboxstore.StateReady {
if err := c.stopSandboxContainer(ctx, sandbox); err != nil {
return nil, errors.Wrapf(err, "failed to stop sandbox container %q", id)
}
}
return &runtime.StopPodSandboxResponse{}, nil return &runtime.StopPodSandboxResponse{}, nil
} }