Move StorageRuntimeServer into libkpod

Signed-off-by: Matthew Heon <mheon@redhat.com>
This commit is contained in:
Matthew Heon 2017-07-26 15:14:07 -04:00
parent 65f8fc850a
commit c65f7ac325
8 changed files with 54 additions and 71 deletions

View file

@ -21,6 +21,7 @@ type ContainerServer struct {
runtime *oci.Runtime runtime *oci.Runtime
store cstorage.Store store cstorage.Store
storageImageServer storage.ImageServer storageImageServer storage.ImageServer
storageRuntimeServer storage.RuntimeServer
ctrNameIndex *registrar.Registrar ctrNameIndex *registrar.Registrar
ctrIDIndex *truncindex.TruncIndex ctrIDIndex *truncindex.TruncIndex
podNameIndex *registrar.Registrar podNameIndex *registrar.Registrar
@ -47,6 +48,11 @@ func (c *ContainerServer) StorageImageServer() storage.ImageServer {
return c.storageImageServer return c.storageImageServer
} }
// StorageRuntimeServer returns the RuntimeServer for container storage
func (c *ContainerServer) StorageRuntimeServer() storage.RuntimeServer {
return c.storageRuntimeServer
}
// CtrNameIndex returns the Registrar for the ContainerServer // CtrNameIndex returns the Registrar for the ContainerServer
func (c *ContainerServer) CtrNameIndex() *registrar.Registrar { func (c *ContainerServer) CtrNameIndex() *registrar.Registrar {
return c.ctrNameIndex return c.ctrNameIndex
@ -114,6 +120,7 @@ func New(config *Config) (*ContainerServer, error) {
runtime: runtime, runtime: runtime,
store: store, store: store,
storageImageServer: imageService, storageImageServer: imageService,
storageRuntimeServer: storage.GetRuntimeService(imageService, pauseImage),
ctrNameIndex: registrar.NewRegistrar(), ctrNameIndex: registrar.NewRegistrar(),
ctrIDIndex: truncindex.NewTruncIndex([]string{}), ctrIDIndex: truncindex.NewTruncIndex([]string{}),
podNameIndex: registrar.NewRegistrar(), podNameIndex: registrar.NewRegistrar(),

View file

@ -314,7 +314,7 @@ func (s *Server) CreateContainer(ctx context.Context, req *pb.CreateContainerReq
} }
defer func() { defer func() {
if err != nil { if err != nil {
err2 := s.storageRuntimeServer.DeleteContainer(containerID) err2 := s.StorageRuntimeServer().DeleteContainer(containerID)
if err2 != nil { if err2 != nil {
logrus.Warnf("Failed to cleanup container directory: %v", err2) logrus.Warnf("Failed to cleanup container directory: %v", err2)
} }
@ -613,7 +613,7 @@ func (s *Server) createSandboxContainer(ctx context.Context, containerID string,
metaname := metadata.Name metaname := metadata.Name
attempt := metadata.Attempt attempt := metadata.Attempt
containerInfo, err := s.storageRuntimeServer.CreateContainer(s.ImageContext(), containerInfo, err := s.StorageRuntimeServer().CreateContainer(s.ImageContext(),
sb.Name(), sb.ID(), sb.Name(), sb.ID(),
image, image, image, image,
containerName, containerID, containerName, containerID,
@ -625,7 +625,7 @@ func (s *Server) createSandboxContainer(ctx context.Context, containerID string,
return nil, err return nil, err
} }
mountPoint, err := s.storageRuntimeServer.StartContainer(containerID) mountPoint, err := s.StorageRuntimeServer().StartContainer(containerID)
if err != nil { if err != nil {
return nil, fmt.Errorf("failed to mount container %s(%s): %v", containerName, containerID, err) return nil, fmt.Errorf("failed to mount container %s(%s): %v", containerName, containerID, err)
} }

View file

@ -27,7 +27,7 @@ func (s *Server) RemoveContainer(ctx context.Context, req *pb.RemoveContainerReq
if err := s.Runtime().StopContainer(c, -1); err != nil { if err := s.Runtime().StopContainer(c, -1); err != nil {
return nil, fmt.Errorf("failed to stop container %s: %v", c.ID(), err) return nil, fmt.Errorf("failed to stop container %s: %v", c.ID(), err)
} }
if err := s.storageRuntimeServer.StopContainer(c.ID()); err != nil { if err := s.StorageRuntimeServer().StopContainer(c.ID()); err != nil {
return nil, fmt.Errorf("failed to unmount container %s: %v", c.ID(), err) return nil, fmt.Errorf("failed to unmount container %s: %v", c.ID(), err)
} }
} }
@ -38,7 +38,7 @@ func (s *Server) RemoveContainer(ctx context.Context, req *pb.RemoveContainerReq
s.removeContainer(c) s.removeContainer(c)
if err := s.storageRuntimeServer.DeleteContainer(c.ID()); err != nil { if err := s.StorageRuntimeServer().DeleteContainer(c.ID()); err != nil {
return nil, fmt.Errorf("failed to delete storage for container %s: %v", c.ID(), err) return nil, fmt.Errorf("failed to delete storage for container %s: %v", c.ID(), err)
} }

View file

@ -25,7 +25,7 @@ func (s *Server) StopContainer(ctx context.Context, req *pb.StopContainerRequest
if err := s.Runtime().StopContainer(c, req.Timeout); err != nil { if err := s.Runtime().StopContainer(c, req.Timeout); err != nil {
return nil, fmt.Errorf("failed to stop container %s: %v", c.ID(), err) return nil, fmt.Errorf("failed to stop container %s: %v", c.ID(), err)
} }
if err := s.storageRuntimeServer.StopContainer(c.ID()); err != nil { if err := s.StorageRuntimeServer().StopContainer(c.ID()); err != nil {
return nil, fmt.Errorf("failed to unmount container %s: %v", c.ID(), err) return nil, fmt.Errorf("failed to unmount container %s: %v", c.ID(), err)
} }
} }

View file

@ -57,11 +57,11 @@ func (s *Server) RemovePodSandbox(ctx context.Context, req *pb.RemovePodSandboxR
continue continue
} }
if err := s.storageRuntimeServer.StopContainer(c.ID()); err != nil && err != storage.ErrContainerUnknown { if err := s.StorageRuntimeServer().StopContainer(c.ID()); err != nil && err != storage.ErrContainerUnknown {
// assume container already umounted // assume container already umounted
logrus.Warnf("failed to stop container %s in pod sandbox %s: %v", c.Name(), sb.ID(), err) logrus.Warnf("failed to stop container %s in pod sandbox %s: %v", c.Name(), sb.ID(), err)
} }
if err := s.storageRuntimeServer.DeleteContainer(c.ID()); err != nil && err != storage.ErrContainerUnknown { if err := s.StorageRuntimeServer().DeleteContainer(c.ID()); err != nil && err != storage.ErrContainerUnknown {
return nil, fmt.Errorf("failed to delete container %s in pod sandbox %s: %v", c.Name(), sb.ID(), err) return nil, fmt.Errorf("failed to delete container %s in pod sandbox %s: %v", c.Name(), sb.ID(), err)
} }
@ -75,10 +75,10 @@ func (s *Server) RemovePodSandbox(ctx context.Context, req *pb.RemovePodSandboxR
s.removeContainer(podInfraContainer) s.removeContainer(podInfraContainer)
// Remove the files related to the sandbox // Remove the files related to the sandbox
if err := s.storageRuntimeServer.StopContainer(sb.ID()); err != nil && err != storage.ErrContainerUnknown { if err := s.StorageRuntimeServer().StopContainer(sb.ID()); err != nil && err != storage.ErrContainerUnknown {
logrus.Warnf("failed to stop sandbox container in pod sandbox %s: %v", sb.ID(), err) logrus.Warnf("failed to stop sandbox container in pod sandbox %s: %v", sb.ID(), err)
} }
if err := s.storageRuntimeServer.RemovePodSandbox(sb.ID()); err != nil && err != pkgstorage.ErrInvalidSandboxID { if err := s.StorageRuntimeServer().RemovePodSandbox(sb.ID()); err != nil && err != pkgstorage.ErrInvalidSandboxID {
return nil, fmt.Errorf("failed to remove pod sandbox %s: %v", sb.ID(), err) return nil, fmt.Errorf("failed to remove pod sandbox %s: %v", sb.ID(), err)
} }

View file

@ -153,7 +153,7 @@ func (s *Server) RunPodSandbox(ctx context.Context, req *pb.RunPodSandboxRequest
} }
}() }()
podContainer, err := s.storageRuntimeServer.CreatePodSandbox(s.ImageContext(), podContainer, err := s.StorageRuntimeServer().CreatePodSandbox(s.ImageContext(),
name, id, name, id,
s.config.PauseImage, "", s.config.PauseImage, "",
containerName, containerName,
@ -170,7 +170,7 @@ func (s *Server) RunPodSandbox(ctx context.Context, req *pb.RunPodSandboxRequest
} }
defer func() { defer func() {
if err != nil { if err != nil {
if err2 := s.storageRuntimeServer.RemovePodSandbox(id); err2 != nil { if err2 := s.StorageRuntimeServer().RemovePodSandbox(id); err2 != nil {
logrus.Warnf("couldn't cleanup pod sandbox %q: %v", id, err2) logrus.Warnf("couldn't cleanup pod sandbox %q: %v", id, err2)
} }
} }
@ -447,7 +447,7 @@ func (s *Server) RunPodSandbox(ctx context.Context, req *pb.RunPodSandboxRequest
} }
saveOptions := generate.ExportOptions{} saveOptions := generate.ExportOptions{}
mountPoint, err := s.storageRuntimeServer.StartContainer(id) mountPoint, err := s.StorageRuntimeServer().StartContainer(id)
if err != nil { if err != nil {
return nil, fmt.Errorf("failed to mount container %s in pod sandbox %s(%s): %v", containerName, sb.Name(), id, err) return nil, fmt.Errorf("failed to mount container %s in pod sandbox %s(%s): %v", containerName, sb.Name(), id, err)
} }
@ -524,12 +524,12 @@ func convertPortMappings(in []*pb.PortMapping) []*hostport.PortMapping {
} }
func (s *Server) setPodSandboxMountLabel(id, mountLabel string) error { func (s *Server) setPodSandboxMountLabel(id, mountLabel string) error {
storageMetadata, err := s.storageRuntimeServer.GetContainerMetadata(id) storageMetadata, err := s.StorageRuntimeServer().GetContainerMetadata(id)
if err != nil { if err != nil {
return err return err
} }
storageMetadata.SetMountLabel(mountLabel) storageMetadata.SetMountLabel(mountLabel)
return s.storageRuntimeServer.SetContainerMetadata(id, storageMetadata) return s.StorageRuntimeServer().SetContainerMetadata(id, storageMetadata)
} }
func getSELinuxLabels(selinuxOptions *pb.SELinuxOption) (processLabel string, mountLabel string, err error) { func getSELinuxLabels(selinuxOptions *pb.SELinuxOption) (processLabel string, mountLabel string, err error) {

View file

@ -80,7 +80,7 @@ func (s *Server) StopPodSandbox(ctx context.Context, req *pb.StopPodSandboxReque
if c.ID() == podInfraContainer.ID() { if c.ID() == podInfraContainer.ID() {
continue continue
} }
if err := s.storageRuntimeServer.StopContainer(c.ID()); err != nil && err != storage.ErrContainerUnknown { if err := s.StorageRuntimeServer().StopContainer(c.ID()); err != nil && err != storage.ErrContainerUnknown {
// assume container already umounted // assume container already umounted
logrus.Warnf("failed to stop container %s in pod sandbox %s: %v", c.Name(), sb.ID(), err) logrus.Warnf("failed to stop container %s in pod sandbox %s: %v", c.Name(), sb.ID(), err)
} }
@ -108,7 +108,7 @@ func (s *Server) StopPodSandbox(ctx context.Context, req *pb.StopPodSandboxReque
} }
} }
} }
if err := s.storageRuntimeServer.StopContainer(sb.ID()); err != nil && err != storage.ErrContainerUnknown { if err := s.StorageRuntimeServer().StopContainer(sb.ID()); err != nil && err != storage.ErrContainerUnknown {
logrus.Warnf("failed to stop sandbox container in pod sandbox %s: %v", sb.ID(), err) logrus.Warnf("failed to stop sandbox container in pod sandbox %s: %v", sb.ID(), err)
} }

View file

@ -11,7 +11,6 @@ import (
"time" "time"
"github.com/Sirupsen/logrus" "github.com/Sirupsen/logrus"
cstorage "github.com/containers/storage"
"github.com/kubernetes-incubator/cri-o/libkpod" "github.com/kubernetes-incubator/cri-o/libkpod"
"github.com/kubernetes-incubator/cri-o/libkpod/sandbox" "github.com/kubernetes-incubator/cri-o/libkpod/sandbox"
"github.com/kubernetes-incubator/cri-o/oci" "github.com/kubernetes-incubator/cri-o/oci"
@ -53,11 +52,9 @@ type Server struct {
libkpod.ContainerServer libkpod.ContainerServer
config Config config Config
storageRuntimeServer storage.RuntimeServer
updateLock sync.RWMutex updateLock sync.RWMutex
netPlugin ocicni.CNIPlugin netPlugin ocicni.CNIPlugin
hostportManager hostport.HostPortManager hostportManager hostport.HostPortManager
seccompEnabled bool seccompEnabled bool
seccompProfile seccomp.Seccomp seccompProfile seccomp.Seccomp
@ -292,7 +289,7 @@ func (s *Server) restore() {
pods := map[string]*storage.RuntimeContainerMetadata{} pods := map[string]*storage.RuntimeContainerMetadata{}
podContainers := map[string]*storage.RuntimeContainerMetadata{} podContainers := map[string]*storage.RuntimeContainerMetadata{}
for _, container := range containers { for _, container := range containers {
metadata, err2 := s.storageRuntimeServer.GetContainerMetadata(container.ID) metadata, err2 := s.StorageRuntimeServer().GetContainerMetadata(container.ID)
if err2 != nil { if err2 != nil {
logrus.Warnf("error parsing metadata for %s: %v, ignoring", container.ID, err2) logrus.Warnf("error parsing metadata for %s: %v, ignoring", container.ID, err2)
continue continue
@ -353,7 +350,7 @@ func (s *Server) update() error {
continue continue
} }
// not previously known, so figure out what it is // not previously known, so figure out what it is
metadata, err2 := s.storageRuntimeServer.GetContainerMetadata(container.ID) metadata, err2 := s.StorageRuntimeServer().GetContainerMetadata(container.ID)
if err2 != nil { if err2 != nil {
logrus.Errorf("error parsing metadata for %s: %v, ignoring", container.ID, err2) logrus.Errorf("error parsing metadata for %s: %v, ignoring", container.ID, err2)
continue continue
@ -456,26 +453,6 @@ func (s *Server) Shutdown() error {
// New creates a new Server with options provided // New creates a new Server with options provided
func New(config *Config) (*Server, error) { func New(config *Config) (*Server, error) {
store, err := cstorage.GetStore(cstorage.StoreOptions{
RunRoot: config.RunRoot,
GraphRoot: config.Root,
GraphDriverName: config.Storage,
GraphDriverOptions: config.StorageOptions,
})
if err != nil {
return nil, err
}
imageService, err := storage.GetImageService(store, config.DefaultTransport, config.InsecureRegistries)
if err != nil {
return nil, err
}
storageRuntimeService := storage.GetRuntimeService(imageService, config.PauseImage)
if err != nil {
return nil, err
}
if err := os.MkdirAll("/var/run/crio", 0755); err != nil { if err := os.MkdirAll("/var/run/crio", 0755); err != nil {
return nil, err return nil, err
} }
@ -494,7 +471,6 @@ func New(config *Config) (*Server, error) {
s := &Server{ s := &Server{
ContainerServer: *containerServer, ContainerServer: *containerServer,
storageRuntimeServer: storageRuntimeService,
netPlugin: netPlugin, netPlugin: netPlugin,
hostportManager: hostportManager, hostportManager: hostportManager,
config: *config, config: *config,