Skip to content

Commit f2107e5

Browse files
committed
generate: Don't serialize Spec.Linux as an empty JSON object
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?". Signed-off-by: W. Trevor King <wking@tremily.us>
1 parent 3334d03 commit f2107e5

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

generate/generate.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,16 @@ func (g *Generator) GetSpec() *rspec.Spec {
181181

182182
// Save writes the spec into w.
183183
func (g *Generator) Save(w io.Writer) error {
184+
if g.spec.Linux != nil {
185+
buf, err := json.Marshal(g.spec.Linux)
186+
if err != nil {
187+
return err
188+
}
189+
if string(buf) == "{}" {
190+
g.spec.Linux = nil
191+
}
192+
}
193+
184194
data, err := json.MarshalIndent(g.spec, "", "\t")
185195
if err != nil {
186196
return err
@@ -959,6 +969,9 @@ func (g *Generator) SetupPrivileged(privileged bool) {
959969
g.spec.Process.Capabilities = finalCapList
960970
g.spec.Process.SelinuxLabel = ""
961971
g.spec.Process.ApparmorProfile = ""
972+
if g.spec.Linux == nil {
973+
g.spec.Linux = &rspec.Linux{}
974+
}
962975
g.spec.Linux.Seccomp = nil
963976
}
964977
}

0 commit comments

Comments
 (0)