Skip to content

Commit 71c8a6b

Browse files
author
Ma Shimiao
committed
generate: add new cgroup namespace option
Signed-off-by: Ma Shimiao <[email protected]>
1 parent ee24bb5 commit 71c8a6b

File tree

3 files changed

+16
-6
lines changed

3 files changed

+16
-6
lines changed

completions/bash/ocitools

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -274,15 +274,20 @@ _ocitools_generate() {
274274
--bind
275275
--cap-add
276276
--cap-drop
277+
--cgroup
277278
--cwd
278279
--env
279280
--gid
280281
--gidmappings
281282
--groups
282283
--hostname
283284
--help
285+
--ipc
286+
--mount
284287
--mount-cgroups
288+
--network
285289
--os
290+
--pid
286291
--poststart
287292
--poststop
288293
--prestart
@@ -297,17 +302,14 @@ _ocitools_generate() {
297302
--tmpfs
298303
--uid
299304
--uidmappings
305+
--uts
300306
"
301307

302308
local boolean_options="
303-
--ipc
304-
--network
305309
--no-new-privileges
306-
--mount
307-
--pid
308310
--privileged
309311
--read-only
310-
--uts
312+
--tty
311313
"
312314

313315
local all_options="$options_with_args $boolean_options"

generate.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ var generateFlags = []cli.Flag{
2727
cli.StringSliceFlag{Name: "groups", Usage: "supplementary groups for the process"},
2828
cli.StringSliceFlag{Name: "cap-add", Usage: "add capabilities"},
2929
cli.StringSliceFlag{Name: "cap-drop", Usage: "drop capabilities"},
30+
cli.StringFlag{Name: "cgroup", Usage: "cgroup namespace"},
3031
cli.StringFlag{Name: "network", Usage: "network namespace"},
3132
cli.StringFlag{Name: "mount", Usage: "mount namespace"},
3233
cli.StringFlag{Name: "pid", Usage: "pid namespace"},
@@ -672,6 +673,8 @@ func mapStrToNamespace(ns string, path string) rspec.Namespace {
672673
return rspec.Namespace{Type: rspec.UTSNamespace, Path: path}
673674
case "user":
674675
return rspec.Namespace{Type: rspec.UserNamespace, Path: path}
676+
case "cgroup":
677+
return rspec.Namespace{Type: rspec.CgroupNamespace, Path: path}
675678
default:
676679
logrus.Fatalf("Should not reach here!")
677680
}
@@ -684,7 +687,7 @@ func setupNamespaces(spec *rspec.Spec, context *cli.Context) {
684687
needsNewUser = true
685688
}
686689

687-
namespaces := []string{"network", "pid", "mount", "ipc", "uts", "user"}
690+
namespaces := []string{"network", "pid", "mount", "ipc", "uts", "user", "cgroup"}
688691
for _, nsName := range namespaces {
689692
if !context.IsSet(nsName) && !(needsNewUser && nsName == "user") {
690693
continue

man/ocitools-generate.1.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,11 @@ compatible runtime like runC to run a container.
4444
**--cap-drop**=[]
4545
Drop Linux capabilities
4646

47+
**--cgroup**=[*PATH*]
48+
Use an Cgroup namespace. If *PATH* is set, join that namespace. If it
49+
is unset, create a new namespace. The special *PATH* `host` removes
50+
any existing Cgroup namespace from the configuration.
51+
4752
**--cgroups-path**=""
4853
Specifiy the path to the cgroups relative to the cgroups mount point.
4954

0 commit comments

Comments
 (0)