Automate the creation of the pod sandbox rootfs

Signed-off-by: Mrunal Patel <mrunalp@gmail.com>
This commit is contained in:
Mrunal Patel 2016-09-20 15:29:41 -07:00
parent e2f60be880
commit 0ba5dfc15a

View file

@ -9,6 +9,7 @@ import (
"github.com/Sirupsen/logrus" "github.com/Sirupsen/logrus"
"github.com/kubernetes-incubator/ocid/oci" "github.com/kubernetes-incubator/ocid/oci"
"github.com/kubernetes-incubator/ocid/utils"
pb "github.com/kubernetes/kubernetes/pkg/kubelet/api/v1alpha1/runtime" pb "github.com/kubernetes/kubernetes/pkg/kubelet/api/v1alpha1/runtime"
"github.com/opencontainers/ocitools/generate" "github.com/opencontainers/ocitools/generate"
"golang.org/x/net/context" "golang.org/x/net/context"
@ -27,6 +28,10 @@ type metadata struct {
Labels map[string]string `json:"labels"` Labels map[string]string `json:"labels"`
} }
const (
podInfraRootfs = "/var/lib/ocid/graph/vfs/pause"
)
func (s *sandbox) addContainer(c *oci.Container) { func (s *sandbox) addContainer(c *oci.Container) {
s.containers.Add(c.Name(), c) s.containers.Add(c.Name(), c)
} }
@ -70,7 +75,7 @@ func (s *Server) CreatePodSandbox(ctx context.Context, req *pb.CreatePodSandboxR
g := generate.New() g := generate.New()
// setup defaults for the pod sandbox // setup defaults for the pod sandbox
g.SetRootPath("/var/lib/ocid/graph/vfs/pause") g.SetRootPath(filepath.Join(podInfraRootfs, "rootfs"))
g.SetRootReadonly(true) g.SetRootReadonly(true)
g.SetProcessArgs([]string{"/pause"}) g.SetProcessArgs([]string{"/pause"})
@ -146,6 +151,17 @@ func (s *Server) CreatePodSandbox(ctx context.Context, req *pb.CreatePodSandboxR
return nil, err 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" containerName := name + "-infra"
container, err := oci.NewContainer(containerName, podSandboxDir, podSandboxDir, labels, name, false) container, err := oci.NewContainer(containerName, podSandboxDir, podSandboxDir, labels, name, false)
if err != nil { if err != nil {