containerd / cgroups

cgroups package for Go

Home Page:https://containerd.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

The container cgroup path of pod is not loaded properly

ErikJiang opened this issue Β· comments

commented

πŸ™ I need some guidance on this.

I am trying to write an NRI plugin and want to use cgroup1.Load() to load the existing container cgroup paths. Still, I found that I can only load the parent path of the Pod, and loading specific container paths within the Pod will report an error that the cgroup is deleted, I would like to know why this is. Is it possible that I'm not using it in the right way?

func (p *plugin) CreateContainer(_ context.Context, pod *api.PodSandbox, ctr *api.Container) (*api.ContainerAdjustment, []*api.ContainerUpdate, error) {
	log.Infof("Creating container %s/%s/%s...", pod.GetNamespace(), pod.GetName(), ctr.GetName())

	adjustment := &api.ContainerAdjustment{}
	updates := []*api.ContainerUpdate{}
        ...
        // 1. It is possible to directly load the pod parent cgroup path
        control, err := cgroup1.Load(cgroup1.StaticPath(pod.Linux.CgroupParent))

        // 2. If the container cgroup path in the pod is loaded, execution will report: "cgroups: cgroup deleted"
	cgroupPath := fmt.Sprintf("%s/cri-containerd-%s.scope", pod.Linux.CgroupParent, ctr.Id)
        control, err := cgroup1.Load(cgroup1.StaticPath(cgroupPath))

         ...
	return adjustment, updates, nil
}
commented

I see why, to load the container's cgroup path you have to do it in the StartContainer phase, loading it in the CreateContainer phase is too early, so it gives an error.