Skip to content

Commit

Permalink
Merge pull request #12860 from rhatdan/cgroups
Browse files Browse the repository at this point in the history
Use CONTAINERS_CONF cgroups flag for remote API.
  • Loading branch information
openshift-merge-robot authored Jan 17, 2022
2 parents 26cf6c8 + 607cb80 commit 8514ebd
Show file tree
Hide file tree
Showing 42 changed files with 142 additions and 97 deletions.
6 changes: 3 additions & 3 deletions cmd/podman/common/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func DefineCreateFlags(cmd *cobra.Command, cf *entities.ContainerCreateOptions,

cgroupsFlagName := "cgroups"
createFlags.StringVar(
&cf.CGroupsMode,
&cf.CgroupsMode,
cgroupsFlagName, cgroupConfig(),
`control container cgroup configuration ("enabled"|"disabled"|"no-conmon"|"split")`,
)
Expand Down Expand Up @@ -159,7 +159,7 @@ func DefineCreateFlags(cmd *cobra.Command, cf *entities.ContainerCreateOptions,

deviceCgroupRuleFlagName := "device-cgroup-rule"
createFlags.StringSliceVar(
&cf.DeviceCGroupRule,
&cf.DeviceCgroupRule,
deviceCgroupRuleFlagName, []string{},
"Add a rule to the cgroup allowed devices list",
)
Expand Down Expand Up @@ -762,7 +762,7 @@ func DefineCreateFlags(cmd *cobra.Command, cf *entities.ContainerCreateOptions,

cgroupParentFlagName := "cgroup-parent"
createFlags.StringVar(
&cf.CGroupParent,
&cf.CgroupParent,
cgroupParentFlagName, "",
"Optional parent cgroup for the container",
)
Expand Down
4 changes: 2 additions & 2 deletions cmd/podman/common/create_opts.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ func ContainerCreateToContainerCLIOpts(cc handlers.CreateContainerConfig, rtc *c
Authfile: "",
CapAdd: append(capAdd, cc.HostConfig.CapAdd...),
CapDrop: append(cappDrop, cc.HostConfig.CapDrop...),
CGroupParent: cc.HostConfig.CgroupParent,
CgroupParent: cc.HostConfig.CgroupParent,
CIDFile: cc.HostConfig.ContainerIDFile,
CPUPeriod: uint64(cc.HostConfig.CPUPeriod),
CPUQuota: cc.HostConfig.CPUQuota,
Expand All @@ -259,7 +259,7 @@ func ContainerCreateToContainerCLIOpts(cc handlers.CreateContainerConfig, rtc *c
// Detach: false, // don't need
// DetachKeys: "", // don't need
Devices: devices,
DeviceCGroupRule: nil,
DeviceCgroupRule: nil,
DeviceReadBPs: readBps,
DeviceReadIOPs: readIops,
DeviceWriteBPs: writeBps,
Expand Down
4 changes: 2 additions & 2 deletions cmd/podman/containers/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,8 +257,8 @@ func CreateInit(c *cobra.Command, vals entities.ContainerCreateOptions, isInfra
}
vals.Env = env
}
if c.Flag("cgroups").Changed && vals.CGroupsMode == "split" && registry.IsRemote() {
return vals, errors.Errorf("the option --cgroups=%q is not supported in remote mode", vals.CGroupsMode)
if c.Flag("cgroups").Changed && vals.CgroupsMode == "split" && registry.IsRemote() {
return vals, errors.Errorf("the option --cgroups=%q is not supported in remote mode", vals.CgroupsMode)
}

if c.Flag("pod").Changed && !strings.HasPrefix(c.Flag("pod").Value.String(), "new:") && c.Flag("userns").Changed {
Expand Down
2 changes: 1 addition & 1 deletion libpod/boltdb_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ func (s *BoltState) Refresh() error {
return errors.Wrapf(err, "error unmarshalling state for pod %s", string(id))
}

// Clear the CGroup path
// Clear the Cgroup path
state.CgroupPath = ""

newStateBytes, err := json.Marshal(state)
Expand Down
10 changes: 5 additions & 5 deletions libpod/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
"github.com/sirupsen/logrus"
)

// CgroupfsDefaultCgroupParent is the cgroup parent for CGroupFS in libpod
// CgroupfsDefaultCgroupParent is the cgroup parent for CgroupFS in libpod
const CgroupfsDefaultCgroupParent = "/libpod_parent"

// SystemdDefaultCgroupParent is the cgroup parent for the systemd cgroup
Expand Down Expand Up @@ -56,7 +56,7 @@ const (
UserNS LinuxNS = iota
// UTSNS is the UTS namespace
UTSNS LinuxNS = iota
// CgroupNS is the CGroup namespace
// CgroupNS is the Cgroup namespace
CgroupNS LinuxNS = iota
)

Expand Down Expand Up @@ -575,7 +575,7 @@ func (c *Container) CreatedTime() time.Time {
return c.config.CreatedTime
}

// CgroupParent gets the container's CGroup parent
// CgroupParent gets the container's Cgroup parent
func (c *Container) CgroupParent() string {
return c.config.CgroupParent
}
Expand Down Expand Up @@ -907,10 +907,10 @@ func (c *Container) CgroupManager() string {
return cgroupManager
}

// CGroupPath returns a cgroups "path" for the given container.
// CgroupPath returns a cgroups "path" for the given container.
// Note that the container must be running. Otherwise, an error
// is returned.
func (c *Container) CGroupPath() (string, error) {
func (c *Container) CgroupPath() (string, error) {
if !c.batched {
c.lock.Lock()
defer c.lock.Unlock()
Expand Down
2 changes: 1 addition & 1 deletion libpod/container_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ type ContainerMiscConfig struct {
// CgroupManager is the cgroup manager used to create this container.
// If empty, the runtime default will be used.
CgroupManager string `json:"cgroupManager,omitempty"`
// 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. Deprecated in favor of CgroupsMode.
NoCgroups bool `json:"noCgroups,omitempty"`
// CgroupsMode indicates how the container will create cgroups
Expand Down
2 changes: 1 addition & 1 deletion libpod/container_inspect.go
Original file line number Diff line number Diff line change
Expand Up @@ -730,7 +730,7 @@ func (c *Container) generateInspectContainerHostConfig(ctrSpec *spec.Spec, named
}
hostConfig.CgroupMode = cgroupMode

// CGroup parent
// Cgroup parent
// Need to check if it's the default, and not print if so.
defaultCgroupParent := ""
switch c.CgroupManager() {
Expand Down
10 changes: 5 additions & 5 deletions libpod/container_internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -1092,7 +1092,7 @@ func (c *Container) init(ctx context.Context, retainRetries bool) error {
// upstream in any OCI runtime.
// TODO: Remove once runc supports cgroupsv2
if strings.Contains(err.Error(), "this version of runc doesn't work on cgroups v2") {
logrus.Errorf("Oci runtime %q does not support CGroups V2: use system migrate to mitigate", c.ociRuntime.Name())
logrus.Errorf("Oci runtime %q does not support Cgroups V2: use system migrate to mitigate", c.ociRuntime.Name())
}
return err
}
Expand Down Expand Up @@ -1291,8 +1291,8 @@ func (c *Container) stop(timeout uint) error {
// a pid namespace then the OCI Runtime needs to kill ALL processes in
// the containers cgroup in order to make sure the container is stopped.
all := !c.hasNamespace(spec.PIDNamespace)
// We can't use --all if CGroups aren't present.
// Rootless containers with CGroups v1 and NoCgroups are both cases
// We can't use --all if Cgroups aren't present.
// Rootless containers with Cgroups v1 and NoCgroups are both cases
// where this can happen.
if all {
if c.config.NoCgroups {
Expand Down Expand Up @@ -1400,7 +1400,7 @@ func (c *Container) stop(timeout uint) error {
// Internal, non-locking function to pause a container
func (c *Container) pause() error {
if c.config.NoCgroups {
return errors.Wrapf(define.ErrNoCgroups, "cannot pause without using CGroups")
return errors.Wrapf(define.ErrNoCgroups, "cannot pause without using Cgroups")
}

if rootless.IsRootless() {
Expand Down Expand Up @@ -1428,7 +1428,7 @@ func (c *Container) pause() error {
// Internal, non-locking function to unpause a container
func (c *Container) unpause() error {
if c.config.NoCgroups {
return errors.Wrapf(define.ErrNoCgroups, "cannot unpause without using CGroups")
return errors.Wrapf(define.ErrNoCgroups, "cannot unpause without using Cgroups")
}

if err := c.ociRuntime.UnpauseContainer(c); err != nil {
Expand Down
4 changes: 2 additions & 2 deletions libpod/container_internal_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -2772,7 +2772,7 @@ func (c *Container) getOCICgroupPath() (string, error) {
// expects cgroups to be passed as follows:
// slice:prefix:name
systemdCgroups := fmt.Sprintf("%s:libpod:%s", path.Base(c.config.CgroupParent), c.ID())
logrus.Debugf("Setting CGroups for container %s to %s", c.ID(), systemdCgroups)
logrus.Debugf("Setting Cgroups for container %s to %s", c.ID(), systemdCgroups)
return systemdCgroups, nil
case (rootless.IsRootless() && (cgroupManager == config.CgroupfsCgroupsManager || !unified)):
if c.config.CgroupParent == "" || !isRootlessCgroupSet(c.config.CgroupParent) {
Expand All @@ -2781,7 +2781,7 @@ func (c *Container) getOCICgroupPath() (string, error) {
fallthrough
case cgroupManager == config.CgroupfsCgroupsManager:
cgroupPath := filepath.Join(c.config.CgroupParent, fmt.Sprintf("libpod-%s", c.ID()))
logrus.Debugf("Setting CGroup path for container %s to %s", c.ID(), cgroupPath)
logrus.Debugf("Setting Cgroup path for container %s to %s", c.ID(), cgroupPath)
return cgroupPath, nil
default:
return "", errors.Wrapf(define.ErrInvalidArg, "invalid cgroup manager %s requested", cgroupManager)
Expand Down
4 changes: 2 additions & 2 deletions libpod/container_validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,13 @@ func (c *Container) validate() error {
if ns.Type == spec.PIDNamespace {
foundPid = true
if ns.Path != "" {
return errors.Wrapf(define.ErrInvalidArg, "containers not creating CGroups must create a private PID namespace - cannot use another")
return errors.Wrapf(define.ErrInvalidArg, "containers not creating Cgroups must create a private PID namespace - cannot use another")
}
break
}
}
if !foundPid {
return errors.Wrapf(define.ErrInvalidArg, "containers not creating CGroups must create a private PID namespace")
return errors.Wrapf(define.ErrInvalidArg, "containers not creating Cgroups must create a private PID namespace")
}
}

Expand Down
12 changes: 6 additions & 6 deletions libpod/define/container_inspect.go
Original file line number Diff line number Diff line change
Expand Up @@ -345,9 +345,9 @@ type InspectContainerHostConfig struct {
// populated.
// TODO.
Cgroup string `json:"Cgroup"`
// Cgroups contains the container's CGroup mode.
// Allowed values are "default" (container is creating CGroups) and
// "disabled" (container is not creating CGroups).
// Cgroups contains the container's Cgroup mode.
// Allowed values are "default" (container is creating Cgroups) and
// "disabled" (container is not creating Cgroups).
// This is Libpod-specific and not included in `docker inspect`.
Cgroups string `json:"Cgroups"`
// Links is unused, and provided purely for Docker compatibility.
Expand Down Expand Up @@ -417,7 +417,7 @@ type InspectContainerHostConfig struct {
Isolation string `json:"Isolation"`
// CpuShares indicates the CPU resources allocated to the container.
// It is a relative weight in the scheduler for assigning CPU time
// versus other CGroups.
// versus other Cgroups.
CpuShares uint64 `json:"CpuShares"`
// Memory indicates the memory resources allocated to the container.
// This is the limit (in bytes) of RAM the container may use.
Expand All @@ -434,12 +434,12 @@ type InspectContainerHostConfig struct {
// 100000, we will set both CpuQuota, CpuPeriod, and NanoCpus. If
// CpuQuota is not the default, we will not set NanoCpus.
NanoCpus int64 `json:"NanoCpus"`
// CgroupParent is the CGroup parent of the container.
// CgroupParent is the Cgroup parent of the container.
// Only set if not default.
CgroupParent string `json:"CgroupParent"`
// BlkioWeight indicates the I/O resources allocated to the container.
// It is a relative weight in the scheduler for assigning I/O time
// versus other CGroups.
// versus other Cgroups.
BlkioWeight uint16 `json:"BlkioWeight"`
// BlkioWeightDevice is an array of I/O resource priorities for
// individual device nodes.
Expand Down
2 changes: 1 addition & 1 deletion libpod/define/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ var (
ErrWillDeadlock = errors.New("deadlock due to lock mismatch")

// ErrNoCgroups indicates that the container does not have its own
// CGroup.
// Cgroup.
ErrNoCgroups = errors.New("this container does not have a cgroup")
// ErrNoLogs indicates that this container is not creating a log so log
// operations cannot be performed on it
Expand Down
2 changes: 1 addition & 1 deletion libpod/define/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ type HostInfo struct {
Arch string `json:"arch"`
BuildahVersion string `json:"buildahVersion"`
CgroupManager string `json:"cgroupManager"`
CGroupsVersion string `json:"cgroupVersion"`
CgroupsVersion string `json:"cgroupVersion"`
CgroupControllers []string `json:"cgroupControllers"`
Conmon *ConmonInfo `json:"conmon"`
CPUs int `json:"cpus"`
Expand Down
6 changes: 3 additions & 3 deletions libpod/define/pod_inspect.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ type InspectPodData struct {
// Labels is a set of key-value labels that have been applied to the
// pod.
Labels map[string]string `json:"Labels,omitempty"`
// CreateCgroup is whether this pod will create its own CGroup to group
// CreateCgroup is whether this pod will create its own Cgroup to group
// containers under.
CreateCgroup bool
// CgroupParent is the parent of the pod's CGroup.
// CgroupParent is the parent of the pod's Cgroup.
CgroupParent string `json:"CgroupParent,omitempty"`
// CgroupPath is the path to the pod's CGroup.
// CgroupPath is the path to the pod's Cgroup.
CgroupPath string `json:"CgroupPath,omitempty"`
// CreateInfra is whether this pod will create an infra container to
// share namespaces.
Expand Down
4 changes: 2 additions & 2 deletions libpod/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ func (r *Runtime) hostInfo() (*define.HostInfo, error) {
return nil, errors.Wrapf(err, "error getting Seccomp profile path")
}

// CGroups version
// Cgroups version
unified, err := cgroups.IsCgroup2UnifiedMode()
if err != nil {
return nil, errors.Wrapf(err, "error reading cgroups mode")
Expand Down Expand Up @@ -150,7 +150,7 @@ func (r *Runtime) hostInfo() (*define.HostInfo, error) {
if unified {
cgroupVersion = "v2"
}
info.CGroupsVersion = cgroupVersion
info.CgroupsVersion = cgroupVersion

slirp4netnsPath := r.config.Engine.NetworkCmdPath
if slirp4netnsPath == "" {
Expand Down
2 changes: 1 addition & 1 deletion libpod/oci_conmon_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -1402,7 +1402,7 @@ func (r *ConmonOCIRuntime) sharedConmonArgs(ctr *Container, cuuid, bundlePath, p
args = append(args, "--log-tag", logTag)
}
if ctr.config.NoCgroups {
logrus.Debugf("Running with no CGroups")
logrus.Debugf("Running with no Cgroups")
args = append(args, "--runtime-arg", "--cgroup-manager", "--runtime-arg", "disabled")
}
return args
Expand Down
8 changes: 4 additions & 4 deletions libpod/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ func WithCgroupManager(manager string) RuntimeOption {
}

if manager != config.CgroupfsCgroupsManager && manager != config.SystemdCgroupsManager {
return errors.Wrapf(define.ErrInvalidArg, "CGroup manager must be one of %s and %s",
return errors.Wrapf(define.ErrInvalidArg, "Cgroup manager must be one of %s and %s",
config.CgroupfsCgroupsManager, config.SystemdCgroupsManager)
}

Expand Down Expand Up @@ -945,7 +945,7 @@ func WithUTSNSFrom(nsCtr *Container) CtrCreateOption {
}
}

// WithCgroupNSFrom indicates the the container should join the CGroup namespace
// WithCgroupNSFrom indicates the the container should join the Cgroup namespace
// of the given container.
// If the container has joined a pod, it can only join the namespaces of
// containers in the same pod.
Expand Down Expand Up @@ -1080,7 +1080,7 @@ func WithLogTag(tag string) CtrCreateOption {
}
}

// WithCgroupsMode disables the creation of CGroups for the conmon process.
// WithCgroupsMode disables the creation of Cgroups for the conmon process.
func WithCgroupsMode(mode string) CtrCreateOption {
return func(ctr *Container) error {
if ctr.valid {
Expand Down Expand Up @@ -1864,7 +1864,7 @@ func WithPodCgroupParent(path string) PodCreateOption {
// WithPodCgroups tells containers in this pod to use the cgroup created for
// this pod.
// This can still be overridden at the container level by explicitly specifying
// a CGroup parent.
// a Cgroup parent.
func WithPodCgroups() PodCreateOption {
return func(pod *Pod) error {
if pod.valid {
Expand Down
12 changes: 6 additions & 6 deletions libpod/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ type PodConfig struct {

// Labels contains labels applied to the pod
Labels map[string]string `json:"labels"`
// CgroupParent contains the pod's CGroup parent
// CgroupParent contains the pod's Cgroup parent
CgroupParent string `json:"cgroupParent"`
// UsePodCgroup indicates whether the pod will create its own CGroup and
// UsePodCgroup indicates whether the pod will create its own Cgroup and
// join containers to it.
// If true, all containers joined to the pod will use the pod cgroup as
// their cgroup parent, and cannot set a different cgroup parent
Expand Down Expand Up @@ -77,7 +77,7 @@ type PodConfig struct {

// podState represents a pod's state
type podState struct {
// CgroupPath is the path to the pod's CGroup
// CgroupPath is the path to the pod's Cgroup
CgroupPath string `json:"cgroupPath"`
// InfraContainerID is the container that holds pod namespace information
// Most often an infra container
Expand Down Expand Up @@ -237,7 +237,7 @@ func (p *Pod) CreateCommand() []string {
return p.config.CreateCommand
}

// CgroupParent returns the pod's CGroup parent
// CgroupParent returns the pod's Cgroup parent
func (p *Pod) CgroupParent() string {
return p.config.CgroupParent
}
Expand Down Expand Up @@ -289,7 +289,7 @@ func (p *Pod) Hostname() string {
return p.config.Hostname
}

// CgroupPath returns the path to the pod's CGroup
// CgroupPath returns the path to the pod's Cgroup
func (p *Pod) CgroupPath() (string, error) {
p.lock.Lock()
defer p.lock.Unlock()
Expand All @@ -315,7 +315,7 @@ func (p *Pod) CgroupPath() (string, error) {
}
if ctr != nil {
ctr.Start(context.Background(), true)
cgroupPath, err := ctr.CGroupPath()
cgroupPath, err := ctr.CgroupPath()
fmt.Println(cgroupPath)
if err != nil {
return "", errors.Wrapf(err, "could not get container cgroup")
Expand Down
2 changes: 1 addition & 1 deletion libpod/pod_internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func (p *Pod) refresh() error {
case config.SystemdCgroupsManager:
cgroupPath, err := systemdSliceFromPath(p.config.CgroupParent, fmt.Sprintf("libpod_pod_%s", p.ID()))
if err != nil {
logrus.Errorf("Creating CGroup for pod %s: %v", p.ID(), err)
logrus.Errorf("Creating Cgroup for pod %s: %v", p.ID(), err)
}
p.state.CgroupPath = cgroupPath
case config.CgroupfsCgroupsManager:
Expand Down
Loading

0 comments on commit 8514ebd

Please sign in to comment.