Skip to content

Commit

Permalink
generate: Adjust to Spec.Linux being a pointer
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
wking committed Jun 18, 2016
1 parent da4db68 commit 965e585
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,12 @@ func modify(spec *rspec.Spec, context *cli.Context) error {
spec.Process.Args = make([]string, 0)
}
spec.Process.SelinuxLabel = context.String("selinux-label")
spec.Linux.CgroupsPath = sPtr(context.String("cgroups-path"))
if spec.Linux == nil {
spec.Linux = &rspec.Linux{}
}
if context.IsSet("cgroups-path") {
spec.Linux.CgroupsPath = sPtr(context.String("cgroups-path"))
}
spec.Linux.MountLabel = context.String("mount-label")
spec.Platform.OS = context.String("os")
spec.Platform.Arch = context.String("arch")
Expand Down Expand Up @@ -228,6 +233,14 @@ func modify(spec *rspec.Spec, context *cli.Context) error {
return err
}

buf, err := json.Marshal(spec.Linux)
if err != nil {
return err
}
if string(buf) == "{}" {
spec.Linux = nil
}

return nil
}

Expand Down Expand Up @@ -807,7 +820,7 @@ func getDefaultTemplate() *rspec.Spec {
Options: []string{"nosuid", "noexec", "nodev", "ro"},
},
},
Linux: rspec.Linux{
Linux: &rspec.Linux{
Resources: &rspec.Resources{
Devices: []rspec.DeviceCgroup{
{
Expand Down

0 comments on commit 965e585

Please sign in to comment.