adds oci image spec to image info placed into imagestore
Signed-off-by: Mike Brown <brownwm@us.ibm.com>
This commit is contained in:
parent
03ac989644
commit
31223fd5b1
@ -139,12 +139,12 @@ func (c *criContainerdService) CreateContainer(ctx context.Context, r *runtime.C
|
|||||||
|
|
||||||
// Create container volumes mounts.
|
// Create container volumes mounts.
|
||||||
// TODO(random-liu): Add cri-containerd integration test for image volume.
|
// TODO(random-liu): Add cri-containerd integration test for image volume.
|
||||||
volumeMounts := c.generateVolumeMounts(containerRootDir, config.GetMounts(), image.Config)
|
volumeMounts := c.generateVolumeMounts(containerRootDir, config.GetMounts(), &image.ImageSpec.Config)
|
||||||
|
|
||||||
// Generate container runtime spec.
|
// Generate container runtime spec.
|
||||||
mounts := c.generateContainerMounts(getSandboxRootDir(c.config.RootDir, sandboxID), config)
|
mounts := c.generateContainerMounts(getSandboxRootDir(c.config.RootDir, sandboxID), config)
|
||||||
|
|
||||||
spec, err := c.generateContainerSpec(id, sandboxPid, config, sandboxConfig, image.Config, append(mounts, volumeMounts...))
|
spec, err := c.generateContainerSpec(id, sandboxPid, config, sandboxConfig, &image.ImageSpec.Config, append(mounts, volumeMounts...))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to generate container %q spec: %v", id, err)
|
return nil, fmt.Errorf("failed to generate container %q spec: %v", id, err)
|
||||||
}
|
}
|
||||||
|
@ -80,11 +80,11 @@ func (c *criContainerdService) stopContainer(ctx context.Context, container cont
|
|||||||
// an error here.
|
// an error here.
|
||||||
return fmt.Errorf("failed to get image metadata %q: %v", container.ImageRef, err)
|
return fmt.Errorf("failed to get image metadata %q: %v", container.ImageRef, err)
|
||||||
}
|
}
|
||||||
if image.Config.StopSignal != "" {
|
if image.ImageSpec.Config.StopSignal != "" {
|
||||||
stopSignal, err = signal.ParseSignal(image.Config.StopSignal)
|
stopSignal, err = signal.ParseSignal(image.ImageSpec.Config.StopSignal)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to parse stop signal %q: %v",
|
return fmt.Errorf("failed to parse stop signal %q: %v",
|
||||||
image.Config.StopSignal, err)
|
image.ImageSpec.Config.StopSignal, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
glog.V(2).Infof("Stop container %q with signal %v", id, stopSignal)
|
glog.V(2).Infof("Stop container %q with signal %v", id, stopSignal)
|
||||||
|
@ -308,10 +308,10 @@ func loadCgroup(cgroupPath string) (cgroups.Cgroup, error) {
|
|||||||
|
|
||||||
// imageInfo is the information about the image got from containerd.
|
// imageInfo is the information about the image got from containerd.
|
||||||
type imageInfo struct {
|
type imageInfo struct {
|
||||||
id string
|
id string
|
||||||
chainID imagedigest.Digest
|
chainID imagedigest.Digest
|
||||||
size int64
|
size int64
|
||||||
config imagespec.ImageConfig
|
imagespec imagespec.Image
|
||||||
}
|
}
|
||||||
|
|
||||||
// getImageInfo gets image info from containerd.
|
// getImageInfo gets image info from containerd.
|
||||||
@ -344,10 +344,10 @@ func getImageInfo(ctx context.Context, image containerd.Image, provider content.
|
|||||||
}
|
}
|
||||||
|
|
||||||
return &imageInfo{
|
return &imageInfo{
|
||||||
id: id,
|
id: id,
|
||||||
chainID: chainID,
|
chainID: chainID,
|
||||||
size: size,
|
size: size,
|
||||||
config: ociimage.Config,
|
imagespec: ociimage,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -47,7 +47,7 @@ func toCRIImage(image imagestore.Image) *runtime.Image {
|
|||||||
RepoDigests: image.RepoDigests,
|
RepoDigests: image.RepoDigests,
|
||||||
Size_: uint64(image.Size),
|
Size_: uint64(image.Size),
|
||||||
}
|
}
|
||||||
uid, username := getUserFromImage(image.Config.User)
|
uid, username := getUserFromImage(image.ImageSpec.Config.User)
|
||||||
if uid != nil {
|
if uid != nil {
|
||||||
runtimeImage.Uid = &runtime.Int64Value{Value: *uid}
|
runtimeImage.Uid = &runtime.Int64Value{Value: *uid}
|
||||||
}
|
}
|
||||||
|
@ -37,8 +37,10 @@ func TestListImages(t *testing.T) {
|
|||||||
RepoTags: []string{"tag-a-1", "tag-b-1"},
|
RepoTags: []string{"tag-a-1", "tag-b-1"},
|
||||||
RepoDigests: []string{"digest-a-1", "digest-b-1"},
|
RepoDigests: []string{"digest-a-1", "digest-b-1"},
|
||||||
Size: 1000,
|
Size: 1000,
|
||||||
Config: &imagespec.ImageConfig{
|
ImageSpec: imagespec.Image{
|
||||||
User: "root",
|
Config: imagespec.ImageConfig{
|
||||||
|
User: "root",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -47,8 +49,10 @@ func TestListImages(t *testing.T) {
|
|||||||
RepoTags: []string{"tag-a-2", "tag-b-2"},
|
RepoTags: []string{"tag-a-2", "tag-b-2"},
|
||||||
RepoDigests: []string{"digest-a-2", "digest-b-2"},
|
RepoDigests: []string{"digest-a-2", "digest-b-2"},
|
||||||
Size: 2000,
|
Size: 2000,
|
||||||
Config: &imagespec.ImageConfig{
|
ImageSpec: imagespec.Image{
|
||||||
User: "1234:1234",
|
Config: imagespec.ImageConfig{
|
||||||
|
User: "1234:1234",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -57,8 +61,10 @@ func TestListImages(t *testing.T) {
|
|||||||
RepoTags: []string{"tag-a-3", "tag-b-3"},
|
RepoTags: []string{"tag-a-3", "tag-b-3"},
|
||||||
RepoDigests: []string{"digest-a-3", "digest-b-3"},
|
RepoDigests: []string{"digest-a-3", "digest-b-3"},
|
||||||
Size: 3000,
|
Size: 3000,
|
||||||
Config: &imagespec.ImageConfig{
|
ImageSpec: imagespec.Image{
|
||||||
User: "nobody",
|
Config: imagespec.ImageConfig{
|
||||||
|
User: "nobody",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -61,13 +61,14 @@ func (c *criContainerdService) LoadImage(ctx context.Context, r *api.LoadImageRe
|
|||||||
if err := c.createImageReference(ctx, id, image.Target()); err != nil {
|
if err := c.createImageReference(ctx, id, image.Target()); err != nil {
|
||||||
return nil, fmt.Errorf("failed to create image reference %q: %v", id, err)
|
return nil, fmt.Errorf("failed to create image reference %q: %v", id, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
img := imagestore.Image{
|
img := imagestore.Image{
|
||||||
ID: id,
|
ID: id,
|
||||||
RepoTags: []string{repoTag},
|
RepoTags: []string{repoTag},
|
||||||
ChainID: info.chainID.String(),
|
ChainID: info.chainID.String(),
|
||||||
Size: info.size,
|
Size: info.size,
|
||||||
Config: &info.config,
|
ImageSpec: info.imagespec,
|
||||||
Image: image,
|
Image: image,
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := c.imageStore.Add(img); err != nil {
|
if err := c.imageStore.Add(img); err != nil {
|
||||||
|
@ -136,11 +136,11 @@ func (c *criContainerdService) PullImage(ctx context.Context, r *runtime.PullIma
|
|||||||
glog.V(4).Infof("Pulled image %q with image id %q, repo tag %q, repo digest %q", imageRef, imageID,
|
glog.V(4).Infof("Pulled image %q with image id %q, repo tag %q, repo digest %q", imageRef, imageID,
|
||||||
repoTag, repoDigest)
|
repoTag, repoDigest)
|
||||||
img := imagestore.Image{
|
img := imagestore.Image{
|
||||||
ID: imageID,
|
ID: imageID,
|
||||||
ChainID: info.chainID.String(),
|
ChainID: info.chainID.String(),
|
||||||
Size: info.size,
|
Size: info.size,
|
||||||
Config: &info.config,
|
ImageSpec: info.imagespec,
|
||||||
Image: image,
|
Image: image,
|
||||||
}
|
}
|
||||||
if repoDigest != "" {
|
if repoDigest != "" {
|
||||||
img.RepoDigests = []string{repoDigest}
|
img.RepoDigests = []string{repoDigest}
|
||||||
|
@ -24,7 +24,6 @@ import (
|
|||||||
"golang.org/x/net/context"
|
"golang.org/x/net/context"
|
||||||
"k8s.io/kubernetes/pkg/kubelet/apis/cri/v1alpha1/runtime"
|
"k8s.io/kubernetes/pkg/kubelet/apis/cri/v1alpha1/runtime"
|
||||||
|
|
||||||
content "github.com/containerd/containerd/content"
|
|
||||||
imagestore "github.com/kubernetes-incubator/cri-containerd/pkg/store/image"
|
imagestore "github.com/kubernetes-incubator/cri-containerd/pkg/store/image"
|
||||||
imagespec "github.com/opencontainers/image-spec/specs-go/v1"
|
imagespec "github.com/opencontainers/image-spec/specs-go/v1"
|
||||||
)
|
)
|
||||||
@ -64,7 +63,7 @@ func toCRIRuntimeImage(image *imagestore.Image) *runtime.Image {
|
|||||||
RepoDigests: image.RepoDigests,
|
RepoDigests: image.RepoDigests,
|
||||||
Size_: uint64(image.Size),
|
Size_: uint64(image.Size),
|
||||||
}
|
}
|
||||||
uid, username := getUserFromImage(image.Config.User)
|
uid, username := getUserFromImage(image.ImageSpec.Config.User)
|
||||||
if uid != nil {
|
if uid != nil {
|
||||||
runtimeImage.Uid = &runtime.Int64Value{Value: *uid}
|
runtimeImage.Uid = &runtime.Int64Value{Value: *uid}
|
||||||
}
|
}
|
||||||
@ -75,10 +74,8 @@ func toCRIRuntimeImage(image *imagestore.Image) *runtime.Image {
|
|||||||
|
|
||||||
// TODO (mikebrow): discuss moving this struct and / or constants for info map for some or all of these fields to CRI
|
// TODO (mikebrow): discuss moving this struct and / or constants for info map for some or all of these fields to CRI
|
||||||
type verboseImageInfo struct {
|
type verboseImageInfo struct {
|
||||||
Config *imagespec.ImageConfig `json:"config"`
|
ChainID string `json:"chainID"`
|
||||||
ConfigDescriptor imagespec.Descriptor `json:"configDescriptor"`
|
ImageSpec imagespec.Image `json:"imageSpec"`
|
||||||
ManifestDescriptor imagespec.Descriptor `json:"manifestDescriptor"`
|
|
||||||
LayerInfo []content.Info `json:"layerInfo"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// toCRIImageInfo converts internal image object information to CRI image status response info map.
|
// toCRIImageInfo converts internal image object information to CRI image status response info map.
|
||||||
@ -88,32 +85,10 @@ func (c *criContainerdService) toCRIImageInfo(ctx context.Context, image *images
|
|||||||
}
|
}
|
||||||
|
|
||||||
info := make(map[string]string)
|
info := make(map[string]string)
|
||||||
i := image.Image
|
|
||||||
descriptor, err := i.Config(ctx)
|
|
||||||
if err != nil {
|
|
||||||
glog.Errorf("Failed to get image config %q: %v", image.ID, err)
|
|
||||||
} // fallthrough
|
|
||||||
|
|
||||||
targetDescriptor := i.Target()
|
|
||||||
var dia []content.Info
|
|
||||||
digests, err := i.RootFS(ctx)
|
|
||||||
if err != nil {
|
|
||||||
glog.Errorf("Failed to get target digests %q: %v", i.Name(), err)
|
|
||||||
} else {
|
|
||||||
dia = make([]content.Info, len(digests))
|
|
||||||
for i, d := range digests {
|
|
||||||
di, err := c.client.ContentStore().Info(ctx, d)
|
|
||||||
if err == nil {
|
|
||||||
dia[i] = di
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
imi := &verboseImageInfo{
|
imi := &verboseImageInfo{
|
||||||
Config: image.Config,
|
ChainID: image.ChainID,
|
||||||
ConfigDescriptor: descriptor,
|
ImageSpec: image.ImageSpec,
|
||||||
ManifestDescriptor: targetDescriptor,
|
|
||||||
LayerInfo: dia,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
m, err := json.Marshal(imi)
|
m, err := json.Marshal(imi)
|
||||||
|
@ -36,8 +36,10 @@ func TestImageStatus(t *testing.T) {
|
|||||||
RepoTags: []string{"a", "b"},
|
RepoTags: []string{"a", "b"},
|
||||||
RepoDigests: []string{"c", "d"},
|
RepoDigests: []string{"c", "d"},
|
||||||
Size: 1234,
|
Size: 1234,
|
||||||
Config: &imagespec.ImageConfig{
|
ImageSpec: imagespec.Image{
|
||||||
User: "user:group",
|
Config: imagespec.ImageConfig{
|
||||||
|
User: "user:group",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
expected := &runtime.Image{
|
expected := &runtime.Image{
|
||||||
|
@ -366,11 +366,11 @@ func loadImages(ctx context.Context, cImages []containerd.Image, provider conten
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
image := imagestore.Image{
|
image := imagestore.Image{
|
||||||
ID: id,
|
ID: id,
|
||||||
ChainID: info.chainID.String(),
|
ChainID: info.chainID.String(),
|
||||||
Size: info.size,
|
Size: info.size,
|
||||||
Config: &info.config,
|
ImageSpec: info.imagespec,
|
||||||
Image: i,
|
Image: i,
|
||||||
}
|
}
|
||||||
// Recover repo digests and repo tags.
|
// Recover repo digests and repo tags.
|
||||||
for _, i := range imgs {
|
for _, i := range imgs {
|
||||||
|
@ -123,7 +123,7 @@ func (c *criContainerdService) RunPodSandbox(ctx context.Context, r *runtime.Run
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Create sandbox container.
|
// Create sandbox container.
|
||||||
spec, err := c.generateSandboxContainerSpec(id, config, image.Config, sandbox.NetNSPath)
|
spec, err := c.generateSandboxContainerSpec(id, config, &image.ImageSpec.Config, sandbox.NetNSPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to generate sandbox container spec: %v", err)
|
return nil, fmt.Errorf("failed to generate sandbox container spec: %v", err)
|
||||||
}
|
}
|
||||||
|
@ -40,8 +40,9 @@ type Image struct {
|
|||||||
ChainID string
|
ChainID string
|
||||||
// Size is the compressed size of the image.
|
// Size is the compressed size of the image.
|
||||||
Size int64
|
Size int64
|
||||||
// Config is the oci image config of the image.
|
// ImageSpec is the oci image structure which describes basic information about the image.
|
||||||
Config *imagespec.ImageConfig
|
ImageSpec imagespec.Image
|
||||||
|
|
||||||
// Containerd image reference
|
// Containerd image reference
|
||||||
Image containerd.Image
|
Image containerd.Image
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,6 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
imagespec "github.com/opencontainers/image-spec/specs-go/v1"
|
|
||||||
assertlib "github.com/stretchr/testify/assert"
|
assertlib "github.com/stretchr/testify/assert"
|
||||||
|
|
||||||
"github.com/kubernetes-incubator/cri-containerd/pkg/store"
|
"github.com/kubernetes-incubator/cri-containerd/pkg/store"
|
||||||
@ -34,7 +33,6 @@ func TestImageStore(t *testing.T) {
|
|||||||
RepoTags: []string{"tag-1"},
|
RepoTags: []string{"tag-1"},
|
||||||
RepoDigests: []string{"digest-1"},
|
RepoDigests: []string{"digest-1"},
|
||||||
Size: 10,
|
Size: 10,
|
||||||
Config: &imagespec.ImageConfig{},
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
ID: "sha256:2123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef",
|
ID: "sha256:2123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef",
|
||||||
@ -42,7 +40,6 @@ func TestImageStore(t *testing.T) {
|
|||||||
RepoTags: []string{"tag-2abcd"},
|
RepoTags: []string{"tag-2abcd"},
|
||||||
RepoDigests: []string{"digest-2abcd"},
|
RepoDigests: []string{"digest-2abcd"},
|
||||||
Size: 20,
|
Size: 20,
|
||||||
Config: &imagespec.ImageConfig{},
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
ID: "sha256:3123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef",
|
ID: "sha256:3123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef",
|
||||||
@ -50,7 +47,6 @@ func TestImageStore(t *testing.T) {
|
|||||||
RepoDigests: []string{"digest-4a333"},
|
RepoDigests: []string{"digest-4a333"},
|
||||||
ChainID: "test-chain-id-4a333",
|
ChainID: "test-chain-id-4a333",
|
||||||
Size: 30,
|
Size: 30,
|
||||||
Config: &imagespec.ImageConfig{},
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
ID: "sha256:4123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef",
|
ID: "sha256:4123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef",
|
||||||
@ -58,7 +54,6 @@ func TestImageStore(t *testing.T) {
|
|||||||
RepoDigests: []string{"digest-4abcd"},
|
RepoDigests: []string{"digest-4abcd"},
|
||||||
ChainID: "test-chain-id-4abcd",
|
ChainID: "test-chain-id-4abcd",
|
||||||
Size: 40,
|
Size: 40,
|
||||||
Config: &imagespec.ImageConfig{},
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
assert := assertlib.New(t)
|
assert := assertlib.New(t)
|
||||||
|
Loading…
Reference in New Issue
Block a user