@@ -37,12 +37,13 @@ import (
3737// in an image configuration that do not have a native representation in the
3838// runtime-spec).
3939const (
40- osAnnotation = "org.opencontainers.image.os"
41- archAnnotation = "org.opencontainers.image.architecture"
42- authorAnnotation = "org.opencontainers.image.author"
43- createdAnnotation = "org.opencontainers.image.created"
44- stopSignalAnnotation = "org.opencontainers.image.stopSignal"
45- exposedPortsAnnotation = "org.opencontainers.image.exposedPorts"
40+ platformOsAnnotation = "org.opencontainers.image.os"
41+ platformArchAnnotation = "org.opencontainers.image.architecture"
42+ platformVariantAnnotation = "org.opencontainers.image.variant"
43+ authorAnnotation = "org.opencontainers.image.author"
44+ createdAnnotation = "org.opencontainers.image.created"
45+ stopSignalAnnotation = "org.opencontainers.image.stopSignal"
46+ exposedPortsAnnotation = "org.opencontainers.image.exposedPorts"
4647)
4748
4849// ToRuntimeSpec converts the given OCI image configuration to a runtime
@@ -107,14 +108,16 @@ func allocateNilStruct(spec *rspec.Spec) {
107108}
108109
109110// MutateRuntimeSpec mutates a given runtime configuration with the image
110- // configuration provided.
111+ // configuration provided in accordance with the image specification's
112+ // conversion mechanism (for more information, see
113+ // <https://github.com/opencontainers/image-spec/blob/main/conversion.md>).
111114func MutateRuntimeSpec (spec * rspec.Spec , rootfs string , image ispec.Image ) error {
112115 ig , err := igen .NewFromImage (image )
113116 if err != nil {
114117 return fmt .Errorf ("creating image generator: %w" , err )
115118 }
116119
117- if ig .OS () != "linux" {
120+ if ig .PlatformOS () != "linux" {
118121 return fmt .Errorf ("unsupported OS: %s" , image .OS )
119122 }
120123
@@ -164,13 +167,23 @@ func MutateRuntimeSpec(spec *rspec.Spec, rootfs string, image ispec.Image) error
164167 spec .Process .Args = args
165168 }
166169
167- // Set annotations fields
170+ // Set the "annotation fields".
171+ setAnnotation := func (name , value string ) {
172+ if value != "" {
173+ spec .Annotations [name ] = value
174+ } else {
175+ delete (spec .Annotations , name )
176+ }
177+ }
178+ setAnnotation (platformOsAnnotation , ig .PlatformOS ())
179+ setAnnotation (platformArchAnnotation , ig .PlatformArchitecture ())
180+ setAnnotation (platformVariantAnnotation , ig .PlatformVariant ())
181+ setAnnotation (authorAnnotation , ig .Author ())
182+ setAnnotation (createdAnnotation , ig .Created ().Format (igen .ISO8601 ))
183+ setAnnotation (stopSignalAnnotation , image .Config .StopSignal )
184+ setAnnotation (exposedPortsAnnotation , strings .Join (ig .ConfigExposedPorts (), "," ))
185+ // Config.Labels need to be applied after the auto-applied labels.
168186 maps .Copy (spec .Annotations , ig .ConfigLabels ())
169- spec .Annotations [osAnnotation ] = ig .OS ()
170- spec .Annotations [archAnnotation ] = ig .Architecture ()
171- spec .Annotations [authorAnnotation ] = ig .Author ()
172- spec .Annotations [createdAnnotation ] = ig .Created ().Format (igen .ISO8601 )
173- spec .Annotations [stopSignalAnnotation ] = image .Config .StopSignal
174187
175188 // Set parsed fields
176189 // Get the *actual* uid and gid of the user. If the image doesn't contain
@@ -204,10 +217,6 @@ func MutateRuntimeSpec(spec *rspec.Spec, rootfs string, image ispec.Image) error
204217 appendEnv (& spec .Process .Env , "HOME" , execUser .Home )
205218 }
206219
207- // Set optional fields
208- ports := ig .ConfigExposedPorts ()
209- spec .Annotations [exposedPortsAnnotation ] = strings .Join (ports , "," )
210-
211220 for _ , vol := range ig .ConfigVolumes () {
212221 // XXX: This is _fine_ but might cause some issues in the future.
213222 spec .Mounts = append (spec .Mounts , rspec.Mount {
0 commit comments