Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion server/container_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,7 @@ func (s *Server) CreateContainer(ctx context.Context, req *pb.CreateContainerReq
defer func() {
if retErr != nil {
log.Infof(ctx, "createCtr: deleting container ID %s from idIndex", ctr.ID())
if err2 := s.CtrIDIndex().Delete(ctr.ID()); err2 != nil {
if err := s.CtrIDIndex().Delete(ctr.ID()); err != nil {
log.Warnf(ctx, "couldn't delete ctr id %s from idIndex", ctr.ID())
}
}
Expand All @@ -541,6 +541,14 @@ func (s *Server) CreateContainer(ctx context.Context, req *pb.CreateContainerReq
if err := s.createContainerPlatform(newContainer, sb.CgroupParent(), mappings); err != nil {
return nil, err
}
defer func() {
if retErr != nil {
log.Infof(ctx, "createCtr: removing container ID %s from runtime", ctr.ID())
if err := s.Runtime().DeleteContainer(newContainer); err != nil {
log.Warnf(ctx, "failed to delete container in runtime %s: %v", ctr.ID(), err)
}
}
}()

if err := s.ContainerStateToDisk(newContainer); err != nil {
log.Warnf(ctx, "unable to write containers %s state to disk: %v", newContainer.ID(), err)
Expand Down
18 changes: 8 additions & 10 deletions server/container_create_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,14 @@ func (s *Server) createSandboxContainer(ctx context.Context, ctr ctrIface.Contai
if err != nil {
return nil, err
}
defer func() {
if retErr != nil {
log.Infof(ctx, "createCtrLinux: deleting container %s from storage", containerInfo.ID)
if err := s.StorageRuntimeServer().DeleteContainer(containerInfo.ID); err != nil {
log.Warnf(ctx, "Failed to cleanup container directory: %v", err)
}
}
}()

mountLabel := containerInfo.MountLabel
var processLabel string
Expand All @@ -391,16 +399,6 @@ func (s *Server) createSandboxContainer(ctx context.Context, ctr ctrIface.Contai
processLabel = ""
}

defer func() {
if retErr != nil {
log.Infof(ctx, "createCtrLinux: deleting container %s from storage", containerInfo.ID)
err2 := s.StorageRuntimeServer().DeleteContainer(containerInfo.ID)
if err2 != nil {
log.Warnf(ctx, "Failed to cleanup container directory: %v", err2)
}
}
}()

containerVolumes, ociMounts, err := addOCIBindMounts(ctx, mountLabel, containerConfig, specgen, s.config.RuntimeConfig.BindMountPrefix)
if err != nil {
return nil, err
Expand Down