From 688f68973648d133406adda4412cc42c1c450ecc Mon Sep 17 00:00:00 2001 From: Mrunal Patel Date: Thu, 22 Sep 2016 16:02:46 -0700 Subject: [PATCH] Include pod namespace in the pod name Signed-off-by: Mrunal Patel --- server/sandbox.go | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/server/sandbox.go b/server/sandbox.go index d66d6ee7..e43b0b83 100644 --- a/server/sandbox.go +++ b/server/sandbox.go @@ -24,7 +24,8 @@ type sandbox struct { } const ( - podInfraRootfs = "/var/lib/ocid/graph/vfs/pause" + podInfraRootfs = "/var/lib/ocid/graph/vfs/pause" + podDefaultNamespace = "default" ) func (s *sandbox) addContainer(c *oci.Container) { @@ -39,12 +40,15 @@ func (s *sandbox) removeContainer(c *oci.Container) { s.containers.Delete(c.Name()) } -func (s *Server) generatePodIDandName(name string) (string, string, error) { +func (s *Server) generatePodIDandName(name, namespace string) (string, string, error) { var ( err error id = stringid.GenerateNonCryptoID() ) - if name, err = s.reservePodName(id, name); err != nil { + if namespace == "" { + namespace = podDefaultNamespace + } + if name, err = s.reservePodName(id, namespace+"-"+name); err != nil { return "", "", err } return id, name, err @@ -59,8 +63,10 @@ func (s *Server) CreatePodSandbox(ctx context.Context, req *pb.CreatePodSandboxR return nil, fmt.Errorf("PodSandboxConfig.Name should not be empty") } + namespace := req.GetConfig().GetMetadata().GetNamespace() + var err error - id, name, err := s.generatePodIDandName(name) + id, name, err := s.generatePodIDandName(name, namespace) if err != nil { return nil, err }