Merge pull request #460 from vbatts/readable_server_fields

server: readable fields
This commit is contained in:
Antonio Murdaca 2017-04-21 00:54:35 +02:00 committed by GitHub
commit 339e01ba79
11 changed files with 72 additions and 72 deletions

View file

@ -39,8 +39,8 @@ var (
)
type runtimeService struct {
imageServer ImageServer
pauseImage string
storageImageServer ImageServer
pauseImage string
}
// ContainerInfo wraps a subset of information about a container: its ID and
@ -159,22 +159,22 @@ func (r *runtimeService) createContainerOrPodSandbox(systemContext *types.System
}
// Check if we have the specified image.
ref, err := istorage.Transport.ParseStoreReference(r.imageServer.GetStore(), imageName)
ref, err := istorage.Transport.ParseStoreReference(r.storageImageServer.GetStore(), imageName)
if err != nil {
// Maybe it's some other transport's copy of the image?
otherRef, err2 := alltransports.ParseImageName(imageName)
if err2 == nil && otherRef.DockerReference() != nil {
ref, err = istorage.Transport.ParseStoreReference(r.imageServer.GetStore(), otherRef.DockerReference().Name())
ref, err = istorage.Transport.ParseStoreReference(r.storageImageServer.GetStore(), otherRef.DockerReference().Name())
}
if err != nil {
// Maybe the image ID is sufficient?
ref, err = istorage.Transport.ParseStoreReference(r.imageServer.GetStore(), "@"+imageID)
ref, err = istorage.Transport.ParseStoreReference(r.storageImageServer.GetStore(), "@"+imageID)
if err != nil {
return ContainerInfo{}, err
}
}
}
img, err := istorage.Transport.GetStoreImage(r.imageServer.GetStore(), ref)
img, err := istorage.Transport.GetStoreImage(r.storageImageServer.GetStore(), ref)
if img == nil && err == storage.ErrImageUnknown && imageName == r.pauseImage {
image := imageID
if imageName != "" {
@ -184,11 +184,11 @@ func (r *runtimeService) createContainerOrPodSandbox(systemContext *types.System
return ContainerInfo{}, ErrInvalidImageName
}
logrus.Debugf("couldn't find image %q, retrieving it", image)
ref, err = r.imageServer.PullImage(systemContext, image, options)
ref, err = r.storageImageServer.PullImage(systemContext, image, options)
if err != nil {
return ContainerInfo{}, err
}
img, err = istorage.Transport.GetStoreImage(r.imageServer.GetStore(), ref)
img, err = istorage.Transport.GetStoreImage(r.storageImageServer.GetStore(), ref)
if err != nil {
return ContainerInfo{}, err
}
@ -247,7 +247,7 @@ func (r *runtimeService) createContainerOrPodSandbox(systemContext *types.System
if metadata.Pod {
names = append(names, metadata.PodName)
}
container, err := r.imageServer.GetStore().CreateContainer(containerID, names, img.ID, "", string(mdata), nil)
container, err := r.storageImageServer.GetStore().CreateContainer(containerID, names, img.ID, "", string(mdata), nil)
if err != nil {
if metadata.Pod {
logrus.Debugf("failed to create pod sandbox %s(%s): %v", metadata.PodName, metadata.PodID, err)
@ -266,7 +266,7 @@ func (r *runtimeService) createContainerOrPodSandbox(systemContext *types.System
// container before returning.
defer func() {
if err != nil {
if err2 := r.imageServer.GetStore().DeleteContainer(container.ID); err2 != nil {
if err2 := r.storageImageServer.GetStore().DeleteContainer(container.ID); err2 != nil {
if metadata.Pod {
logrus.Infof("%v deleting partially-created pod sandbox %q", err2, container.ID)
} else {
@ -281,18 +281,18 @@ func (r *runtimeService) createContainerOrPodSandbox(systemContext *types.System
// Add a name to the container's layer so that it's easier to follow
// what's going on if we're just looking at the storage-eye view of things.
layerName := metadata.ContainerName + "-layer"
names, err = r.imageServer.GetStore().GetNames(container.LayerID)
names, err = r.storageImageServer.GetStore().GetNames(container.LayerID)
if err != nil {
return ContainerInfo{}, err
}
names = append(names, layerName)
err = r.imageServer.GetStore().SetNames(container.LayerID, names)
err = r.storageImageServer.GetStore().SetNames(container.LayerID, names)
if err != nil {
return ContainerInfo{}, err
}
// Find out where the container work directories are, so that we can return them.
containerDir, err := r.imageServer.GetStore().GetContainerDirectory(container.ID)
containerDir, err := r.storageImageServer.GetStore().GetContainerDirectory(container.ID)
if err != nil {
return ContainerInfo{}, err
}
@ -302,7 +302,7 @@ func (r *runtimeService) createContainerOrPodSandbox(systemContext *types.System
logrus.Debugf("container %q has work directory %q", container.ID, containerDir)
}
containerRunDir, err := r.imageServer.GetStore().GetContainerRunDirectory(container.ID)
containerRunDir, err := r.storageImageServer.GetStore().GetContainerRunDirectory(container.ID)
if err != nil {
return ContainerInfo{}, err
}
@ -329,14 +329,14 @@ func (r *runtimeService) CreateContainer(systemContext *types.SystemContext, pod
}
func (r *runtimeService) RemovePodSandbox(idOrName string) error {
container, err := r.imageServer.GetStore().GetContainer(idOrName)
container, err := r.storageImageServer.GetStore().GetContainer(idOrName)
if err != nil {
if err == storage.ErrContainerUnknown {
return ErrInvalidSandboxID
}
return err
}
err = r.imageServer.GetStore().DeleteContainer(container.ID)
err = r.storageImageServer.GetStore().DeleteContainer(container.ID)
if err != nil {
logrus.Debugf("failed to delete pod sandbox %q: %v", container.ID, err)
return err
@ -345,14 +345,14 @@ func (r *runtimeService) RemovePodSandbox(idOrName string) error {
}
func (r *runtimeService) DeleteContainer(idOrName string) error {
container, err := r.imageServer.GetStore().GetContainer(idOrName)
container, err := r.storageImageServer.GetStore().GetContainer(idOrName)
if err != nil {
if err == storage.ErrContainerUnknown {
return ErrInvalidContainerID
}
return err
}
err = r.imageServer.GetStore().DeleteContainer(container.ID)
err = r.storageImageServer.GetStore().DeleteContainer(container.ID)
if err != nil {
logrus.Debugf("failed to delete container %q: %v", container.ID, err)
return err
@ -366,12 +366,12 @@ func (r *runtimeService) SetContainerMetadata(idOrName string, metadata RuntimeC
logrus.Debugf("failed to encode metadata for %q: %v", idOrName, err)
return err
}
return r.imageServer.GetStore().SetMetadata(idOrName, string(mdata))
return r.storageImageServer.GetStore().SetMetadata(idOrName, string(mdata))
}
func (r *runtimeService) GetContainerMetadata(idOrName string) (RuntimeContainerMetadata, error) {
metadata := RuntimeContainerMetadata{}
mdata, err := r.imageServer.GetStore().GetMetadata(idOrName)
mdata, err := r.storageImageServer.GetStore().GetMetadata(idOrName)
if err != nil {
return metadata, err
}
@ -382,7 +382,7 @@ func (r *runtimeService) GetContainerMetadata(idOrName string) (RuntimeContainer
}
func (r *runtimeService) StartContainer(idOrName string) (string, error) {
container, err := r.imageServer.GetStore().GetContainer(idOrName)
container, err := r.storageImageServer.GetStore().GetContainer(idOrName)
if err != nil {
if err == storage.ErrContainerUnknown {
return "", ErrInvalidContainerID
@ -393,7 +393,7 @@ func (r *runtimeService) StartContainer(idOrName string) (string, error) {
if err = json.Unmarshal([]byte(container.Metadata), &metadata); err != nil {
return "", err
}
mountPoint, err := r.imageServer.GetStore().Mount(container.ID, metadata.MountLabel)
mountPoint, err := r.storageImageServer.GetStore().Mount(container.ID, metadata.MountLabel)
if err != nil {
logrus.Debugf("failed to mount container %q: %v", container.ID, err)
return "", err
@ -403,14 +403,14 @@ func (r *runtimeService) StartContainer(idOrName string) (string, error) {
}
func (r *runtimeService) StopContainer(idOrName string) error {
container, err := r.imageServer.GetStore().GetContainer(idOrName)
container, err := r.storageImageServer.GetStore().GetContainer(idOrName)
if err != nil {
if err == storage.ErrContainerUnknown {
return ErrInvalidContainerID
}
return err
}
err = r.imageServer.GetStore().Unmount(container.ID)
err = r.storageImageServer.GetStore().Unmount(container.ID)
if err != nil {
logrus.Debugf("failed to unmount container %q: %v", container.ID, err)
return err
@ -420,33 +420,33 @@ func (r *runtimeService) StopContainer(idOrName string) error {
}
func (r *runtimeService) GetWorkDir(id string) (string, error) {
container, err := r.imageServer.GetStore().GetContainer(id)
container, err := r.storageImageServer.GetStore().GetContainer(id)
if err != nil {
if err == storage.ErrContainerUnknown {
return "", ErrInvalidContainerID
}
return "", err
}
return r.imageServer.GetStore().GetContainerDirectory(container.ID)
return r.storageImageServer.GetStore().GetContainerDirectory(container.ID)
}
func (r *runtimeService) GetRunDir(id string) (string, error) {
container, err := r.imageServer.GetStore().GetContainer(id)
container, err := r.storageImageServer.GetStore().GetContainer(id)
if err != nil {
if err == storage.ErrContainerUnknown {
return "", ErrInvalidContainerID
}
return "", err
}
return r.imageServer.GetStore().GetContainerRunDirectory(container.ID)
return r.storageImageServer.GetStore().GetContainerRunDirectory(container.ID)
}
// GetRuntimeService returns a RuntimeServer that uses the passed-in image
// service to pull and manage images, and its store to manage containers based
// on those images.
func GetRuntimeService(imageServer ImageServer, pauseImage string) RuntimeServer {
func GetRuntimeService(storageImageServer ImageServer, pauseImage string) RuntimeServer {
return &runtimeService{
imageServer: imageServer,
pauseImage: pauseImage,
storageImageServer: storageImageServer,
pauseImage: pauseImage,
}
}

View file

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

View file

@ -36,11 +36,11 @@ func (s *Server) RemoveContainer(ctx context.Context, req *pb.RemoveContainerReq
s.removeContainer(c)
if err := s.storage.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)
}
if err := s.storage.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)
}

View file

@ -41,7 +41,7 @@ func (s *Server) ContainerStatus(ctx context.Context, req *pb.ContainerStatusReq
}
resp.Status.Mounts = mounts
status, err := s.images.ImageStatus(s.imageContext, image.Image)
status, err := s.storageImageServer.ImageStatus(s.imageContext, image.Image)
if err != nil {
return nil, err
}

View file

@ -17,7 +17,7 @@ func (s *Server) ListImages(ctx context.Context, req *pb.ListImagesRequest) (*pb
filter = filterImage.Image
}
}
results, err := s.images.ListImages(filter)
results, err := s.storageImageServer.ListImages(filter)
if err != nil {
return nil, err
}

View file

@ -47,7 +47,7 @@ func (s *Server) PullImage(ctx context.Context, req *pb.PullImageRequest) (*pb.P
},
}
}
_, err := s.images.PullImage(s.imageContext, image, options)
_, err := s.storageImageServer.PullImage(s.imageContext, image, options)
if err != nil {
return nil, err
}

View file

@ -19,7 +19,7 @@ func (s *Server) RemoveImage(ctx context.Context, req *pb.RemoveImageRequest) (*
if image == "" {
return nil, fmt.Errorf("no image specified")
}
err := s.images.RemoveImage(s.imageContext, image)
err := s.storageImageServer.RemoveImage(s.imageContext, image)
if err != nil {
return nil, err
}

View file

@ -20,7 +20,7 @@ func (s *Server) ImageStatus(ctx context.Context, req *pb.ImageStatusRequest) (*
if image == "" {
return nil, fmt.Errorf("no image specified")
}
status, err := s.images.ImageStatus(s.imageContext, image)
status, err := s.storageImageServer.ImageStatus(s.imageContext, image)
if err != nil {
if err == storage.ErrImageUnknown {
return &pb.ImageStatusResponse{}, nil

View file

@ -52,10 +52,10 @@ func (s *Server) RemovePodSandbox(ctx context.Context, req *pb.RemovePodSandboxR
continue
}
if err := s.storage.StopContainer(c.ID()); err != nil {
if err := s.storageRuntimeServer.StopContainer(c.ID()); err != nil {
return nil, fmt.Errorf("failed to delete container %s in pod sandbox %s: %v", c.Name(), sb.id, err)
}
if err := s.storage.DeleteContainer(c.ID()); err != nil {
if err := s.storageRuntimeServer.DeleteContainer(c.ID()); err != nil {
return nil, fmt.Errorf("failed to delete container %s in pod sandbox %s: %v", c.Name(), sb.id, err)
}
@ -85,10 +85,10 @@ func (s *Server) RemovePodSandbox(ctx context.Context, req *pb.RemovePodSandboxR
sb.infraContainer = nil
// Remove the files related to the sandbox
if err := s.storage.StopContainer(sb.id); err != nil {
if err := s.storageRuntimeServer.StopContainer(sb.id); err != nil {
return nil, fmt.Errorf("failed to delete sandbox container in pod sandbox %s: %v", sb.id, err)
}
if err := s.storage.RemovePodSandbox(sb.id); err != nil {
if err := s.storageRuntimeServer.RemovePodSandbox(sb.id); err != nil {
return nil, fmt.Errorf("failed to remove pod sandbox %s: %v", sb.id, err)
}

View file

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

View file

@ -29,20 +29,20 @@ const (
// Server implements the RuntimeService and ImageService
type Server struct {
config Config
runtime *oci.Runtime
store sstorage.Store
images storage.ImageServer
storage storage.RuntimeServer
stateLock sync.Mutex
updateLock sync.RWMutex
state *serverState
netPlugin ocicni.CNIPlugin
podNameIndex *registrar.Registrar
podIDIndex *truncindex.TruncIndex
ctrNameIndex *registrar.Registrar
ctrIDIndex *truncindex.TruncIndex
imageContext *types.SystemContext
config Config
runtime *oci.Runtime
store sstorage.Store
storageImageServer storage.ImageServer
storageRuntimeServer storage.RuntimeServer
stateLock sync.Mutex
updateLock sync.RWMutex
state *serverState
netPlugin ocicni.CNIPlugin
podNameIndex *registrar.Registrar
podIDIndex *truncindex.TruncIndex
ctrNameIndex *registrar.Registrar
ctrIDIndex *truncindex.TruncIndex
imageContext *types.SystemContext
seccompEnabled bool
seccompProfile seccomp.Seccomp
@ -255,7 +255,7 @@ func (s *Server) restore() {
pods := map[string]*storage.RuntimeContainerMetadata{}
podContainers := map[string]*storage.RuntimeContainerMetadata{}
for _, container := range containers {
metadata, err2 := s.storage.GetContainerMetadata(container.ID)
metadata, err2 := s.storageRuntimeServer.GetContainerMetadata(container.ID)
if err2 != nil {
logrus.Warnf("error parsing metadata for %s: %v, ignoring", container.ID, err2)
continue
@ -316,7 +316,7 @@ func (s *Server) update() error {
continue
}
// not previously known, so figure out what it is
metadata, err2 := s.storage.GetContainerMetadata(container.ID)
metadata, err2 := s.storageRuntimeServer.GetContainerMetadata(container.ID)
if err2 != nil {
logrus.Errorf("error parsing metadata for %s: %v, ignoring", container.ID, err2)
continue
@ -470,12 +470,12 @@ func New(config *Config) (*Server, error) {
return nil, err
}
s := &Server{
runtime: r,
store: store,
images: imageService,
storage: storageRuntimeService,
netPlugin: netPlugin,
config: *config,
runtime: r,
store: store,
storageImageServer: imageService,
storageRuntimeServer: storageRuntimeService,
netPlugin: netPlugin,
config: *config,
state: &serverState{
sandboxes: sandboxes,
containers: containers,