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