Skip to content

Commit

Permalink
generate: Move Generator.spec to Generator.Config
Browse files Browse the repository at this point in the history
This makes the attribute public, since quite a few config
manipulations are easier using Go's types than they are via
getter/setter/mutator methods.  This also means that we can drop
methods that are more awkward than direct access (although we'll want
to keep methods that are more convenient than direct access).  I
haven't done any method-dropping in this commit though, aside from the
getter/setter for the config itself.  I'd called for this back when we
started adding these methods [1], and Mrunal was sounding more
positive about the public-attribute approach a few weeks ago [2].

I've also renamed this from "spec" to "config", because it is a
config.  I'm not sure why runtime-spec decided to call the main
config.go type 'Spec' [3], but I don't think we should repeat that
idiosyncrasy.

[1]: opencontainers#137 (comment)
[2]: opencontainers#253 (comment)
[3]: https://github.com/opencontainers/runtime-spec/blob/v1.0.0-rc2/specs-go/config.go#L6

Signed-off-by: W. Trevor King <wking@tremily.us>
  • Loading branch information
wking committed Nov 23, 2016
1 parent 476f1fb commit 6815c45
Show file tree
Hide file tree
Showing 4 changed files with 321 additions and 333 deletions.
4 changes: 1 addition & 3 deletions cmd/oci-runtime-tool/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,7 @@ func setupSpec(g *generate.Generator, context *cli.Context) error {
g.HostSpecific = true
}

spec := g.Spec()

if len(spec.Version) == 0 {
if len(g.Config.Version) == 0 {
g.SetVersion(rspec.Version)
}

Expand Down
74 changes: 74 additions & 0 deletions generate/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package generate

import (
rspec "github.com/opencontainers/runtime-spec/specs-go"
)

func (g *Generator) initConfig() {
if g.Config == nil {
g.Config = &rspec.Spec{}
}
}

func (g *Generator) initConfigAnnotations() {
g.initConfig()
if g.Config.Annotations == nil {
g.Config.Annotations = make(map[string]string)
}
}

func (g *Generator) initConfigLinux() {
g.initConfig()
if g.Config.Linux == nil {
g.Config.Linux = &rspec.Linux{}
}
}

func (g *Generator) initConfigLinuxSysctl() {
g.initConfigLinux()
if g.Config.Linux.Sysctl == nil {
g.Config.Linux.Sysctl = make(map[string]string)
}
}

func (g *Generator) initConfigLinuxSeccomp() {
g.initConfigLinux()
if g.Config.Linux.Seccomp == nil {
g.Config.Linux.Seccomp = &rspec.Seccomp{}
}
}

func (g *Generator) initConfigLinuxResources() {
g.initConfigLinux()
if g.Config.Linux.Resources == nil {
g.Config.Linux.Resources = &rspec.Resources{}
}
}

func (g *Generator) initConfigLinuxResourcesCPU() {
g.initConfigLinuxResources()
if g.Config.Linux.Resources.CPU == nil {
g.Config.Linux.Resources.CPU = &rspec.CPU{}
}
}

func (g *Generator) initConfigLinuxResourcesMemory() {
g.initConfigLinuxResources()
if g.Config.Linux.Resources.Memory == nil {
g.Config.Linux.Resources.Memory = &rspec.Memory{}
}
}

func (g *Generator) initConfigLinuxResourcesNetwork() {
g.initConfigLinuxResources()
if g.Config.Linux.Resources.Network == nil {
g.Config.Linux.Resources.Network = &rspec.Network{}
}
}

func (g *Generator) initConfigLinuxResourcesPids() {
g.initConfigLinuxResources()
if g.Config.Linux.Resources.Pids == nil {
g.Config.Linux.Resources.Pids = &rspec.Pids{}
}
}
Loading

0 comments on commit 6815c45

Please sign in to comment.