@@ -1357,6 +1357,38 @@ func containerAndPodFromLabels(inspect *docker.Container) (pod *api.Pod, contain
1357
1357
return
1358
1358
}
1359
1359
1360
+ func (dm * DockerManager ) applyOOMScoreAdj (container * api.Container , containerInfo * docker.Container ) error {
1361
+ cgroupName , err := dm .procFs .GetFullContainerName (containerInfo .State .Pid )
1362
+ if err != nil {
1363
+ if err == os .ErrNotExist {
1364
+ // Container exited. We cannot do anything about it. Ignore this error.
1365
+ glog .V (2 ).Infof ("Failed to apply OOM score adj on container %q with ID %q. Init process does not exist." , containerInfo .Name , containerInfo .ID )
1366
+ return nil
1367
+ }
1368
+ return err
1369
+ }
1370
+ // Set OOM score of the container based on the priority of the container.
1371
+ // Processes in lower-priority pods should be killed first if the system runs out of memory.
1372
+ // The main pod infrastructure container is considered high priority, since if it is killed the
1373
+ // whole pod will die.
1374
+ // TODO: Cache this value.
1375
+ var oomScoreAdj int
1376
+ if containerInfo .Name == PodInfraContainerName {
1377
+ oomScoreAdj = qos .PodInfraOOMAdj
1378
+ } else {
1379
+ oomScoreAdj = qos .GetContainerOOMScoreAdjust (container , int64 (dm .machineInfo .MemoryCapacity ))
1380
+ }
1381
+ if err = dm .oomAdjuster .ApplyOOMScoreAdjContainer (cgroupName , oomScoreAdj , 5 ); err != nil {
1382
+ if err == os .ErrNotExist {
1383
+ // Container exited. We cannot do anything about it. Ignore this error.
1384
+ glog .V (2 ).Infof ("Failed to apply OOM score adj on container %q with ID %q. Init process does not exist." , containerInfo .Name , containerInfo .ID )
1385
+ return nil
1386
+ }
1387
+ return err
1388
+ }
1389
+ return nil
1390
+ }
1391
+
1360
1392
// Run a single container from a pod. Returns the docker container ID
1361
1393
// If do not need to pass labels, just pass nil.
1362
1394
func (dm * DockerManager ) runContainerInPod (pod * api.Pod , container * api.Container , netMode , ipcMode , pidMode string , restartCount int ) (kubecontainer.ContainerID , error ) {
@@ -1418,24 +1450,9 @@ func (dm *DockerManager) runContainerInPod(pod *api.Pod, container *api.Containe
1418
1450
return kubecontainer.ContainerID {}, fmt .Errorf ("can't get init PID for container %q" , id )
1419
1451
}
1420
1452
1421
- // Set OOM score of the container based on the priority of the container.
1422
- // Processes in lower-priority pods should be killed first if the system runs out of memory.
1423
- // The main pod infrastructure container is considered high priority, since if it is killed the
1424
- // whole pod will die.
1425
- var oomScoreAdj int
1426
- if container .Name == PodInfraContainerName {
1427
- oomScoreAdj = qos .PodInfraOOMAdj
1428
- } else {
1429
- oomScoreAdj = qos .GetContainerOOMScoreAdjust (container , int64 (dm .machineInfo .MemoryCapacity ))
1430
- }
1431
- cgroupName , err := dm .procFs .GetFullContainerName (containerInfo .State .Pid )
1432
- if err != nil {
1433
- return kubecontainer.ContainerID {}, fmt .Errorf ("GetFullContainerName: %v" , err )
1434
- }
1435
- if err = dm .oomAdjuster .ApplyOOMScoreAdjContainer (cgroupName , oomScoreAdj , 5 ); err != nil {
1436
- return kubecontainer.ContainerID {}, fmt .Errorf ("ApplyOOMScoreAdjContainer: %v" , err )
1453
+ if err := dm .applyOOMScoreAdj (container , containerInfo ); err != nil {
1454
+ return kubecontainer.ContainerID {}, fmt .Errorf ("failed to apply oom-score-adj to container %q- %v" , err , containerInfo .Name )
1437
1455
}
1438
-
1439
1456
// The addNDotsOption call appends the ndots option to the resolv.conf file generated by docker.
1440
1457
// This resolv.conf file is shared by all containers of the same pod, and needs to be modified only once per pod.
1441
1458
// we modify it when the pause container is created since it is the first container created in the pod since it holds
0 commit comments