Allow specifying short pod IDs for container create
Signed-off-by: Mrunal Patel <mrunalp@gmail.com>
This commit is contained in:
parent
2e387072ac
commit
833333538e
1 changed files with 16 additions and 7 deletions
|
@ -25,12 +25,21 @@ const (
|
||||||
|
|
||||||
// CreateContainer creates a new container in specified PodSandbox
|
// CreateContainer creates a new container in specified PodSandbox
|
||||||
func (s *Server) CreateContainer(ctx context.Context, req *pb.CreateContainerRequest) (*pb.CreateContainerResponse, error) {
|
func (s *Server) CreateContainer(ctx context.Context, req *pb.CreateContainerRequest) (*pb.CreateContainerResponse, error) {
|
||||||
// The id of the PodSandbox
|
sbID := req.GetPodSandboxId()
|
||||||
podSandboxID := req.GetPodSandboxId()
|
if sbID == "" {
|
||||||
sb := s.getSandbox(podSandboxID)
|
return nil, fmt.Errorf("PodSandboxId should not be empty")
|
||||||
if sb == nil {
|
|
||||||
return nil, fmt.Errorf("the pod sandbox (%s) does not exist", podSandboxID)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sandboxID, err := s.podIDIndex.Get(sbID)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("PodSandbox with ID starting with %s not found: %v", sbID, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
sb := s.getSandbox(sandboxID)
|
||||||
|
if sb == nil {
|
||||||
|
return nil, fmt.Errorf("specified sandbox not found: %s", sandboxID)
|
||||||
|
}
|
||||||
|
|
||||||
// The config of the container
|
// The config of the container
|
||||||
containerConfig := req.GetConfig()
|
containerConfig := req.GetConfig()
|
||||||
if containerConfig == nil {
|
if containerConfig == nil {
|
||||||
|
@ -45,11 +54,11 @@ func (s *Server) CreateContainer(ctx context.Context, req *pb.CreateContainerReq
|
||||||
// containerDir is the dir for the container bundle.
|
// containerDir is the dir for the container bundle.
|
||||||
containerDir := filepath.Join(s.runtime.ContainerDir(), name)
|
containerDir := filepath.Join(s.runtime.ContainerDir(), name)
|
||||||
|
|
||||||
if _, err := os.Stat(containerDir); err == nil {
|
if _, err = os.Stat(containerDir); err == nil {
|
||||||
return nil, fmt.Errorf("container (%s) already exists", containerDir)
|
return nil, fmt.Errorf("container (%s) already exists", containerDir)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := os.MkdirAll(containerDir, 0755); err != nil {
|
if err = os.MkdirAll(containerDir, 0755); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue