mirror of
https://github.com/containers/podman.git
synced 2025-10-19 20:23:08 +08:00
podman: add new option --cgroups=no-conmon
it allows to disable cgroups creation only for the conmon process. A new cgroup is created for the container payload. Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
This commit is contained in:
@ -158,7 +158,7 @@ func getCreateFlags(c *cliconfig.PodmanCommand) {
|
|||||||
)
|
)
|
||||||
createFlags.String(
|
createFlags.String(
|
||||||
"cgroups", "enabled",
|
"cgroups", "enabled",
|
||||||
"control container cgroup configuration",
|
`control container cgroup configuration ("enabled"|"disabled"|"no-conmon")`,
|
||||||
)
|
)
|
||||||
createFlags.String(
|
createFlags.String(
|
||||||
"cgroup-parent", "",
|
"cgroup-parent", "",
|
||||||
|
@ -78,8 +78,9 @@ If the host uses cgroups v1, the default is set to **host**. On cgroups v2 the
|
|||||||
**--cgroups**=*mode*
|
**--cgroups**=*mode*
|
||||||
|
|
||||||
Determines whether the container will create CGroups.
|
Determines whether the container will create CGroups.
|
||||||
Valid values are *enabled* and *disabled*, which the default being *enabled*.
|
Valid values are *enabled*, *disabled*, *no-conmon*, which the default being *enabled*.
|
||||||
The *disabled* option will force the container to not create CGroups, and thus conflicts with CGroup options (**--cgroupns** and **--cgroup-parent**).
|
The *disabled* option will force the container to not create CGroups, and thus conflicts with CGroup options (**--cgroupns** and **--cgroup-parent**).
|
||||||
|
The *no-conmon* option disables a new CGroup only for the conmon process.
|
||||||
|
|
||||||
**--cgroup-parent**=*path*
|
**--cgroup-parent**=*path*
|
||||||
|
|
||||||
|
@ -92,8 +92,9 @@ If the host uses cgroups v1, the default is set to **host**. On cgroups v2 the
|
|||||||
**--cgroups**=*mode*
|
**--cgroups**=*mode*
|
||||||
|
|
||||||
Determines whether the container will create CGroups.
|
Determines whether the container will create CGroups.
|
||||||
Valid values are *enabled* and *disabled*, which the default being *enabled*.
|
Valid values are *enabled*, *disabled*, *no-conmon*, which the default being *enabled*.
|
||||||
The *disabled* option will force the container to not create CGroups, and thus conflicts with CGroup options (**--cgroupns** and **--cgroup-parent**).
|
The *disabled* option will force the container to not create CGroups, and thus conflicts with CGroup options (**--cgroupns** and **--cgroup-parent**).
|
||||||
|
The *no-conmon* option disables a new CGroup only for the conmon process.
|
||||||
|
|
||||||
**--cgroup-parent**=*cgroup*
|
**--cgroup-parent**=*cgroup*
|
||||||
|
|
||||||
|
@ -373,8 +373,11 @@ type ContainerConfig struct {
|
|||||||
// Time container was created
|
// Time container was created
|
||||||
CreatedTime time.Time `json:"createdTime"`
|
CreatedTime time.Time `json:"createdTime"`
|
||||||
// NoCgroups indicates that the container will not create CGroups. It is
|
// NoCgroups indicates that the container will not create CGroups. It is
|
||||||
// incompatible with CgroupParent.
|
// incompatible with CgroupParent. Deprecated in favor of CgroupsMode.
|
||||||
NoCgroups bool `json:"noCgroups,omitempty"`
|
NoCgroups bool `json:"noCgroups,omitempty"`
|
||||||
|
// CgroupsMode indicates how the container will create cgroups
|
||||||
|
// (disabled, no-conmon, enabled). It supersedes NoCgroups.
|
||||||
|
CgroupsMode string `json:"cgroupsMode,omitempty"`
|
||||||
// Cgroup parent of the container
|
// Cgroup parent of the container
|
||||||
CgroupParent string `json:"cgroupParent"`
|
CgroupParent string `json:"cgroupParent"`
|
||||||
// LogPath log location
|
// LogPath log location
|
||||||
|
@ -1297,11 +1297,17 @@ func startCommandGivenSelinux(cmd *exec.Cmd) error {
|
|||||||
// it then signals for conmon to start by sending nonse data down the start fd
|
// it then signals for conmon to start by sending nonse data down the start fd
|
||||||
func (r *ConmonOCIRuntime) moveConmonToCgroupAndSignal(ctr *Container, cmd *exec.Cmd, startFd *os.File) error {
|
func (r *ConmonOCIRuntime) moveConmonToCgroupAndSignal(ctr *Container, cmd *exec.Cmd, startFd *os.File) error {
|
||||||
mustCreateCgroup := true
|
mustCreateCgroup := true
|
||||||
// If cgroup creation is disabled - just signal.
|
|
||||||
if ctr.config.NoCgroups {
|
if ctr.config.NoCgroups {
|
||||||
mustCreateCgroup = false
|
mustCreateCgroup = false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If cgroup creation is disabled - just signal.
|
||||||
|
switch ctr.config.CgroupsMode {
|
||||||
|
case "disabled", "no-conmon":
|
||||||
|
mustCreateCgroup = false
|
||||||
|
}
|
||||||
|
|
||||||
if mustCreateCgroup {
|
if mustCreateCgroup {
|
||||||
cgroupParent := ctr.CgroupParent()
|
cgroupParent := ctr.CgroupParent()
|
||||||
if r.cgroupManager == define.SystemdCgroupsManager {
|
if r.cgroupManager == define.SystemdCgroupsManager {
|
||||||
|
@ -1078,25 +1078,26 @@ func WithLogTag(tag string) CtrCreateOption {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// WithNoCgroups disables the creation of CGroups for the new container.
|
// WithCgroupsMode disables the creation of CGroups for the conmon process.
|
||||||
func WithNoCgroups() CtrCreateOption {
|
func WithCgroupsMode(mode string) CtrCreateOption {
|
||||||
return func(ctr *Container) error {
|
return func(ctr *Container) error {
|
||||||
if ctr.valid {
|
if ctr.valid {
|
||||||
return define.ErrCtrFinalized
|
return define.ErrCtrFinalized
|
||||||
}
|
}
|
||||||
|
|
||||||
if ctr.config.CgroupParent != "" {
|
switch mode {
|
||||||
return errors.Wrapf(define.ErrInvalidArg, "NoCgroups conflicts with CgroupParent")
|
case "disabled":
|
||||||
}
|
|
||||||
|
|
||||||
if ctr.config.PIDNsCtr != "" {
|
|
||||||
return errors.Wrapf(define.ErrInvalidArg, "NoCgroups requires a private PID namespace and cannot be used when PID namespace is shared with another container")
|
|
||||||
}
|
|
||||||
|
|
||||||
ctr.config.NoCgroups = true
|
ctr.config.NoCgroups = true
|
||||||
|
ctr.config.CgroupsMode = mode
|
||||||
|
case "enabled", "no-conmon":
|
||||||
|
ctr.config.CgroupsMode = mode
|
||||||
|
default:
|
||||||
|
return errors.Wrapf(define.ErrInvalidArg, "Invalid cgroup mode %q", mode)
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// WithCgroupParent sets the Cgroup Parent of the new container.
|
// WithCgroupParent sets the Cgroup Parent of the new container.
|
||||||
|
@ -213,8 +213,8 @@ func (c *CgroupConfig) ToCreateOptions(runtime *libpod.Runtime) ([]libpod.CtrCre
|
|||||||
options = append(options, libpod.WithCgroupParent(c.CgroupParent))
|
options = append(options, libpod.WithCgroupParent(c.CgroupParent))
|
||||||
}
|
}
|
||||||
|
|
||||||
if c.Cgroups == "disabled" {
|
if c.Cgroups != "" {
|
||||||
options = append(options, libpod.WithNoCgroups())
|
options = append(options, libpod.WithCgroupsMode(c.Cgroups))
|
||||||
}
|
}
|
||||||
|
|
||||||
return options, nil
|
return options, nil
|
||||||
|
@ -358,10 +358,10 @@ func (config *CreateConfig) createConfigToOCISpec(runtime *libpod.Runtime, userM
|
|||||||
return nil, errors.New("cannot specify resource limits when cgroups are disabled is specified")
|
return nil, errors.New("cannot specify resource limits when cgroups are disabled is specified")
|
||||||
}
|
}
|
||||||
configSpec.Linux.Resources = &spec.LinuxResources{}
|
configSpec.Linux.Resources = &spec.LinuxResources{}
|
||||||
case "enabled", "":
|
case "enabled", "no-conmon", "":
|
||||||
// Do nothing
|
// Do nothing
|
||||||
default:
|
default:
|
||||||
return nil, errors.New("unrecognized option for cgroups; supported are 'default' and 'disabled'")
|
return nil, errors.New("unrecognized option for cgroups; supported are 'default', 'disabled', 'no-conmon'")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add annotations
|
// Add annotations
|
||||||
|
Reference in New Issue
Block a user