Skip to content

Commit

Permalink
image: generator: implement annotation generation to runtime
Browse files Browse the repository at this point in the history
It's important the we set annotations in the resultant runtime config --
otherwise we could be dropping important configuration information. For
some reason this information is duplicated in two places in the
image-spec so we just pick an arbitrary ordering (that will need to be
clarified in a proposal to opencontainers/image-spec#479).

Signed-off-by: Aleksa Sarai <asarai@suse.com>
  • Loading branch information
cyphar committed Dec 10, 2016
1 parent 98d9a82 commit 3da6b85
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
18 changes: 14 additions & 4 deletions image/generator/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ import (
// configuration appropriate for use, which is templated on the default
// configuration specified by the OCI runtime-tools. It is equivalent to
// MutateRuntimeSpec("runtime-tools/generate".New(), image).Spec().
func ToRuntimeSpec(rootfs string, image v1.Image) (rspec.Spec, error) {
func ToRuntimeSpec(rootfs string, image v1.Image, manifest v1.Manifest) (rspec.Spec, error) {
g := rgen.New()
if err := MutateRuntimeSpec(g, rootfs, image); err != nil {
if err := MutateRuntimeSpec(g, rootfs, image, manifest); err != nil {
return rspec.Spec{}, err
}
return *g.Spec(), nil
Expand All @@ -42,7 +42,7 @@ func ToRuntimeSpec(rootfs string, image v1.Image) (rspec.Spec, error) {
// MutateRuntimeSpec mutates a given runtime specification generator with the
// image configuration provided. It returns the original generator, and does
// not modify any fields directly (to allow for chaining).
func MutateRuntimeSpec(g rgen.Generator, rootfs string, image v1.Image) error {
func MutateRuntimeSpec(g rgen.Generator, rootfs string, image v1.Image, manifest v1.Manifest) error {
if image.OS != "linux" {
return fmt.Errorf("unsupported OS: %s", image.OS)
}
Expand Down Expand Up @@ -111,7 +111,17 @@ func MutateRuntimeSpec(g rgen.Generator, rootfs string, image v1.Image) error {
g.AddTmpfsMount(vol, []string{"rw"})
}

// TODO: Handle annotations (both manifest and config annotations).
// XXX: This order-of-addition is actually not codified in the spec.
// However, this will be sorted once I write a proposal for it.
// opencontainers/image-spec#479

g.ClearAnnotations()
for key, value := range image.Config.Labels {
g.AddAnnotation(key, value)
}
for key, value := range manifest.Annotations {
g.AddAnnotation(key, value)
}

return nil
}
2 changes: 1 addition & 1 deletion image/layer/unpack.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ func UnpackManifest(ctx context.Context, engine cas.Engine, bundle string, manif
}).Infof("unpack manifest: unpacking config")

g := rgen.New()
if err := igen.MutateRuntimeSpec(g, rootfsPath, *config); err != nil {
if err := igen.MutateRuntimeSpec(g, rootfsPath, *config, manifest); err != nil {
return fmt.Errorf("unpack manifest: generating config.json: %s", err)
}

Expand Down

0 comments on commit 3da6b85

Please sign in to comment.