mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-12 13:31:52 +00:00
kubelet/rkt: Add getImageManifest() to retrive the image manifest for container.
This commit is contained in:
parent
5e7a7b9206
commit
2a87d56171
@ -38,7 +38,7 @@ type image struct {
|
|||||||
// sha512-91e98d7f1679a097c878203c9659f2a26ae394656b3147963324c61fa3832f15 coreos.com/etcd:v2.0.9
|
// sha512-91e98d7f1679a097c878203c9659f2a26ae394656b3147963324c61fa3832f15 coreos.com/etcd:v2.0.9
|
||||||
//
|
//
|
||||||
func (im *image) parseString(input string) error {
|
func (im *image) parseString(input string) error {
|
||||||
idName := strings.Split(input, "\t")
|
idName := strings.Split(strings.TrimSpace(input), "\t")
|
||||||
if len(idName) != 2 {
|
if len(idName) != 2 {
|
||||||
return fmt.Errorf("invalid image information from 'rkt images': %q", input)
|
return fmt.Errorf("invalid image information from 'rkt images': %q", input)
|
||||||
}
|
}
|
||||||
|
@ -349,12 +349,37 @@ func setApp(app *appctypes.App, c *api.Container) error {
|
|||||||
return setIsolators(app, c)
|
return setIsolators(app, c)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// getImageManifest invokes 'rkt image cat-manifest' to retrive the image manifest
|
||||||
|
// for the image.
|
||||||
|
func (r *runtime) getImageManifest(image string) (*appcschema.ImageManifest, error) {
|
||||||
|
var manifest appcschema.ImageManifest
|
||||||
|
|
||||||
|
// TODO(yifan): Assume docker images for now.
|
||||||
|
output, err := r.runCommand("image", "cat-manifest", "--quiet", dockerPrefix+image)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if len(output) != 1 {
|
||||||
|
return nil, fmt.Errorf("no output")
|
||||||
|
}
|
||||||
|
return &manifest, json.Unmarshal([]byte(output[0]), &manifest)
|
||||||
|
}
|
||||||
|
|
||||||
// makePodManifest transforms a kubelet pod spec to the rkt pod manifest.
|
// makePodManifest transforms a kubelet pod spec to the rkt pod manifest.
|
||||||
// TODO(yifan): Use the RunContainerOptions generated by GenerateRunContainerOptions().
|
// TODO(yifan): Use the RunContainerOptions generated by GenerateRunContainerOptions().
|
||||||
func (r *runtime) makePodManifest(pod *api.Pod) (*appcschema.PodManifest, error) {
|
func (r *runtime) makePodManifest(pod *api.Pod) (*appcschema.PodManifest, error) {
|
||||||
manifest := appcschema.BlankPodManifest()
|
manifest := appcschema.BlankPodManifest()
|
||||||
|
|
||||||
for _, c := range pod.Spec.Containers {
|
for _, c := range pod.Spec.Containers {
|
||||||
|
imgManifest, err := r.getImageManifest(c.Image)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if imgManifest.App == nil {
|
||||||
|
return nil, fmt.Errorf("no app section in image manifest for image: %q", c.Image)
|
||||||
|
}
|
||||||
|
|
||||||
img, err := r.getImageByName(c.Image)
|
img, err := r.getImageByName(c.Image)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -364,22 +389,15 @@ func (r *runtime) makePodManifest(pod *api.Pod) (*appcschema.PodManifest, error)
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO(yifan): Override the image manifest's app and store it in the pod manifest.
|
if err := setApp(imgManifest.App, &c); err != nil {
|
||||||
// We need to get the image manifest. https://github.com/coreos/rkt/issues/850
|
|
||||||
app := &appctypes.App{}
|
|
||||||
if err := setApp(app, &c); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
imageName, err := appctypes.NewACName(img.name)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
manifest.Apps = append(manifest.Apps, appcschema.RuntimeApp{
|
manifest.Apps = append(manifest.Apps, appcschema.RuntimeApp{
|
||||||
// TODO(yifan): We should allow app name to be different with
|
// TODO(yifan): We should allow app name to be different with
|
||||||
// image name. See https://github.com/coreos/rkt/pull/640.
|
// image name. See https://github.com/coreos/rkt/pull/640.
|
||||||
Name: *imageName,
|
Name: imgManifest.Name,
|
||||||
Image: appcschema.RuntimeImage{ID: *hash},
|
Image: appcschema.RuntimeImage{ID: *hash},
|
||||||
App: app,
|
App: imgManifest.App,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1118,18 +1136,33 @@ func (r *runtime) listImages() ([]image, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// getImageByName tries to find the image info with the given image name.
|
// getImageByName tries to find the image info with the given image name.
|
||||||
func (r *runtime) getImageByName(name string) (image, error) {
|
func (r *runtime) getImageByName(imageName string) (image, error) {
|
||||||
// TODO(yifan): Use rkt image cat-file when that is ready:
|
// TODO(yifan): Print hash in rkt image?
|
||||||
// https://github.com/coreos/rkt/pull/649
|
|
||||||
images, err := r.listImages()
|
images, err := r.listImages()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return image{}, err
|
return image{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var name, version string
|
||||||
|
nameVersion := strings.Split(imageName, ":")
|
||||||
|
|
||||||
|
// TODO(yifan): Currently the name cannot include "_", it is replaced
|
||||||
|
// by "-". See the issue in appc/spec: https://github.com/appc/spec/issues/406.
|
||||||
|
name, err = appctypes.SanitizeACName(nameVersion[0])
|
||||||
|
if err != nil {
|
||||||
|
return image{}, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(nameVersion) == 2 {
|
||||||
|
version = nameVersion[1]
|
||||||
|
}
|
||||||
|
|
||||||
for _, img := range images {
|
for _, img := range images {
|
||||||
if img.name == name {
|
if img.name == name {
|
||||||
return img, nil
|
if version == "" || img.version == version {
|
||||||
|
return img, nil
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return image{}, fmt.Errorf("cannot find the image %q", name)
|
return image{}, fmt.Errorf("cannot find the image %q", imageName)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user