cmd/server: provide a flag to set ocid root dir

Signed-off-by: Antonio Murdaca <runcom@redhat.com>
This commit is contained in:
Antonio Murdaca 2016-09-21 10:59:37 +02:00
parent a16a4df967
commit 857aaa7816
No known key found for this signature in database
GPG key ID: B2BEAD150DE936B9
3 changed files with 17 additions and 4 deletions

View file

@ -4,6 +4,7 @@ import (
"fmt"
"net"
"os"
"path/filepath"
"github.com/Sirupsen/logrus"
"github.com/kubernetes-incubator/ocid/server"
@ -12,6 +13,10 @@ import (
"k8s.io/kubernetes/pkg/kubelet/api/v1alpha1/runtime"
)
const (
ocidRoot = "/var/lib/ocid"
)
func main() {
app := cli.NewApp()
app.Name = "ocid"
@ -19,14 +24,19 @@ func main() {
app.Version = "0.0.1"
app.Flags = []cli.Flag{
cli.StringFlag{
Name: "root",
Value: ocidRoot,
Usage: "ocid root dir",
},
cli.StringFlag{
Name: "sandboxdir",
Value: "/var/lib/ocid/sandboxes",
Value: filepath.Join(ocidRoot, "sandboxes"),
Usage: "ocid pod sandbox dir",
},
cli.StringFlag{
Name: "containerdir",
Value: "/var/lib/ocid/containers",
Value: filepath.Join(ocidRoot, "containers"),
Usage: "ocid container dir",
},
cli.StringFlag{
@ -94,7 +104,7 @@ func main() {
containerDir := c.String("containerdir")
sandboxDir := c.String("sandboxdir")
service, err := server.New(c.String("runtime"), sandboxDir, containerDir)
service, err := server.New(c.String("runtime"), c.String("root"), sandboxDir, containerDir)
if err != nil {
logrus.Fatal(err)
}

View file

@ -89,6 +89,7 @@ func (s *Server) CreatePodSandbox(ctx context.Context, req *pb.CreatePodSandboxR
// creates a spec Generator with the default spec.
g := generate.New()
podInfraRootfs := filepath.Join(s.root, "graph/vfs/pause")
// setup defaults for the pod sandbox
g.SetRootPath(filepath.Join(podInfraRootfs, "rootfs"))
g.SetRootReadonly(true)

View file

@ -24,6 +24,7 @@ const (
// Server implements the RuntimeService and ImageService
type Server struct {
root string
runtime *oci.Runtime
sandboxDir string
stateLock sync.Mutex
@ -102,7 +103,7 @@ func (s *Server) reservePodName(id, name string) (string, error) {
}
// New creates a new Server with options provided
func New(runtimePath, sandboxDir, containerDir string) (*Server, error) {
func New(runtimePath, root, sandboxDir, containerDir string) (*Server, error) {
// TODO: This will go away later when we have wrapper process or systemd acting as
// subreaper.
if err := utils.SetSubreaper(1); err != nil {
@ -130,6 +131,7 @@ func New(runtimePath, sandboxDir, containerDir string) (*Server, error) {
return nil, err
}
s := &Server{
root: root,
runtime: r,
netPlugin: netPlugin,
sandboxDir: sandboxDir,