Merge pull request #122 from Crazykev/fix-name-release

pod/container name should be released when create failed
This commit is contained in:
Mrunal Patel 2016-10-11 11:10:55 -07:00 committed by GitHub
commit 472893cfbe
3 changed files with 8 additions and 6 deletions

View file

@ -93,6 +93,7 @@ func (s *Server) CreateContainer(ctx context.Context, req *pb.CreateContainerReq
containerDir := filepath.Join(s.runtime.ContainerDir(), containerID) containerDir := filepath.Join(s.runtime.ContainerDir(), containerID)
defer func() { defer func() {
if err != nil { if err != nil {
s.releaseContainerName(containerName)
err1 := os.RemoveAll(containerDir) err1 := os.RemoveAll(containerDir)
if err1 != nil { if err1 != nil {
logrus.Warnf("Failed to cleanup container directory: %v") logrus.Warnf("Failed to cleanup container directory: %v")

View file

@ -104,18 +104,19 @@ func (s *Server) RunPodSandbox(ctx context.Context, req *pb.RunPodSandboxRequest
return nil, fmt.Errorf("pod sandbox (%s) already exists", podSandboxDir) return nil, fmt.Errorf("pod sandbox (%s) already exists", podSandboxDir)
} }
if err = os.MkdirAll(podSandboxDir, 0755); err != nil {
return nil, err
}
defer func() { defer func() {
if err != nil { if err != nil {
s.releasePodName(name)
if err2 := os.RemoveAll(podSandboxDir); err2 != nil { if err2 := os.RemoveAll(podSandboxDir); err2 != nil {
logrus.Warnf("couldn't cleanup podSandboxDir %s: %v", podSandboxDir, err2) logrus.Warnf("couldn't cleanup podSandboxDir %s: %v", podSandboxDir, err2)
} }
} }
}() }()
if err = os.MkdirAll(podSandboxDir, 0755); err != nil {
return nil, err
}
// creates a spec Generator with the default spec. // creates a spec Generator with the default spec.
g := generate.New() g := generate.New()

View file

@ -192,10 +192,10 @@ func (s *Server) reserveContainerName(id, name string) (string, error) {
if err == registrar.ErrNameReserved { if err == registrar.ErrNameReserved {
id, err := s.ctrNameIndex.Get(name) id, err := s.ctrNameIndex.Get(name)
if err != nil { if err != nil {
logrus.Warnf("name %s already reserved for %s", name, id) logrus.Warnf("get reserved name %s failed", name)
return "", err return "", err
} }
return "", fmt.Errorf("conflict, name %s already reserved", name) return "", fmt.Errorf("conflict, name %s already reserved for %s", name, id)
} }
return "", fmt.Errorf("error reserving name %s", name) return "", fmt.Errorf("error reserving name %s", name)
} }