|
@@ -8,10 +8,12 @@ import (
|
|
|
)
|
|
|
|
|
|
// ToRootless converts spec to be compatible with "rootless" runc.
|
|
|
-// * Remove cgroups (will be supported in separate PR when delegation permission is configured)
|
|
|
+// * Remove non-supported cgroups
|
|
|
// * Fix up OOMScoreAdj
|
|
|
-func ToRootless(spec *specs.Spec) error {
|
|
|
- return toRootless(spec, getCurrentOOMScoreAdj())
|
|
|
+//
|
|
|
+// v2Controllers should be non-nil only if running with v2 and systemd.
|
|
|
+func ToRootless(spec *specs.Spec, v2Controllers []string) error {
|
|
|
+ return toRootless(spec, v2Controllers, getCurrentOOMScoreAdj())
|
|
|
}
|
|
|
|
|
|
func getCurrentOOMScoreAdj() int {
|
|
@@ -26,10 +28,44 @@ func getCurrentOOMScoreAdj() int {
|
|
|
return i
|
|
|
}
|
|
|
|
|
|
-func toRootless(spec *specs.Spec, currentOOMScoreAdj int) error {
|
|
|
- // Remove cgroup settings.
|
|
|
- spec.Linux.Resources = nil
|
|
|
- spec.Linux.CgroupsPath = ""
|
|
|
+func toRootless(spec *specs.Spec, v2Controllers []string, currentOOMScoreAdj int) error {
|
|
|
+ if len(v2Controllers) == 0 {
|
|
|
+ // Remove cgroup settings.
|
|
|
+ spec.Linux.Resources = nil
|
|
|
+ spec.Linux.CgroupsPath = ""
|
|
|
+ } else {
|
|
|
+ if spec.Linux.Resources != nil {
|
|
|
+ m := make(map[string]struct{})
|
|
|
+ for _, s := range v2Controllers {
|
|
|
+ m[s] = struct{}{}
|
|
|
+ }
|
|
|
+ // Remove devices: https://github.com/containers/crun/issues/255
|
|
|
+ spec.Linux.Resources.Devices = nil
|
|
|
+ if _, ok := m["memory"]; !ok {
|
|
|
+ spec.Linux.Resources.Memory = nil
|
|
|
+ }
|
|
|
+ if _, ok := m["cpu"]; !ok {
|
|
|
+ spec.Linux.Resources.CPU = nil
|
|
|
+ }
|
|
|
+ if _, ok := m["cpuset"]; !ok {
|
|
|
+ if spec.Linux.Resources.CPU != nil {
|
|
|
+ spec.Linux.Resources.CPU.Cpus = ""
|
|
|
+ spec.Linux.Resources.CPU.Mems = ""
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if _, ok := m["pids"]; !ok {
|
|
|
+ spec.Linux.Resources.Pids = nil
|
|
|
+ }
|
|
|
+ if _, ok := m["io"]; !ok {
|
|
|
+ spec.Linux.Resources.BlockIO = nil
|
|
|
+ }
|
|
|
+ if _, ok := m["rdma"]; !ok {
|
|
|
+ spec.Linux.Resources.Rdma = nil
|
|
|
+ }
|
|
|
+ spec.Linux.Resources.HugepageLimits = nil
|
|
|
+ spec.Linux.Resources.Network = nil
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
if spec.Process.OOMScoreAdj != nil && *spec.Process.OOMScoreAdj < currentOOMScoreAdj {
|
|
|
*spec.Process.OOMScoreAdj = currentOOMScoreAdj
|