Avoid duplicate image configuration parsing logic
Don't bother trying to find and parse the image's configuration blob after we've already done it; just reuse the value. This frees us from making the assumption that the last blob which was committed to local storage was the image's configuration blob. Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
This commit is contained in:
parent
8957156c41
commit
7e9ac9700b
1 changed files with 4 additions and 66 deletions
|
@ -1,13 +1,12 @@
|
||||||
package image
|
package image
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/containers/image/docker/reference"
|
"github.com/containers/image/docker/reference"
|
||||||
"github.com/containers/storage"
|
"github.com/containers/storage"
|
||||||
|
"github.com/kubernetes-incubator/cri-o/cmd/kpod/docker"
|
||||||
"github.com/kubernetes-incubator/cri-o/libkpod/driver"
|
"github.com/kubernetes-incubator/cri-o/libkpod/driver"
|
||||||
digest "github.com/opencontainers/go-digest"
|
|
||||||
ociv1 "github.com/opencontainers/image-spec/specs-go/v1"
|
ociv1 "github.com/opencontainers/image-spec/specs-go/v1"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
)
|
)
|
||||||
|
@ -22,7 +21,7 @@ type ImageData struct {
|
||||||
Comment string
|
Comment string
|
||||||
Created *time.Time
|
Created *time.Time
|
||||||
Container string
|
Container string
|
||||||
ContainerConfig containerConfig
|
ContainerConfig docker.Config
|
||||||
Author string
|
Author string
|
||||||
Config ociv1.ImageConfig
|
Config ociv1.ImageConfig
|
||||||
Architecture string
|
Architecture string
|
||||||
|
@ -33,27 +32,6 @@ type ImageData struct {
|
||||||
RootFS ociv1.RootFS
|
RootFS ociv1.RootFS
|
||||||
}
|
}
|
||||||
|
|
||||||
type containerConfig struct {
|
|
||||||
Hostname string
|
|
||||||
Domainname string
|
|
||||||
User string
|
|
||||||
AttachStdin bool
|
|
||||||
AttachStdout bool
|
|
||||||
AttachStderr bool
|
|
||||||
Tty bool
|
|
||||||
OpenStdin bool
|
|
||||||
StdinOnce bool
|
|
||||||
Env []string
|
|
||||||
Cmd []string
|
|
||||||
ArgsEscaped bool
|
|
||||||
Image digest.Digest
|
|
||||||
Volumes map[string]interface{}
|
|
||||||
WorkingDir string
|
|
||||||
Entrypoint []string
|
|
||||||
Labels interface{}
|
|
||||||
OnBuild []string
|
|
||||||
}
|
|
||||||
|
|
||||||
type rootFS struct {
|
type rootFS struct {
|
||||||
Type string
|
Type string
|
||||||
Layers []string
|
Layers []string
|
||||||
|
@ -96,34 +74,6 @@ func GetImageData(store storage.Store, name string) (*ImageData, error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrapf(err, "error reading image %q", name)
|
return nil, errors.Wrapf(err, "error reading image %q", name)
|
||||||
}
|
}
|
||||||
blobDigests, err := getDigests(*img)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
var bigData interface{}
|
|
||||||
ctrConfig := containerConfig{}
|
|
||||||
container := ""
|
|
||||||
if len(blobDigests) > 0 {
|
|
||||||
bd, err := store.ImageBigData(img.ID, string(blobDigests[len(blobDigests)-1]))
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
err = json.Unmarshal(bd, &bigData)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
container = (bigData.(map[string]interface{})["container"]).(string)
|
|
||||||
cc, err := json.MarshalIndent((bigData.(map[string]interface{})["container_config"]).(map[string]interface{}), "", " ")
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
err = json.Unmarshal(cc, &ctrConfig)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
tags, digests, err := ParseImageNames(img.Names)
|
tags, digests, err := ParseImageNames(img.Names)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -166,8 +116,8 @@ func GetImageData(store storage.Store, name string) (*ImageData, error) {
|
||||||
Parent: string(cid.Docker.Parent),
|
Parent: string(cid.Docker.Parent),
|
||||||
Comment: cid.OCIv1.History[0].Comment,
|
Comment: cid.OCIv1.History[0].Comment,
|
||||||
Created: cid.OCIv1.Created,
|
Created: cid.OCIv1.Created,
|
||||||
Container: container,
|
Container: cid.Docker.Container,
|
||||||
ContainerConfig: ctrConfig,
|
ContainerConfig: cid.Docker.ContainerConfig,
|
||||||
Author: cid.OCIv1.Author,
|
Author: cid.OCIv1.Author,
|
||||||
Config: cid.OCIv1.Config,
|
Config: cid.OCIv1.Config,
|
||||||
Architecture: cid.OCIv1.Architecture,
|
Architecture: cid.OCIv1.Architecture,
|
||||||
|
@ -181,15 +131,3 @@ func GetImageData(store storage.Store, name string) (*ImageData, error) {
|
||||||
RootFS: cid.OCIv1.RootFS,
|
RootFS: cid.OCIv1.RootFS,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func getDigests(img storage.Image) ([]digest.Digest, error) {
|
|
||||||
metadata, err := ParseMetadata(img)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
digests := []digest.Digest{}
|
|
||||||
for _, blob := range metadata.Blobs {
|
|
||||||
digests = append(digests, blob.Digest)
|
|
||||||
}
|
|
||||||
return digests, nil
|
|
||||||
}
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue