Skip to content

Commit 853c5c4

Browse files
mheonrh-atomic-bot
authored andcommitted
Add --cgroup-manager flag to Podman binary
Signed-off-by: Matthew Heon <[email protected]> Closes: containers#507 Approved by: baude
1 parent df83d36 commit 853c5c4

File tree

7 files changed

+21
-4
lines changed

7 files changed

+21
-4
lines changed

cmd/podman/libpodruntime/runtime.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,10 @@ func GetRuntimeWithStorageOpts(c *cli.Context, storageOpts *storage.StoreOptions
4242
options = append(options, libpod.WithConmonPath(c.GlobalString("conmon")))
4343
}
4444

45-
// TODO flag to set CGroup manager?
45+
if c.GlobalIsSet("cgroup-manager") {
46+
options = append(options, libpod.WithCgroupManager(c.GlobalString("cgroup-manager")))
47+
}
48+
4649
// TODO flag to set libpod static dir?
4750
// TODO flag to set libpod tmp dir?
4851

cmd/podman/main.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,10 @@ func main() {
108108
return nil
109109
}
110110
app.Flags = []cli.Flag{
111+
cli.StringFlag{
112+
Name: "cgroup-manager",
113+
Usage: "cgroup manager to use (cgroupfs or systemd, default cgroupfs)",
114+
},
111115
cli.StringFlag{
112116
Name: "cni-config-dir",
113117
Usage: "path of the configuration directory for CNI networks",

docs/podman.1.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ has the capability to debug pods/images created by crio.
2323
**--help, -h**
2424
Print usage statement
2525

26+
**--cgroup-manager**
27+
CGroup manager to use for container cgroups. Supported values are cgroupfs (default) or systemd. Setting this flag can cause certain commands to break when called on containers created by the other CGroup manager type.
28+
2629
**--config value, -c**=**"config.file"**
2730
Path of a config file detailing container server configuration options
2831

libpod/container_internal.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1133,7 +1133,9 @@ func (c *Container) generateSpec(ctx context.Context) (*spec.Spec, error) {
11331133
// When runc is set to use Systemd as a cgroup manager, it
11341134
// expects cgroups to be passed as follows:
11351135
// slice:prefix:name
1136-
g.SetLinuxCgroupsPath(path.Base(c.config.CgroupParent) + ":" + "libpod" + ":" + c.ID())
1136+
systemdCgroups := fmt.Sprintf("%s:libpod:%s", path.Base(c.config.CgroupParent), c.ID())
1137+
logrus.Debugf("Setting CGroups for container %s to %s", c.ID(), systemdCgroups)
1138+
g.SetLinuxCgroupsPath(systemdCgroups)
11371139
} else {
11381140
cgroupPath, err := c.CGroupPath()
11391141
if err != nil {

libpod/oci.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ func (r *OCIRuntime) createOCIContainer(ctr *Container, cgroupParent string) (er
321321

322322
// Move conmon to specified cgroup
323323
if r.cgroupManager == SystemdCgroupsManager {
324-
unitName := createUnitName("libpod", ctr.ID())
324+
unitName := createUnitName("libpod-conmon", ctr.ID())
325325

326326
logrus.Infof("Running conmon under slice %s and unitName %s", cgroupParent, unitName)
327327
if err = utils.RunUnderSystemdScope(cmd.Process.Pid, cgroupParent, unitName); err != nil {

libpod/options.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,11 @@ func WithCgroupManager(manager string) RuntimeOption {
152152
return ErrRuntimeFinalized
153153
}
154154

155+
if manager != CgroupfsCgroupsManager && manager != SystemdCgroupsManager {
156+
return errors.Wrapf(ErrInvalidArg, "CGroup manager must be one of %s and %s",
157+
CgroupfsCgroupsManager, SystemdCgroupsManager)
158+
}
159+
155160
rt.config.CgroupManager = manager
156161

157162
return nil

libpod/runtime.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ var (
158158
ConmonEnvVars: []string{
159159
"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
160160
},
161-
CgroupManager: "cgroupfs",
161+
CgroupManager: CgroupfsCgroupsManager,
162162
HooksDir: hooks.DefaultHooksDir,
163163
StaticDir: filepath.Join(storage.DefaultStoreOptions.GraphRoot, "libpod"),
164164
TmpDir: "/var/run/libpod",

0 commit comments

Comments
 (0)