From ec0b27fffc4c7e1dfceb0ed231b8eeecfc2f5afd Mon Sep 17 00:00:00 2001 From: Mrunal Patel Date: Thu, 6 Oct 2016 15:32:01 -0700 Subject: [PATCH] Add a helper method to get sandbox from request Signed-off-by: Mrunal Patel --- server/sandbox.go | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/server/sandbox.go b/server/sandbox.go index fcaa411d..7698fa6f 100644 --- a/server/sandbox.go +++ b/server/sandbox.go @@ -59,6 +59,28 @@ func (s *Server) generatePodIDandName(name string, namespace string, attempt uin return id, name, err } +type podSandboxRequest interface { + GetPodSandboxId() string +} + +func (s *Server) getPodSandboxFromRequest(req podSandboxRequest) (*sandbox, error) { + sbID := req.GetPodSandboxId() + if sbID == "" { + return nil, fmt.Errorf("PodSandboxId should not be empty") + } + + 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) + } + return sb, nil +} + // RunPodSandbox creates and runs a pod-level sandbox. func (s *Server) RunPodSandbox(ctx context.Context, req *pb.RunPodSandboxRequest) (*pb.RunPodSandboxResponse, error) { var processLabel, mountLabel string