mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-22 19:31:44 +00:00
Return only isolated cpus in podresources interface
Co-Authored-by: Swati Sehgal <swsehgal@redhat.com> Signed-off-by: Alexey Perevalov <alexey.perevalov@huawei.com>
This commit is contained in:
parent
c4d802b0b5
commit
5d9032007a
@ -1064,7 +1064,7 @@ func (cm *containerManagerImpl) GetAllocatableDevices() []*podresourcesapi.Conta
|
||||
|
||||
func (cm *containerManagerImpl) GetCPUs(podUID, containerName string) []int64 {
|
||||
if cm.cpuManager != nil {
|
||||
return cm.cpuManager.GetCPUs(podUID, containerName).ToSliceNoSortInt64()
|
||||
return cm.cpuManager.GetExclusiveCPUs(podUID, containerName).ToSliceNoSortInt64()
|
||||
}
|
||||
return []int64{}
|
||||
}
|
||||
|
@ -77,9 +77,9 @@ type Manager interface {
|
||||
// and other resource controllers.
|
||||
GetTopologyHints(*v1.Pod, *v1.Container) map[string][]topologymanager.TopologyHint
|
||||
|
||||
// GetCPUs implements the podresources.CPUsProvider interface to provide allocated
|
||||
// cpus for the container
|
||||
GetCPUs(podUID, containerName string) cpuset.CPUSet
|
||||
// GetExclusiveCPUs implements the podresources.CPUsProvider interface to provide
|
||||
// exclusively allocated cpus for the container
|
||||
GetExclusiveCPUs(podUID, containerName string) cpuset.CPUSet
|
||||
|
||||
// GetPodTopologyHints implements the topologymanager.HintProvider Interface
|
||||
// and is consulted to achieve NUMA aware resource alignment per Pod
|
||||
@ -88,6 +88,10 @@ type Manager interface {
|
||||
|
||||
// GetAllocatableCPUs returns the assignable (not allocated) CPUs
|
||||
GetAllocatableCPUs() cpuset.CPUSet
|
||||
|
||||
// GetCPUAffinity returns cpuset which includes cpus from shared pools
|
||||
// as well as exclusively allocated cpus
|
||||
GetCPUAffinity(podUID, containerName string) cpuset.CPUSet
|
||||
}
|
||||
|
||||
type manager struct {
|
||||
@ -506,7 +510,15 @@ func (m *manager) updateContainerCPUSet(containerID string, cpus cpuset.CPUSet)
|
||||
})
|
||||
}
|
||||
|
||||
func (m *manager) GetCPUs(podUID, containerName string) cpuset.CPUSet {
|
||||
func (m *manager) GetExclusiveCPUs(podUID, containerName string) cpuset.CPUSet {
|
||||
if result, ok := m.state.GetCPUSet(string(podUID), containerName); ok {
|
||||
return result
|
||||
}
|
||||
|
||||
return cpuset.CPUSet{}
|
||||
}
|
||||
|
||||
func (m *manager) GetCPUAffinity(podUID, containerName string) cpuset.CPUSet {
|
||||
return m.state.GetCPUSetOrDefault(podUID, containerName)
|
||||
}
|
||||
|
||||
|
@ -70,8 +70,8 @@ func (m *fakeManager) State() state.Reader {
|
||||
return m.state
|
||||
}
|
||||
|
||||
func (m *fakeManager) GetCPUs(podUID, containerName string) cpuset.CPUSet {
|
||||
klog.InfoS("GetCPUs", "podUID", podUID, "containerName", containerName)
|
||||
func (m *fakeManager) GetExclusiveCPUs(podUID, containerName string) cpuset.CPUSet {
|
||||
klog.InfoS("GetExclusiveCPUs", "podUID", podUID, "containerName", containerName)
|
||||
return cpuset.CPUSet{}
|
||||
}
|
||||
|
||||
@ -80,6 +80,11 @@ func (m *fakeManager) GetAllocatableCPUs() cpuset.CPUSet {
|
||||
return cpuset.CPUSet{}
|
||||
}
|
||||
|
||||
func (m *fakeManager) GetCPUAffinity(podUID, containerName string) cpuset.CPUSet {
|
||||
klog.InfoS("GetCPUAffinity", "podUID", podUID, "containerName", containerName)
|
||||
return cpuset.CPUSet{}
|
||||
}
|
||||
|
||||
// NewFakeManager creates empty/fake cpu manager
|
||||
func NewFakeManager() Manager {
|
||||
return &fakeManager{
|
||||
|
@ -29,7 +29,7 @@ import (
|
||||
|
||||
func (i *internalContainerLifecycleImpl) PreCreateContainer(pod *v1.Pod, container *v1.Container, containerConfig *runtimeapi.ContainerConfig) error {
|
||||
if i.cpuManager != nil {
|
||||
allocatedCPUs := i.cpuManager.GetCPUs(string(pod.UID), container.Name)
|
||||
allocatedCPUs := i.cpuManager.GetCPUAffinity(string(pod.UID), container.Name)
|
||||
if !allocatedCPUs.IsEmpty() {
|
||||
containerConfig.Linux.Resources.CpusetCpus = allocatedCPUs.String()
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user