diff options
author | OpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com> | 2019-09-21 20:19:48 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-09-21 20:19:48 +0200 |
commit | 0d95e3aa06baf0613addc69b3d01bb7c262abd34 (patch) | |
tree | b313c8ede7893d1427e3520d8e8b8057275a773e /libpod | |
parent | e947d6354d9e154b07c34728abf3c2399b993131 (diff) | |
parent | e4e42e67e35189ab3a10cf1457e409198c618257 (diff) | |
download | podman-0d95e3aa06baf0613addc69b3d01bb7c262abd34.tar.gz podman-0d95e3aa06baf0613addc69b3d01bb7c262abd34.tar.bz2 podman-0d95e3aa06baf0613addc69b3d01bb7c262abd34.zip |
Merge pull request #4029 from rhatdan/cgroup
We need to convert libpod.conf files in user homedir for cgroupv2
Diffstat (limited to 'libpod')
-rw-r--r-- | libpod/runtime.go | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/libpod/runtime.go b/libpod/runtime.go index e2b9667be..675c92b7a 100644 --- a/libpod/runtime.go +++ b/libpod/runtime.go @@ -23,6 +23,7 @@ import ( "github.com/containers/libpod/libpod/events" "github.com/containers/libpod/libpod/image" "github.com/containers/libpod/libpod/lock" + "github.com/containers/libpod/pkg/cgroups" sysreg "github.com/containers/libpod/pkg/registries" "github.com/containers/libpod/pkg/rootless" "github.com/containers/libpod/pkg/util" @@ -254,6 +255,8 @@ type RuntimeConfig struct { // SDNotify tells Libpod to allow containers to notify the host // systemd of readiness using the SD_NOTIFY mechanism SDNotify bool + // CgroupCheck verifies if the cgroup check for correct OCI runtime has been done. + CgroupCheck bool `toml:"cgroup_check,omitempty"` } // runtimeConfiguredFrom is a struct used during early runtime init to help @@ -575,6 +578,10 @@ func newRuntimeFromConfig(ctx context.Context, userConfigPath string, options .. configPath) } + if err := cgroupV2Check(configPath, tmpConfig); err != nil { + return nil, err + } + if tmpConfig.StaticDir != "" { runtime.configuredFrom.libpodStaticDirSet = true } @@ -664,6 +671,14 @@ func newRuntimeFromConfig(ctx context.Context, userConfigPath string, options .. runtime.config.OCIRuntime = tmpConfig.OCIRuntime } + cgroupsV2, err := cgroups.IsCgroup2UnifiedMode() + if err != nil { + return nil, err + } + if cgroupsV2 { + runtime.config.CgroupCheck = true + } + break } } @@ -1451,3 +1466,37 @@ func (r *Runtime) ImageRuntime() *image.Runtime { func (r *Runtime) SystemContext() *types.SystemContext { return r.imageContext } + +// Since runc does not currently support cgroupV2 +// Change to default crun on first running of libpod.conf +// TODO Once runc has support for cgroups, this function should be removed. +func cgroupV2Check(configPath string, tmpConfig *RuntimeConfig) error { + if !tmpConfig.CgroupCheck && rootless.IsRootless() { + cgroupsV2, err := cgroups.IsCgroup2UnifiedMode() + if err != nil { + return err + } + if cgroupsV2 { + path, err := exec.LookPath("crun") + if err != nil { + logrus.Warnf("Can not find crun package on the host, containers might fail to run on cgroup V2 systems without crun: %q", err) + // Can't find crun path so do nothing + return nil + } + tmpConfig.CgroupCheck = true + tmpConfig.OCIRuntime = path + file, err := os.OpenFile(configPath, os.O_RDWR|os.O_CREATE, 0666) + if err != nil { + return errors.Wrapf(err, "cannot open file %s", configPath) + } + defer file.Close() + enc := toml.NewEncoder(file) + if err := enc.Encode(tmpConfig); err != nil { + if removeErr := os.Remove(configPath); removeErr != nil { + logrus.Debugf("unable to remove %s: %q", configPath, err) + } + } + } + } + return nil +} |