Add a helper to get container from request
Signed-off-by: Mrunal Patel <mrunalp@gmail.com>
This commit is contained in:
parent
027aaf15b7
commit
a56cbb4117
1 changed files with 22 additions and 0 deletions
|
@ -41,6 +41,28 @@ func (s *Server) generateContainerIDandName(podName string, name string, attempt
|
||||||
return id, name, err
|
return id, name, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type containerRequest interface {
|
||||||
|
GetContainerId() string
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *Server) getContainerFromRequest(req containerRequest) (*oci.Container, error) {
|
||||||
|
ctrID := req.GetContainerId()
|
||||||
|
if ctrID == "" {
|
||||||
|
return nil, fmt.Errorf("container ID should not be empty")
|
||||||
|
}
|
||||||
|
|
||||||
|
containerID, err := s.ctrIDIndex.Get(ctrID)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("container with ID starting with %s not found: %v", ctrID, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
c := s.state.containers.Get(containerID)
|
||||||
|
if c == nil {
|
||||||
|
return nil, fmt.Errorf("specified container not found: %s", containerID)
|
||||||
|
}
|
||||||
|
return c, nil
|
||||||
|
}
|
||||||
|
|
||||||
// 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) (res *pb.CreateContainerResponse, err error) {
|
func (s *Server) CreateContainer(ctx context.Context, req *pb.CreateContainerRequest) (res *pb.CreateContainerResponse, err error) {
|
||||||
sbID := req.GetPodSandboxId()
|
sbID := req.GetPodSandboxId()
|
||||||
|
|
Loading…
Reference in a new issue