Be more diligent about cleaning up failed-to-create containers
If server/Server.createSandboxContainer() fails after calling server/Server.StorageRuntimeServer().CreateContainer(), cleanup logic in server/Server.CreateContainer() won't try to clean it up, but we still need to clean up the on-disk container and its layer. Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
This commit is contained in:
parent
6a456d1502
commit
893aa4e8c7
1 changed files with 10 additions and 1 deletions
|
@ -1065,6 +1065,14 @@ func (s *Server) createSandboxContainer(ctx context.Context, containerID string,
|
|||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer func() {
|
||||
if err != nil {
|
||||
err2 := s.StorageRuntimeServer().DeleteContainer(containerInfo.ID)
|
||||
if err2 != nil {
|
||||
logrus.Warnf("Failed to cleanup container directory: %v", err2)
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
mountPoint, err := s.StorageRuntimeServer().StartContainer(containerID)
|
||||
if err != nil {
|
||||
|
@ -1074,7 +1082,8 @@ func (s *Server) createSandboxContainer(ctx context.Context, containerID string,
|
|||
|
||||
containerImageConfig := containerInfo.Config
|
||||
if containerImageConfig == nil {
|
||||
return nil, fmt.Errorf("empty image config for %s", image)
|
||||
err = fmt.Errorf("empty image config for %s", image)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if containerImageConfig.Config.StopSignal != "" {
|
||||
|
|
Loading…
Reference in a new issue