Skip to content

Commit 965e585

Browse files
committed
generate: Adjust to Spec.Linux being a pointer
Catch up with opencontainers/runtime-spec@6323157 (specs-go/config: Make Linux and Solaris omitempty (again), 2016-06-17, #502). The "does the marshaled JSON look like '{}'?" check is a pretty cheap trick, but it was the easiest way I could think of for "is there anything useful in here?". An alternative approach that conditionally added an &rspec.Linux{} only if needed seemed too tedious. Signed-off-by: W. Trevor King <wking@tremily.us>
1 parent da4db68 commit 965e585

1 file changed

Lines changed: 15 additions & 2 deletions

File tree

generate.go

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,12 @@ func modify(spec *rspec.Spec, context *cli.Context) error {
142142
spec.Process.Args = make([]string, 0)
143143
}
144144
spec.Process.SelinuxLabel = context.String("selinux-label")
145-
spec.Linux.CgroupsPath = sPtr(context.String("cgroups-path"))
145+
if spec.Linux == nil {
146+
spec.Linux = &rspec.Linux{}
147+
}
148+
if context.IsSet("cgroups-path") {
149+
spec.Linux.CgroupsPath = sPtr(context.String("cgroups-path"))
150+
}
146151
spec.Linux.MountLabel = context.String("mount-label")
147152
spec.Platform.OS = context.String("os")
148153
spec.Platform.Arch = context.String("arch")
@@ -228,6 +233,14 @@ func modify(spec *rspec.Spec, context *cli.Context) error {
228233
return err
229234
}
230235

236+
buf, err := json.Marshal(spec.Linux)
237+
if err != nil {
238+
return err
239+
}
240+
if string(buf) == "{}" {
241+
spec.Linux = nil
242+
}
243+
231244
return nil
232245
}
233246

@@ -807,7 +820,7 @@ func getDefaultTemplate() *rspec.Spec {
807820
Options: []string{"nosuid", "noexec", "nodev", "ro"},
808821
},
809822
},
810-
Linux: rspec.Linux{
823+
Linux: &rspec.Linux{
811824
Resources: &rspec.Resources{
812825
Devices: []rspec.DeviceCgroup{
813826
{

0 commit comments

Comments
 (0)