mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-30 15:05:27 +00:00
CPU Manager - Add check to policy.Allocate() for init conatiners
If container allocated CPUs is an init container, release those CPUs back into the shared pool for re-allocation to next container.
This commit is contained in:
parent
709989efa2
commit
467f66580b
@ -215,22 +215,6 @@ func (m *manager) Allocate(p *v1.Pod, c *v1.Container) error {
|
||||
m.Lock()
|
||||
defer m.Unlock()
|
||||
|
||||
// TODO: Reuse CPUs allocated to init containers to mimic functionality
|
||||
// from previous implementation below. Logic should probably be pushed into
|
||||
// the policy now instead of doing it at this level.
|
||||
|
||||
//// Proactively remove CPUs from init containers that have already run.
|
||||
//// They are guaranteed to have run to completion before any other
|
||||
//// container is run.
|
||||
//for _, initContainer := range p.Spec.InitContainers {
|
||||
// if c.Name != initContainer.Name {
|
||||
// err := m.policyRemoveContainerByRef(string(p.UID), initContainer.Name)
|
||||
// if err != nil {
|
||||
// klog.Warningf("[cpumanager] unable to remove init container (pod: %s, container: %s, error: %v)", string(p.UID), initContainer.Name, err)
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
|
||||
// Call down into the policy to assign this container CPUs if required.
|
||||
err := m.policy.Allocate(m.state, p, c)
|
||||
if err != nil {
|
||||
|
@ -209,6 +209,17 @@ func (p *staticPolicy) Allocate(s state.State, pod *v1.Pod, container *v1.Contai
|
||||
return err
|
||||
}
|
||||
s.SetCPUSet(string(pod.UID), container.Name, cpuset)
|
||||
|
||||
// Check if the container that has just been allocated resources is an init container.
|
||||
// If so, release its CPUs back into the shared pool so they can be reallocated.
|
||||
for _, initContainer := range pod.Spec.InitContainers {
|
||||
if container.Name == initContainer.Name {
|
||||
if toRelease, ok := s.GetCPUSet(string(pod.UID), container.Name); ok {
|
||||
// Mutate the shared pool, adding released cpus.
|
||||
s.SetDefaultCPUSet(s.GetDefaultCPUSet().Union(toRelease))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// container belongs in the shared pool (nothing to do; use default cpuset)
|
||||
return nil
|
||||
|
Loading…
Reference in New Issue
Block a user