Add support for adjusting OOM score adjustment.
The OomScoreAdj field is added to the LinuxContainerAdjustment structure of the NRI plugin. This field records the value of oom_score_adj that needs to be adjusted during CreateContainer. Added the appropriate set method and the method to write back to the NRI response. Fix #92
TEST METHOD: We build a NRI plugin with CreateContainer function like this:
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())
//
// This is the container creation request handler. Because the container
// has not been created yet, this is the lifecycle event which allows you
// the largest set of changes to the container's configuration, including
// some of the later immautable parameters. Take a look at the adjustment
// functions in pkg/api/adjustment.go to see the available controls.
//
// In addition to reconfiguring the container being created, you are also
// allowed to update other existing containers. Take a look at the update
// functions in pkg/api/update.go to see the available controls.
//
adjustment := &api.ContainerAdjustment{}
adjustment.SetLinuxOomScoreAdj(121)
log.Infof("set oom score: %v", 121)
return adjustment, nil, nil
}
Then run this NRI plugin with containerd. Create a k8s pod of apache.
[root@master bin]# kubectl get po -A |grep apache
kube-system apache-66f99dd558-c9bgm 1/1 Running 0 4h5m
Run the docker inspect command to query the process ID of the Apache container is 3445531.
At last, query the oom_score_adj of this pid. It has been set to 121 successfully.
[root@master bin]# cat /proc/3445531/oom_score_adj
121
Thank's for the PR @zxj874478410 ! I have a few nits, but otherwise it looks good to me.
Thanks for the review @klihub . I've fixed these faults.
@klihub @mikebrow Just rebased code and fixed conflicts, please take a look, thanks.
LGTM
@klihub @mikebrow Sorry for conflict again. Just fixed conflicts, please take a look, thanks.
@zxj874478410 This fix is not sufficient in it's current form as it breaks replacing a mount with another one to the same destination. I think we'd need a bit of additional code to prevent that from happening. Maybe something like this, where 8f509e7d0f2e4e9af7f7acb77e9c18f2e882efaf is an updated version of your commit, and 7ea0a47f00f853b4e970b980b1a24b082c0930f0 adds a new test case for mount removal.
@zxj874478410 This fix is not sufficient in it's current form as it breaks replacing a mount with another one to the same destination. I think we'd need a bit of additional code to prevent that from happening. Maybe something like this, where 8f509e7 is an updated version of your commit, and 7ea0a47 adds a new test case for mount removal.
Thanks for the detailed instructions, but does this problem refer to another pr #87 ? This one refers to OOM score adjustment.
@zxj874478410 This fix is not sufficient in it's current form as it breaks replacing a mount with another one to the same destination. I think we'd need a bit of additional code to prevent that from happening. Maybe something like this, where 8f509e7 is an updated version of your commit, and 7ea0a47 adds a new test case for mount removal.
Thanks for the detailed instructions, but does this problem refer to another pr #87 ? This one refers to OOM score adjustment.
Argh... Sorry about that. Yes, you are absolutely right, it is about PR #87. Time to renew my glasses or get a brain transplant...
这是来自QQ邮箱的假期自动回复邮件。 您好,我最近正在休假中,无法亲自回复您的邮件。我将在假期结束后,尽快给您回复。