Include pod namespace in the pod name

Signed-off-by: Mrunal Patel <mrunalp@gmail.com>
This commit is contained in:
Mrunal Patel 2016-09-22 16:02:46 -07:00
parent f5614a116f
commit 688f689736

View file

@ -24,7 +24,8 @@ type sandbox struct {
} }
const ( const (
podInfraRootfs = "/var/lib/ocid/graph/vfs/pause" podInfraRootfs = "/var/lib/ocid/graph/vfs/pause"
podDefaultNamespace = "default"
) )
func (s *sandbox) addContainer(c *oci.Container) { func (s *sandbox) addContainer(c *oci.Container) {
@ -39,12 +40,15 @@ func (s *sandbox) removeContainer(c *oci.Container) {
s.containers.Delete(c.Name()) 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 ( var (
err error err error
id = stringid.GenerateNonCryptoID() 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 "", "", err
} }
return id, name, 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") return nil, fmt.Errorf("PodSandboxConfig.Name should not be empty")
} }
namespace := req.GetConfig().GetMetadata().GetNamespace()
var err error var err error
id, name, err := s.generatePodIDandName(name) id, name, err := s.generatePodIDandName(name, namespace)
if err != nil { if err != nil {
return nil, err return nil, err
} }