Skip to content

Commit 4fcbcb4

Browse files
committed
Merge branch 'v1.0.0.rc1'
* v1.0.0.rc1: man/ocitools.1: Replace "**...(1)**" with "**...**(1)" add namespace check for uid/gid mappings validation: add linux resource check add label manpage and fix help support setting oom_score_adj generate: fix mount-cgroups bug completions: update based on generate help message update urfave/cli package to v1.18.0 generate: optimize namespace setup log and fix manpage change param type of AddProcessAdditionalGid remove unnecessary return error value Modify generate API Add Travis CI badge to README generate: fix capability.List() for cap_last_cap not exist generate: remove unnecessary spec initialization generate: fix tmpfs adding based on manpage Check CAP_LAST_CAP while setting privileged generate: Remove superfluous err check from Save Signed-off-by: W. Trevor King <wking@tremily.us> Conflicts: cmd/ocitools/generate.go man/ocitools-generate.1.md The conflicts are because: * support setting oom_score_adj (#176, #185) * add label manpage and fix help (#189, #190) have landed in master and been backported to v1.0.0.rc1 since this branch split from master. They wouldn't have happend if I'd rebased this branch on the current master before merging v1.0.0.rc1, but then I'd have to repeat the initial dance done with eac0762 (Merge commit '30e2ea2', 2016-08-02) and b45bebd (Merge commit '6acca9e', 2016-08-02).
2 parents eac0762 + 975c97f commit 4fcbcb4

6 files changed

Lines changed: 66 additions & 26 deletions

File tree

cmd/ocitools/generate.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ var generateFlags = []cli.Flag{
3636
cli.StringFlag{Name: "mount-label", Usage: "selinux mount context label"},
3737
cli.StringSliceFlag{Name: "tmpfs", Usage: "mount tmpfs"},
3838
cli.StringSliceFlag{Name: "args", Usage: "command to run in the container"},
39-
cli.StringSliceFlag{Name: "env", Usage: "add environment variable"},
39+
cli.StringSliceFlag{Name: "env", Usage: "add environment variable e.g. key=value"},
4040
cli.StringFlag{Name: "cgroups-path", Usage: "specify the path to the cgroups"},
4141
cli.StringFlag{Name: "mount-cgroups", Value: "no", Usage: "mount cgroups (rw,ro,no)"},
4242
cli.StringSliceFlag{Name: "bind", Usage: "bind mount directories src:dest:(rw,ro)"},
@@ -58,6 +58,7 @@ var generateFlags = []cli.Flag{
5858
cli.StringSliceFlag{Name: "seccomp-errno", Usage: "specifies syscalls to be added to list that returns an error"},
5959
cli.StringFlag{Name: "template", Usage: "base template to use for creating the configuration"},
6060
cli.StringSliceFlag{Name: "label", Usage: "add annotations to the configuration e.g. key=value"},
61+
cli.IntFlag{Name: "oom-score-adj", Usage: "oom_score_adj for the container"},
6162
}
6263

6364
var generateCommand = cli.Command{
@@ -319,6 +320,10 @@ func setupSpec(g *generate.Generator, context *cli.Context) error {
319320
g.AddLinuxGIDMapping(hid, cid, size)
320321
}
321322

323+
if context.IsSet("oom-score-adj") {
324+
g.SetLinuxResourcesOOMScoreAdj(context.Int("oom-score-adj"))
325+
}
326+
322327
var sd string
323328
var sa, ss []string
324329

cmd/ocitools/validate.go

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -316,13 +316,7 @@ func checkLinux(spec rspec.Spec, rootfs string, hostCheck bool) (msgs []string)
316316
ipcExists := false
317317
mountExists := false
318318
netExists := false
319-
320-
if len(spec.Linux.UIDMappings) > 5 {
321-
msgs = append(msgs, "Only 5 UID mappings are allowed (linux kernel restriction).")
322-
}
323-
if len(spec.Linux.GIDMappings) > 5 {
324-
msgs = append(msgs, "Only 5 GID mappings are allowed (linux kernel restriction).")
325-
}
319+
userExists := false
326320

327321
for index := 0; index < len(spec.Linux.Namespaces); index++ {
328322
if !namespaceValid(spec.Linux.Namespaces[index]) {
@@ -336,10 +330,20 @@ func checkLinux(spec rspec.Spec, rootfs string, hostCheck bool) (msgs []string)
336330
netExists = true
337331
} else if spec.Linux.Namespaces[index].Type == rspec.MountNamespace {
338332
mountExists = true
333+
} else if spec.Linux.Namespaces[index].Type == rspec.UserNamespace {
334+
userExists = true
339335
}
340336
}
341337
}
342338

339+
if (len(spec.Linux.UIDMappings) > 0 || len(spec.Linux.GIDMappings) > 0) && !userExists {
340+
msgs = append(msgs, "UID/GID mappings requires a new User namespace to be specified as well")
341+
} else if len(spec.Linux.UIDMappings) > 5 {
342+
msgs = append(msgs, "Only 5 UID mappings are allowed (linux kernel restriction).")
343+
} else if len(spec.Linux.GIDMappings) > 5 {
344+
msgs = append(msgs, "Only 5 GID mappings are allowed (linux kernel restriction).")
345+
}
346+
343347
for k := range spec.Linux.Sysctl {
344348
if strings.HasPrefix(k, "net.") && !netExists {
345349
msgs = append(msgs, fmt.Sprintf("Sysctl %v requires a new Network namespace to be specified as well", k))
@@ -361,6 +365,11 @@ func checkLinux(spec rspec.Spec, rootfs string, hostCheck bool) (msgs []string)
361365
}
362366
}
363367

368+
if spec.Linux.Resources != nil {
369+
ms := checkLinuxResources(*spec.Linux.Resources, hostCheck)
370+
msgs = append(msgs, ms...)
371+
}
372+
364373
if spec.Linux.Seccomp != nil {
365374
ms := checkSeccomp(*spec.Linux.Seccomp)
366375
msgs = append(msgs, ms...)
@@ -381,6 +390,21 @@ func checkLinux(spec rspec.Spec, rootfs string, hostCheck bool) (msgs []string)
381390
return
382391
}
383392

393+
func checkLinuxResources(r rspec.Resources, hostCheck bool) (msgs []string) {
394+
logrus.Debugf("check linux resources")
395+
396+
if r.Memory != nil {
397+
if r.Memory.Limit != nil && r.Memory.Swap != nil && uint64(*r.Memory.Limit) > uint64(*r.Memory.Swap) {
398+
msgs = append(msgs, fmt.Sprintf("Minimum memoryswap should be larger than memory limit"))
399+
}
400+
if r.Memory.Limit != nil && r.Memory.Reservation != nil && uint64(*r.Memory.Reservation) > uint64(*r.Memory.Limit) {
401+
msgs = append(msgs, fmt.Sprintf("Minimum memory limit should be larger than memory reservation"))
402+
}
403+
}
404+
405+
return
406+
}
407+
384408
func checkSeccomp(s rspec.Seccomp) (msgs []string) {
385409
logrus.Debugf("check seccomp")
386410

completions/bash/ocitools

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,7 @@ _ocitools_generate() {
275275
--cap-add
276276
--cap-drop
277277
--cgroup
278+
--cgroup-path
278279
--cwd
279280
--env
280281
--gid
@@ -283,25 +284,31 @@ _ocitools_generate() {
283284
--hostname
284285
--help
285286
--ipc
287+
--label
286288
--mount
287289
--mount-cgroups
290+
--mount-label
288291
--network
289292
--os
293+
--output
290294
--pid
291295
--poststart
292296
--poststop
293297
--prestart
294298
--root-propagation
295299
--rootfs
296-
--seccomp-default
300+
--seccomp-allow
297301
--seccomp-arch
302+
--seccomp-default
303+
--seccomp-errno
298304
--seccomp-syscalls
299305
--selinux-label
300-
--mount-label
301306
--sysctl
307+
--tmplate
302308
--tmpfs
303309
--uid
304310
--uidmappings
311+
--user
305312
--uts
306313
"
307314

@@ -330,11 +337,6 @@ _ocitools_generate() {
330337
return
331338
;;
332339

333-
--seccomp-default)
334-
__ocitools_complete_seccomp_actions
335-
return
336-
;;
337-
338340
--root-propagation)
339341
__ocitools_complete_propagations
340342
return

generate/generate.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -194,11 +194,7 @@ func (g *Generator) Save(w io.Writer) error {
194194
}
195195

196196
_, err = w.Write(data)
197-
if err != nil {
198-
return err
199-
}
200-
201-
return nil
197+
return err
202198
}
203199

204200
// SaveToFile writes the spec into a file.
@@ -362,6 +358,12 @@ func (g *Generator) SetLinuxMountLabel(label string) {
362358
g.spec.Linux.MountLabel = label
363359
}
364360

361+
// SetLinuxResourcesOOMScoreAdj sets g.spec.Linux.Resources.OOMScoreAdj.
362+
func (g *Generator) SetLinuxResourcesOOMScoreAdj(adj int) {
363+
g.initSpecLinuxResources()
364+
g.spec.Linux.Resources.OOMScoreAdj = &adj
365+
}
366+
365367
// SetLinuxResourcesCPUShares sets g.spec.Linux.Resources.CPU.Shares.
366368
func (g *Generator) SetLinuxResourcesCPUShares(shares uint64) {
367369
g.initSpecLinuxResourcesCPU()
@@ -855,6 +857,7 @@ func (g *Generator) AddCgroupsMount(mountCgroupOption string) error {
855857
switch mountCgroupOption {
856858
case "ro":
857859
case "rw":
860+
break
858861
case "no":
859862
return nil
860863
default:

man/ocitools-generate.1.md

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,10 @@ read the configuration from `config.json`.
5858
Current working directory for the process
5959

6060
**--env**=[]
61-
Set environment variables
62-
This option allows you to specify arbitrary
63-
environment variables that are available for the process that will be launched
64-
inside of the container.
61+
Set environment variables e.g. key=value.
62+
This option allows you to specify arbitrary environment variables
63+
that are available for the process that will be launched inside of
64+
the container.
6565

6666
**--gid**=GID
6767
Gid for the process inside of container
@@ -84,6 +84,9 @@ inside of the container.
8484
The special *PATH* `host` removes any existing IPC namespace from the
8585
configuration.
8686

87+
**--label**=[]
88+
Add annotations to the configuration e.g. key=value.
89+
8790
**--mount**=*PATH*
8891
Use a mount namespace where *PATH* is an existing mount namespace file
8992
to join. The special *PATH* empty-string creates a new namespace.
@@ -117,6 +120,9 @@ inside of the container.
117120
using tools like setuid apps. It is a good idea to run unprivileged
118121
containers with this flag.
119122

123+
**--oom-score-adj**=adj
124+
Specifies oom_score_adj for the container.
125+
120126
**--output**=PATH
121127
Instead of writing the configuration JSON to stdout, write it to a
122128
file at *PATH* (overwriting the existing content if a file already

man/ocitools.1.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,11 @@ ocitools is a collection of tools for working with the [OCI runtime specificatio
3838
# COMMANDS
3939
**validate**
4040
Validating OCI bundle
41-
See **ocitools-validate(1)** for full documentation on the **validate** command.
41+
See **ocitools-validate**(1) for full documentation on the **validate** command.
4242

4343
**generate**
4444
Generating OCI runtime spec configuration files
45-
See **ocitools-generate(1)** for full documentation on the **generate** command.
45+
See **ocitools-generate**(1) for full documentation on the **generate** command.
4646

4747
# SEE ALSO
4848
**ocitools-validate**(1), **ocitools-generate**(1)

0 commit comments

Comments
 (0)