From 1f4a4742cb19c2398857a35d8d3a1130725dc993 Mon Sep 17 00:00:00 2001 From: Antonio Murdaca Date: Thu, 11 May 2017 11:12:37 +0200 Subject: [PATCH] oci: add container directory to Container struct Signed-off-by: Antonio Murdaca --- oci/container.go | 8 ++++++-- server/container_create.go | 2 +- server/sandbox_run.go | 2 +- server/server.go | 14 ++++++++++++-- 4 files changed, 20 insertions(+), 6 deletions(-) diff --git a/oci/container.go b/oci/container.go index 9ac624e4..ea8856c0 100644 --- a/oci/container.go +++ b/oci/container.go @@ -15,7 +15,6 @@ import ( type Container struct { id string name string - bundlePath string logPath string labels fields.Set annotations fields.Set @@ -27,6 +26,10 @@ type Container struct { state *ContainerState metadata *pb.ContainerMetadata opLock sync.Mutex + // this is the /var/run/storage/... directory, erased on reboot + bundlePath string + // this is the /var/lib/storage/... directory + dir string } // ContainerState represents the status of a container. @@ -39,7 +42,7 @@ type ContainerState struct { } // NewContainer creates a container object. -func NewContainer(id string, name string, bundlePath string, logPath string, netns ns.NetNS, labels map[string]string, annotations map[string]string, image *pb.ImageSpec, metadata *pb.ContainerMetadata, sandbox string, terminal bool, privileged bool) (*Container, error) { +func NewContainer(id string, name string, bundlePath string, logPath string, netns ns.NetNS, labels map[string]string, annotations map[string]string, image *pb.ImageSpec, metadata *pb.ContainerMetadata, sandbox string, terminal bool, privileged bool, dir string) (*Container, error) { c := &Container{ id: id, name: name, @@ -53,6 +56,7 @@ func NewContainer(id string, name string, bundlePath string, logPath string, net metadata: metadata, annotations: annotations, image: image, + dir: dir, } return c, nil } diff --git a/server/container_create.go b/server/container_create.go index d9f8dbf8..28eb3f75 100644 --- a/server/container_create.go +++ b/server/container_create.go @@ -648,7 +648,7 @@ func (s *Server) createSandboxContainer(ctx context.Context, containerID string, return nil, err } - container, err := oci.NewContainer(containerID, containerName, containerInfo.RunDir, logPath, sb.netNs(), labels, annotations, imageSpec, metadata, sb.id, containerConfig.Tty, sb.privileged) + container, err := oci.NewContainer(containerID, containerName, containerInfo.RunDir, logPath, sb.netNs(), labels, annotations, imageSpec, metadata, sb.id, containerConfig.Tty, sb.privileged, containerInfo.Dir) if err != nil { return nil, err } diff --git a/server/sandbox_run.go b/server/sandbox_run.go index 6359be17..77204a52 100644 --- a/server/sandbox_run.go +++ b/server/sandbox_run.go @@ -408,7 +408,7 @@ func (s *Server) RunPodSandbox(ctx context.Context, req *pb.RunPodSandboxRequest return nil, fmt.Errorf("failed to write runtime configuration for pod sandbox %s(%s): %v", sb.name, id, err) } - container, err := oci.NewContainer(id, containerName, podContainer.RunDir, logPath, sb.netNs(), labels, annotations, nil, nil, id, false, sb.privileged) + container, err := oci.NewContainer(id, containerName, podContainer.RunDir, logPath, sb.netNs(), labels, annotations, nil, nil, id, false, sb.privileged, podContainer.Dir) if err != nil { return nil, err } diff --git a/server/server.go b/server/server.go index ce9564c1..647f6892 100644 --- a/server/server.go +++ b/server/server.go @@ -121,6 +121,11 @@ func (s *Server) loadContainer(id string) error { return err } + containerDir, err := s.store.GetContainerDirectory(id) + if err != nil { + return err + } + var img *pb.ImageSpec image, ok := m.Annotations["crio/image"] if ok { @@ -134,7 +139,7 @@ func (s *Server) loadContainer(id string) error { return err } - ctr, err := oci.NewContainer(id, name, containerPath, m.Annotations["crio/log_path"], sb.netNs(), labels, annotations, img, &metadata, sb.id, tty, sb.privileged) + ctr, err := oci.NewContainer(id, name, containerPath, m.Annotations["crio/log_path"], sb.netNs(), labels, annotations, img, &metadata, sb.id, tty, sb.privileged, containerDir) if err != nil { return err } @@ -251,6 +256,11 @@ func (s *Server) loadSandbox(id string) error { return err } + sandboxDir, err := s.store.GetContainerDirectory(id) + if err != nil { + return err + } + cname, err := s.reserveContainerName(m.Annotations["crio/container_id"], m.Annotations["crio/container_name"]) if err != nil { return err @@ -261,7 +271,7 @@ func (s *Server) loadSandbox(id string) error { } }() - scontainer, err := oci.NewContainer(m.Annotations["crio/container_id"], cname, sandboxPath, m.Annotations["crio/log_path"], sb.netNs(), labels, annotations, nil, nil, id, false, privileged) + scontainer, err := oci.NewContainer(m.Annotations["crio/container_id"], cname, sandboxPath, m.Annotations["crio/log_path"], sb.netNs(), labels, annotations, nil, nil, id, false, privileged, sandboxDir) if err != nil { return err }