Skip to content

Commit a0fe802

Browse files
committed
generate: Move Generator.spec to Generator.Config
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]: #137 (comment) [2]: #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 <[email protected]>
1 parent 303b751 commit a0fe802

File tree

4 files changed

+334
-346
lines changed

4 files changed

+334
-346
lines changed

cmd/oci-runtime-tool/generate.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,9 +136,7 @@ func setupSpec(g *generate.Generator, context *cli.Context) error {
136136
g.HostSpecific = true
137137
}
138138

139-
spec := g.Spec()
140-
141-
if len(spec.Version) == 0 {
139+
if len(g.Config.Version) == 0 {
142140
g.SetVersion(rspec.Version)
143141
}
144142

generate/config.go

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
package generate
2+
3+
import (
4+
rspec "github.com/opencontainers/runtime-spec/specs-go"
5+
)
6+
7+
func (g *Generator) initConfig() {
8+
if g.Config == nil {
9+
g.Config = &rspec.Spec{}
10+
}
11+
}
12+
13+
func (g *Generator) initConfigAnnotations() {
14+
g.initConfig()
15+
if g.Config.Annotations == nil {
16+
g.Config.Annotations = make(map[string]string)
17+
}
18+
}
19+
20+
func (g *Generator) initConfigLinux() {
21+
g.initConfig()
22+
if g.Config.Linux == nil {
23+
g.Config.Linux = &rspec.Linux{}
24+
}
25+
}
26+
27+
func (g *Generator) initConfigLinuxSysctl() {
28+
g.initConfigLinux()
29+
if g.Config.Linux.Sysctl == nil {
30+
g.Config.Linux.Sysctl = make(map[string]string)
31+
}
32+
}
33+
34+
func (g *Generator) initConfigLinuxSeccomp() {
35+
g.initConfigLinux()
36+
if g.Config.Linux.Seccomp == nil {
37+
g.Config.Linux.Seccomp = &rspec.Seccomp{}
38+
}
39+
}
40+
41+
func (g *Generator) initConfigLinuxResources() {
42+
g.initConfigLinux()
43+
if g.Config.Linux.Resources == nil {
44+
g.Config.Linux.Resources = &rspec.Resources{}
45+
}
46+
}
47+
48+
func (g *Generator) initConfigLinuxResourcesCPU() {
49+
g.initConfigLinuxResources()
50+
if g.Config.Linux.Resources.CPU == nil {
51+
g.Config.Linux.Resources.CPU = &rspec.CPU{}
52+
}
53+
}
54+
55+
func (g *Generator) initConfigLinuxResourcesMemory() {
56+
g.initConfigLinuxResources()
57+
if g.Config.Linux.Resources.Memory == nil {
58+
g.Config.Linux.Resources.Memory = &rspec.Memory{}
59+
}
60+
}
61+
62+
func (g *Generator) initConfigLinuxResourcesNetwork() {
63+
g.initConfigLinuxResources()
64+
if g.Config.Linux.Resources.Network == nil {
65+
g.Config.Linux.Resources.Network = &rspec.Network{}
66+
}
67+
}
68+
69+
func (g *Generator) initConfigLinuxResourcesPids() {
70+
g.initConfigLinuxResources()
71+
if g.Config.Linux.Resources.Pids == nil {
72+
g.Config.Linux.Resources.Pids = &rspec.Pids{}
73+
}
74+
}

0 commit comments

Comments
 (0)