From 0ba5dfc15a844ee784489613f18f6affd03b4fa0 Mon Sep 17 00:00:00 2001 From: Mrunal Patel Date: Tue, 20 Sep 2016 15:29:41 -0700 Subject: [PATCH] Automate the creation of the pod sandbox rootfs Signed-off-by: Mrunal Patel --- server/sandbox.go | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/server/sandbox.go b/server/sandbox.go index a0418e06..50d7c090 100644 --- a/server/sandbox.go +++ b/server/sandbox.go @@ -9,6 +9,7 @@ import ( "github.com/Sirupsen/logrus" "github.com/kubernetes-incubator/ocid/oci" + "github.com/kubernetes-incubator/ocid/utils" pb "github.com/kubernetes/kubernetes/pkg/kubelet/api/v1alpha1/runtime" "github.com/opencontainers/ocitools/generate" "golang.org/x/net/context" @@ -27,6 +28,10 @@ type metadata struct { Labels map[string]string `json:"labels"` } +const ( + podInfraRootfs = "/var/lib/ocid/graph/vfs/pause" +) + func (s *sandbox) addContainer(c *oci.Container) { s.containers.Add(c.Name(), c) } @@ -70,7 +75,7 @@ func (s *Server) CreatePodSandbox(ctx context.Context, req *pb.CreatePodSandboxR g := generate.New() // setup defaults for the pod sandbox - g.SetRootPath("/var/lib/ocid/graph/vfs/pause") + g.SetRootPath(filepath.Join(podInfraRootfs, "rootfs")) g.SetRootReadonly(true) g.SetProcessArgs([]string{"/pause"}) @@ -146,6 +151,17 @@ func (s *Server) CreatePodSandbox(ctx context.Context, req *pb.CreatePodSandboxR return nil, err } + if _, err = os.Stat(podInfraRootfs); err != nil { + if os.IsNotExist(err) { + // TODO: Replace by rootfs creation API when it is ready + if err := utils.CreateFakeRootfs(podInfraRootfs, "docker://kubernetes/pause"); err != nil { + return nil, err + } + } else { + return nil, err + } + } + containerName := name + "-infra" container, err := oci.NewContainer(containerName, podSandboxDir, podSandboxDir, labels, name, false) if err != nil {