node: podresources: translate types in cm

during the review, we convened that the manager types
(CPUSet, ResourceDeviceInstances) should not cross the
containermanager API boundary; thus, the ContainerManager layer
is the correct place to do the type conversion

We push back the type conversions from the podresources server
layer, fixing tests accordingly.

Signed-off-by: Francesco Romani <fromani@redhat.com>
This commit is contained in:
Francesco Romani 2021-03-07 19:55:16 +01:00
parent ad68f9588c
commit 8afdf4f146
10 changed files with 136 additions and 166 deletions

View File

@ -19,7 +19,6 @@ package podresources
import ( import (
"context" "context"
"k8s.io/kubernetes/pkg/kubelet/cm/devicemanager"
"k8s.io/kubernetes/pkg/kubelet/metrics" "k8s.io/kubernetes/pkg/kubelet/metrics"
"k8s.io/kubelet/pkg/apis/podresources/v1" "k8s.io/kubelet/pkg/apis/podresources/v1"
@ -60,8 +59,8 @@ func (p *v1PodResourcesServer) List(ctx context.Context, req *v1.ListPodResource
for j, container := range pod.Spec.Containers { for j, container := range pod.Spec.Containers {
pRes.Containers[j] = &v1.ContainerResources{ pRes.Containers[j] = &v1.ContainerResources{
Name: container.Name, Name: container.Name,
Devices: containerDevicesFromResourceDeviceInstances(p.devicesProvider.GetDevices(string(pod.UID), container.Name)), Devices: p.devicesProvider.GetDevices(string(pod.UID), container.Name),
CpuIds: p.cpusProvider.GetCPUs(string(pod.UID), container.Name).ToSliceNoSortInt64(), CpuIds: p.cpusProvider.GetCPUs(string(pod.UID), container.Name),
} }
} }
podResources[i] = &pRes podResources[i] = &pRes
@ -77,32 +76,7 @@ func (p *v1PodResourcesServer) GetAllocatableResources(ctx context.Context, req
metrics.PodResourcesEndpointRequestsTotalCount.WithLabelValues("v1").Inc() metrics.PodResourcesEndpointRequestsTotalCount.WithLabelValues("v1").Inc()
return &v1.AllocatableResourcesResponse{ return &v1.AllocatableResourcesResponse{
Devices: containerDevicesFromResourceDeviceInstances(p.devicesProvider.GetAllocatableDevices()), Devices: p.devicesProvider.GetAllocatableDevices(),
CpuIds: p.cpusProvider.GetAllocatableCPUs().ToSliceNoSortInt64(), CpuIds: p.cpusProvider.GetAllocatableCPUs(),
}, nil }, nil
} }
func containerDevicesFromResourceDeviceInstances(devs devicemanager.ResourceDeviceInstances) []*v1.ContainerDevices {
var respDevs []*v1.ContainerDevices
for resourceName, resourceDevs := range devs {
for devID, dev := range resourceDevs {
for _, node := range dev.GetTopology().GetNodes() {
numaNode := node.GetID()
respDevs = append(respDevs, &v1.ContainerDevices{
ResourceName: resourceName,
DeviceIds: []string{devID},
Topology: &v1.TopologyInfo{
Nodes: []*v1.NUMANode{
{
ID: numaNode,
},
},
},
})
}
}
}
return respDevs
}

View File

@ -25,7 +25,6 @@ import (
"k8s.io/api/core/v1" "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types" "k8s.io/apimachinery/pkg/types"
pluginapi "k8s.io/kubelet/pkg/apis/deviceplugin/v1beta1"
podresourcesapi "k8s.io/kubelet/pkg/apis/podresources/v1" podresourcesapi "k8s.io/kubelet/pkg/apis/podresources/v1"
"k8s.io/kubernetes/pkg/kubelet/cm/cpuset" "k8s.io/kubernetes/pkg/kubelet/cm/cpuset"
"k8s.io/kubernetes/pkg/kubelet/cm/devicemanager" "k8s.io/kubernetes/pkg/kubelet/cm/devicemanager"
@ -38,35 +37,28 @@ func TestListPodResourcesV1(t *testing.T) {
containerName := "container-name" containerName := "container-name"
numaID := int64(1) numaID := int64(1)
devs := devicemanager.ResourceDeviceInstances{ devs := []*podresourcesapi.ContainerDevices{
"resource": devicemanager.DeviceInstances{ {
"dev0": pluginapi.Device{ ResourceName: "resource",
Topology: &pluginapi.TopologyInfo{ DeviceIds: []string{"dev0", "dev1"},
Nodes: []*pluginapi.NUMANode{{ID: numaID}}, Topology: &podresourcesapi.TopologyInfo{Nodes: []*podresourcesapi.NUMANode{{ID: numaID}}},
},
},
"dev1": pluginapi.Device{
Topology: &pluginapi.TopologyInfo{
Nodes: []*pluginapi.NUMANode{{ID: numaID}},
},
},
}, },
} }
cpus := cpuset.NewCPUSet(12, 23, 30) cpus := []int64{12, 23, 30}
for _, tc := range []struct { for _, tc := range []struct {
desc string desc string
pods []*v1.Pod pods []*v1.Pod
devices devicemanager.ResourceDeviceInstances devices []*podresourcesapi.ContainerDevices
cpus cpuset.CPUSet cpus []int64
expectedResponse *podresourcesapi.ListPodResourcesResponse expectedResponse *podresourcesapi.ListPodResourcesResponse
}{ }{
{ {
desc: "no pods", desc: "no pods",
pods: []*v1.Pod{}, pods: []*v1.Pod{},
devices: devicemanager.NewResourceDeviceInstances(), devices: []*podresourcesapi.ContainerDevices{},
cpus: cpuset.CPUSet{}, cpus: []int64{},
expectedResponse: &podresourcesapi.ListPodResourcesResponse{}, expectedResponse: &podresourcesapi.ListPodResourcesResponse{},
}, },
{ {
@ -87,8 +79,8 @@ func TestListPodResourcesV1(t *testing.T) {
}, },
}, },
}, },
devices: devicemanager.NewResourceDeviceInstances(), devices: []*podresourcesapi.ContainerDevices{},
cpus: cpuset.CPUSet{}, cpus: []int64{},
expectedResponse: &podresourcesapi.ListPodResourcesResponse{ expectedResponse: &podresourcesapi.ListPodResourcesResponse{
PodResources: []*podresourcesapi.PodResources{ PodResources: []*podresourcesapi.PodResources{
{ {
@ -132,8 +124,8 @@ func TestListPodResourcesV1(t *testing.T) {
Containers: []*podresourcesapi.ContainerResources{ Containers: []*podresourcesapi.ContainerResources{
{ {
Name: containerName, Name: containerName,
Devices: containerDevicesFromResourceDeviceInstances(devs), Devices: devs,
CpuIds: cpus.ToSliceNoSortInt64(), CpuIds: cpus,
}, },
}, },
}, },
@ -162,52 +154,51 @@ func TestListPodResourcesV1(t *testing.T) {
} }
func TestAllocatableResources(t *testing.T) { func TestAllocatableResources(t *testing.T) {
allDevs := devicemanager.ResourceDeviceInstances{ allDevs := []*podresourcesapi.ContainerDevices{
"resource": { {
"dev0": { ResourceName: "resource",
ID: "GPU-fef8089b-4820-abfc-e83e-94318197576e", DeviceIds: []string{"dev0"},
Health: "Healthy", Topology: &podresourcesapi.TopologyInfo{
Topology: &pluginapi.TopologyInfo{ Nodes: []*podresourcesapi.NUMANode{
Nodes: []*pluginapi.NUMANode{
{ {
ID: 0, ID: 0,
}, },
}, },
}, },
}, },
"dev1": { {
ID: "VF-8536e1e8-9dc6-4645-9aea-882db92e31e7", ResourceName: "resource",
Health: "Healthy", DeviceIds: []string{"dev1"},
Topology: &pluginapi.TopologyInfo{ Topology: &podresourcesapi.TopologyInfo{
Nodes: []*pluginapi.NUMANode{ Nodes: []*podresourcesapi.NUMANode{
{ {
ID: 1, ID: 1,
}, },
}, },
}, },
}, },
},
} }
allCPUs := cpuset.NewCPUSet(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16)
allCPUs := []int64{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}
for _, tc := range []struct { for _, tc := range []struct {
desc string desc string
allCPUs cpuset.CPUSet allCPUs []int64
allDevices devicemanager.ResourceDeviceInstances allDevices []*podresourcesapi.ContainerDevices
expectedAllocatableResourcesResponse *podresourcesapi.AllocatableResourcesResponse expectedAllocatableResourcesResponse *podresourcesapi.AllocatableResourcesResponse
}{ }{
{ {
desc: "no devices, no CPUs", desc: "no devices, no CPUs",
allCPUs: cpuset.CPUSet{}, allCPUs: []int64{},
allDevices: devicemanager.NewResourceDeviceInstances(), allDevices: []*podresourcesapi.ContainerDevices{},
expectedAllocatableResourcesResponse: &podresourcesapi.AllocatableResourcesResponse{}, expectedAllocatableResourcesResponse: &podresourcesapi.AllocatableResourcesResponse{},
}, },
{ {
desc: "no devices, all CPUs", desc: "no devices, all CPUs",
allCPUs: allCPUs, allCPUs: allCPUs,
allDevices: devicemanager.NewResourceDeviceInstances(), allDevices: []*podresourcesapi.ContainerDevices{},
expectedAllocatableResourcesResponse: &podresourcesapi.AllocatableResourcesResponse{ expectedAllocatableResourcesResponse: &podresourcesapi.AllocatableResourcesResponse{
CpuIds: allCPUs.ToSliceNoSortInt64(), CpuIds: allCPUs,
}, },
}, },
{ {
@ -215,7 +206,7 @@ func TestAllocatableResources(t *testing.T) {
allCPUs: allCPUs, allCPUs: allCPUs,
allDevices: allDevs, allDevices: allDevs,
expectedAllocatableResourcesResponse: &podresourcesapi.AllocatableResourcesResponse{ expectedAllocatableResourcesResponse: &podresourcesapi.AllocatableResourcesResponse{
CpuIds: allCPUs.ToSliceNoSortInt64(), CpuIds: allCPUs,
Devices: []*podresourcesapi.ContainerDevices{ Devices: []*podresourcesapi.ContainerDevices{
{ {
ResourceName: "resource", ResourceName: "resource",
@ -244,7 +235,7 @@ func TestAllocatableResources(t *testing.T) {
}, },
{ {
desc: "with devices, no CPUs", desc: "with devices, no CPUs",
allCPUs: cpuset.CPUSet{}, allCPUs: []int64{},
allDevices: allDevs, allDevices: allDevs,
expectedAllocatableResourcesResponse: &podresourcesapi.AllocatableResourcesResponse{ expectedAllocatableResourcesResponse: &podresourcesapi.AllocatableResourcesResponse{
Devices: []*podresourcesapi.ContainerDevices{ Devices: []*podresourcesapi.ContainerDevices{
@ -277,7 +268,7 @@ func TestAllocatableResources(t *testing.T) {
t.Run(tc.desc, func(t *testing.T) { t.Run(tc.desc, func(t *testing.T) {
m := new(mockProvider) m := new(mockProvider)
m.On("GetDevices", "", "").Return([]*podresourcesapi.ContainerDevices{}) m.On("GetDevices", "", "").Return([]*podresourcesapi.ContainerDevices{})
m.On("GetCPUs", "", "").Return(cpuset.CPUSet{}) m.On("GetCPUs", "", "").Return([]int64{})
m.On("UpdateAllocatedDevices").Return() m.On("UpdateAllocatedDevices").Return()
m.On("GetAllocatableDevices").Return(tc.allDevices) m.On("GetAllocatableDevices").Return(tc.allDevices)
m.On("GetAllocatableCPUs").Return(tc.allCPUs) m.On("GetAllocatableCPUs").Return(tc.allCPUs)
@ -335,27 +326,10 @@ func equalContainerDevices(devA, devB []*podresourcesapi.ContainerDevices) bool
return false return false
} }
// the ordering of container devices in the response is not defined,
// so we need to do a full scan, failing at first mismatch
for idx := 0; idx < len(devA); idx++ { for idx := 0; idx < len(devA); idx++ {
if !containsContainerDevice(devA[idx], devB) { cntDevA := devA[idx]
return false cntDevB := devB[idx]
}
}
return true
}
func containsContainerDevice(cntDev *podresourcesapi.ContainerDevices, devs []*podresourcesapi.ContainerDevices) bool {
for idx := 0; idx < len(devs); idx++ {
if equalContainerDevice(cntDev, devs[idx]) {
return true
}
}
return false
}
func equalContainerDevice(cntDevA, cntDevB *podresourcesapi.ContainerDevices) bool {
if cntDevA.ResourceName != cntDevB.ResourceName { if cntDevA.ResourceName != cntDevB.ResourceName {
return false return false
} }
@ -365,6 +339,8 @@ func equalContainerDevice(cntDevA, cntDevB *podresourcesapi.ContainerDevices) bo
if !equalStrings(cntDevA.DeviceIds, cntDevB.DeviceIds) { if !equalStrings(cntDevA.DeviceIds, cntDevB.DeviceIds) {
return false return false
} }
}
return true return true
} }

View File

@ -68,10 +68,9 @@ func (p *v1alpha1PodResourcesServer) List(ctx context.Context, req *v1alpha1.Lis
} }
for j, container := range pod.Spec.Containers { for j, container := range pod.Spec.Containers {
v1devices := containerDevicesFromResourceDeviceInstances(p.devicesProvider.GetDevices(string(pod.UID), container.Name))
pRes.Containers[j] = &v1alpha1.ContainerResources{ pRes.Containers[j] = &v1alpha1.ContainerResources{
Name: container.Name, Name: container.Name,
Devices: v1DevicesToAlphaV1(v1devices), Devices: v1DevicesToAlphaV1(p.devicesProvider.GetDevices(string(pod.UID), container.Name)),
} }
} }
podResources[i] = &pRes podResources[i] = &pRes

View File

@ -25,10 +25,8 @@ import (
"k8s.io/api/core/v1" "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types" "k8s.io/apimachinery/pkg/types"
pluginapi "k8s.io/kubelet/pkg/apis/deviceplugin/v1beta1" podresourcesv1 "k8s.io/kubelet/pkg/apis/podresources/v1"
"k8s.io/kubelet/pkg/apis/podresources/v1alpha1" "k8s.io/kubelet/pkg/apis/podresources/v1alpha1"
"k8s.io/kubernetes/pkg/kubelet/cm/cpuset"
"k8s.io/kubernetes/pkg/kubelet/cm/devicemanager"
) )
type mockProvider struct { type mockProvider struct {
@ -40,28 +38,28 @@ func (m *mockProvider) GetPods() []*v1.Pod {
return args.Get(0).([]*v1.Pod) return args.Get(0).([]*v1.Pod)
} }
func (m *mockProvider) GetDevices(podUID, containerName string) devicemanager.ResourceDeviceInstances { func (m *mockProvider) GetDevices(podUID, containerName string) []*podresourcesv1.ContainerDevices {
args := m.Called(podUID, containerName) args := m.Called(podUID, containerName)
return args.Get(0).(devicemanager.ResourceDeviceInstances) return args.Get(0).([]*podresourcesv1.ContainerDevices)
} }
func (m *mockProvider) GetCPUs(podUID, containerName string) cpuset.CPUSet { func (m *mockProvider) GetCPUs(podUID, containerName string) []int64 {
args := m.Called(podUID, containerName) args := m.Called(podUID, containerName)
return args.Get(0).(cpuset.CPUSet) return args.Get(0).([]int64)
} }
func (m *mockProvider) UpdateAllocatedDevices() { func (m *mockProvider) UpdateAllocatedDevices() {
m.Called() m.Called()
} }
func (m *mockProvider) GetAllocatableDevices() devicemanager.ResourceDeviceInstances { func (m *mockProvider) GetAllocatableDevices() []*podresourcesv1.ContainerDevices {
args := m.Called() args := m.Called()
return args.Get(0).(devicemanager.ResourceDeviceInstances) return args.Get(0).([]*podresourcesv1.ContainerDevices)
} }
func (m *mockProvider) GetAllocatableCPUs() cpuset.CPUSet { func (m *mockProvider) GetAllocatableCPUs() []int64 {
args := m.Called() args := m.Called()
return args.Get(0).(cpuset.CPUSet) return args.Get(0).([]int64)
} }
func TestListPodResourcesV1alpha1(t *testing.T) { func TestListPodResourcesV1alpha1(t *testing.T) {
@ -70,23 +68,23 @@ func TestListPodResourcesV1alpha1(t *testing.T) {
podUID := types.UID("pod-uid") podUID := types.UID("pod-uid")
containerName := "container-name" containerName := "container-name"
devs := devicemanager.ResourceDeviceInstances{ devs := []*podresourcesv1.ContainerDevices{
"resource": devicemanager.DeviceInstances{ {
"dev0": pluginapi.Device{}, ResourceName: "resource",
"dev1": pluginapi.Device{}, DeviceIds: []string{"dev0", "dev1"},
}, },
} }
for _, tc := range []struct { for _, tc := range []struct {
desc string desc string
pods []*v1.Pod pods []*v1.Pod
devices devicemanager.ResourceDeviceInstances devices []*podresourcesv1.ContainerDevices
expectedResponse *v1alpha1.ListPodResourcesResponse expectedResponse *v1alpha1.ListPodResourcesResponse
}{ }{
{ {
desc: "no pods", desc: "no pods",
pods: []*v1.Pod{}, pods: []*v1.Pod{},
devices: devicemanager.NewResourceDeviceInstances(), devices: []*podresourcesv1.ContainerDevices{},
expectedResponse: &v1alpha1.ListPodResourcesResponse{}, expectedResponse: &v1alpha1.ListPodResourcesResponse{},
}, },
{ {
@ -107,7 +105,7 @@ func TestListPodResourcesV1alpha1(t *testing.T) {
}, },
}, },
}, },
devices: devicemanager.NewResourceDeviceInstances(), devices: []*podresourcesv1.ContainerDevices{},
expectedResponse: &v1alpha1.ListPodResourcesResponse{ expectedResponse: &v1alpha1.ListPodResourcesResponse{
PodResources: []*v1alpha1.PodResources{ PodResources: []*v1alpha1.PodResources{
{ {
@ -150,7 +148,7 @@ func TestListPodResourcesV1alpha1(t *testing.T) {
Containers: []*v1alpha1.ContainerResources{ Containers: []*v1alpha1.ContainerResources{
{ {
Name: containerName, Name: containerName,
Devices: v1DevicesToAlphaV1(containerDevicesFromResourceDeviceInstances(devs)), Devices: v1DevicesToAlphaV1(devs),
}, },
}, },
}, },

View File

@ -18,8 +18,7 @@ package podresources
import ( import (
"k8s.io/api/core/v1" "k8s.io/api/core/v1"
"k8s.io/kubernetes/pkg/kubelet/cm/cpuset" podresourcesapi "k8s.io/kubelet/pkg/apis/podresources/v1"
"k8s.io/kubernetes/pkg/kubelet/cm/devicemanager"
) )
// DevicesProvider knows how to provide the devices used by the given container // DevicesProvider knows how to provide the devices used by the given container
@ -27,9 +26,9 @@ type DevicesProvider interface {
// UpdateAllocatedDevices frees any Devices that are bound to terminated pods. // UpdateAllocatedDevices frees any Devices that are bound to terminated pods.
UpdateAllocatedDevices() UpdateAllocatedDevices()
// GetDevices returns information about the devices assigned to pods and containers // GetDevices returns information about the devices assigned to pods and containers
GetDevices(podUID, containerName string) devicemanager.ResourceDeviceInstances GetDevices(podUID, containerName string) []*podresourcesapi.ContainerDevices
// GetAllocatableDevices returns information about all the devices known to the manager // GetAllocatableDevices returns information about all the devices known to the manager
GetAllocatableDevices() devicemanager.ResourceDeviceInstances GetAllocatableDevices() []*podresourcesapi.ContainerDevices
} }
// PodsProvider knows how to provide the pods admitted by the node // PodsProvider knows how to provide the pods admitted by the node
@ -40,7 +39,7 @@ type PodsProvider interface {
// CPUsProvider knows how to provide the cpus used by the given container // CPUsProvider knows how to provide the cpus used by the given container
type CPUsProvider interface { type CPUsProvider interface {
// GetCPUs returns information about the cpus assigned to pods and containers // GetCPUs returns information about the cpus assigned to pods and containers
GetCPUs(podUID, containerName string) cpuset.CPUSet GetCPUs(podUID, containerName string) []int64
// GetAllocatableCPUs returns the allocatable (not allocated) CPUs // GetAllocatableCPUs returns the allocatable (not allocated) CPUs
GetAllocatableCPUs() cpuset.CPUSet GetAllocatableCPUs() []int64
} }

View File

@ -26,9 +26,11 @@ import (
// TODO: Migrate kubelet to either use its own internal objects or client library. // TODO: Migrate kubelet to either use its own internal objects or client library.
v1 "k8s.io/api/core/v1" v1 "k8s.io/api/core/v1"
internalapi "k8s.io/cri-api/pkg/apis" internalapi "k8s.io/cri-api/pkg/apis"
podresourcesapi "k8s.io/kubelet/pkg/apis/podresources/v1"
kubeletconfig "k8s.io/kubernetes/pkg/kubelet/apis/config" kubeletconfig "k8s.io/kubernetes/pkg/kubelet/apis/config"
"k8s.io/kubernetes/pkg/kubelet/apis/podresources" "k8s.io/kubernetes/pkg/kubelet/apis/podresources"
"k8s.io/kubernetes/pkg/kubelet/cm/cpuset" "k8s.io/kubernetes/pkg/kubelet/cm/cpuset"
"k8s.io/kubernetes/pkg/kubelet/cm/devicemanager"
"k8s.io/kubernetes/pkg/kubelet/config" "k8s.io/kubernetes/pkg/kubelet/config"
kubecontainer "k8s.io/kubernetes/pkg/kubelet/container" kubecontainer "k8s.io/kubernetes/pkg/kubelet/container"
evictionapi "k8s.io/kubernetes/pkg/kubelet/eviction/api" evictionapi "k8s.io/kubernetes/pkg/kubelet/eviction/api"
@ -186,3 +188,28 @@ func ParseQOSReserved(m map[string]string) (*map[v1.ResourceName]int64, error) {
} }
return &reservations, nil return &reservations, nil
} }
func containerDevicesFromResourceDeviceInstances(devs devicemanager.ResourceDeviceInstances) []*podresourcesapi.ContainerDevices {
var respDevs []*podresourcesapi.ContainerDevices
for resourceName, resourceDevs := range devs {
for devID, dev := range resourceDevs {
for _, node := range dev.GetTopology().GetNodes() {
numaNode := node.GetID()
respDevs = append(respDevs, &podresourcesapi.ContainerDevices{
ResourceName: resourceName,
DeviceIds: []string{devID},
Topology: &podresourcesapi.TopologyInfo{
Nodes: []*podresourcesapi.NUMANode{
{
ID: numaNode,
},
},
},
})
}
}
}
return respDevs
}

View File

@ -47,11 +47,11 @@ import (
utilfeature "k8s.io/apiserver/pkg/util/feature" utilfeature "k8s.io/apiserver/pkg/util/feature"
"k8s.io/client-go/tools/record" "k8s.io/client-go/tools/record"
internalapi "k8s.io/cri-api/pkg/apis" internalapi "k8s.io/cri-api/pkg/apis"
podresourcesapi "k8s.io/kubelet/pkg/apis/podresources/v1"
kubefeatures "k8s.io/kubernetes/pkg/features" kubefeatures "k8s.io/kubernetes/pkg/features"
"k8s.io/kubernetes/pkg/kubelet/cadvisor" "k8s.io/kubernetes/pkg/kubelet/cadvisor"
"k8s.io/kubernetes/pkg/kubelet/cm/containermap" "k8s.io/kubernetes/pkg/kubelet/cm/containermap"
"k8s.io/kubernetes/pkg/kubelet/cm/cpumanager" "k8s.io/kubernetes/pkg/kubelet/cm/cpumanager"
"k8s.io/kubernetes/pkg/kubelet/cm/cpuset"
"k8s.io/kubernetes/pkg/kubelet/cm/devicemanager" "k8s.io/kubernetes/pkg/kubelet/cm/devicemanager"
"k8s.io/kubernetes/pkg/kubelet/cm/memorymanager" "k8s.io/kubernetes/pkg/kubelet/cm/memorymanager"
"k8s.io/kubernetes/pkg/kubelet/cm/topologymanager" "k8s.io/kubernetes/pkg/kubelet/cm/topologymanager"
@ -1068,20 +1068,20 @@ func (cm *containerManagerImpl) GetDevicePluginResourceCapacity() (v1.ResourceLi
return cm.deviceManager.GetCapacity() return cm.deviceManager.GetCapacity()
} }
func (cm *containerManagerImpl) GetDevices(podUID, containerName string) devicemanager.ResourceDeviceInstances { func (cm *containerManagerImpl) GetDevices(podUID, containerName string) []*podresourcesapi.ContainerDevices {
return cm.deviceManager.GetDevices(podUID, containerName) return containerDevicesFromResourceDeviceInstances(cm.deviceManager.GetDevices(podUID, containerName))
} }
func (cm *containerManagerImpl) GetAllocatableDevices() devicemanager.ResourceDeviceInstances { func (cm *containerManagerImpl) GetAllocatableDevices() []*podresourcesapi.ContainerDevices {
return cm.deviceManager.GetAllocatableDevices() return containerDevicesFromResourceDeviceInstances(cm.deviceManager.GetAllocatableDevices())
} }
func (cm *containerManagerImpl) GetCPUs(podUID, containerName string) cpuset.CPUSet { func (cm *containerManagerImpl) GetCPUs(podUID, containerName string) []int64 {
return cm.cpuManager.GetCPUs(podUID, containerName).Clone() return cm.cpuManager.GetCPUs(podUID, containerName).ToSliceNoSortInt64()
} }
func (cm *containerManagerImpl) GetAllocatableCPUs() cpuset.CPUSet { func (cm *containerManagerImpl) GetAllocatableCPUs() []int64 {
return cm.cpuManager.GetAllocatableCPUs() return cm.cpuManager.GetAllocatableCPUs().ToSliceNoSortInt64()
} }
func (cm *containerManagerImpl) ShouldResetExtendedResourceCapacity() bool { func (cm *containerManagerImpl) ShouldResetExtendedResourceCapacity() bool {

View File

@ -22,9 +22,8 @@ import (
"k8s.io/apimachinery/pkg/api/resource" "k8s.io/apimachinery/pkg/api/resource"
internalapi "k8s.io/cri-api/pkg/apis" internalapi "k8s.io/cri-api/pkg/apis"
podresourcesapi "k8s.io/kubelet/pkg/apis/podresources/v1"
"k8s.io/kubernetes/pkg/kubelet/cm/cpumanager" "k8s.io/kubernetes/pkg/kubelet/cm/cpumanager"
"k8s.io/kubernetes/pkg/kubelet/cm/cpuset"
"k8s.io/kubernetes/pkg/kubelet/cm/devicemanager"
"k8s.io/kubernetes/pkg/kubelet/cm/memorymanager" "k8s.io/kubernetes/pkg/kubelet/cm/memorymanager"
"k8s.io/kubernetes/pkg/kubelet/cm/topologymanager" "k8s.io/kubernetes/pkg/kubelet/cm/topologymanager"
"k8s.io/kubernetes/pkg/kubelet/config" "k8s.io/kubernetes/pkg/kubelet/config"
@ -111,11 +110,11 @@ func (cm *containerManagerStub) GetPodCgroupRoot() string {
return "" return ""
} }
func (cm *containerManagerStub) GetDevices(_, _ string) devicemanager.ResourceDeviceInstances { func (cm *containerManagerStub) GetDevices(_, _ string) []*podresourcesapi.ContainerDevices {
return nil return nil
} }
func (cm *containerManagerStub) GetAllocatableDevices() devicemanager.ResourceDeviceInstances { func (cm *containerManagerStub) GetAllocatableDevices() []*podresourcesapi.ContainerDevices {
return nil return nil
} }
@ -131,12 +130,12 @@ func (cm *containerManagerStub) UpdateAllocatedDevices() {
return return
} }
func (cm *containerManagerStub) GetCPUs(_, _ string) cpuset.CPUSet { func (cm *containerManagerStub) GetCPUs(_, _ string) []int64 {
return cpuset.CPUSet{} return nil
} }
func (cm *containerManagerStub) GetAllocatableCPUs() cpuset.CPUSet { func (cm *containerManagerStub) GetAllocatableCPUs() []int64 {
return cpuset.CPUSet{} return nil
} }
func NewStubContainerManager() ContainerManager { func NewStubContainerManager() ContainerManager {

View File

@ -32,10 +32,10 @@ import (
utilfeature "k8s.io/apiserver/pkg/util/feature" utilfeature "k8s.io/apiserver/pkg/util/feature"
"k8s.io/client-go/tools/record" "k8s.io/client-go/tools/record"
internalapi "k8s.io/cri-api/pkg/apis" internalapi "k8s.io/cri-api/pkg/apis"
podresourcesapi "k8s.io/kubelet/pkg/apis/podresources/v1"
kubefeatures "k8s.io/kubernetes/pkg/features" kubefeatures "k8s.io/kubernetes/pkg/features"
"k8s.io/kubernetes/pkg/kubelet/cadvisor" "k8s.io/kubernetes/pkg/kubelet/cadvisor"
"k8s.io/kubernetes/pkg/kubelet/cm/cpumanager" "k8s.io/kubernetes/pkg/kubelet/cm/cpumanager"
"k8s.io/kubernetes/pkg/kubelet/cm/cpuset"
"k8s.io/kubernetes/pkg/kubelet/cm/devicemanager" "k8s.io/kubernetes/pkg/kubelet/cm/devicemanager"
"k8s.io/kubernetes/pkg/kubelet/cm/memorymanager" "k8s.io/kubernetes/pkg/kubelet/cm/memorymanager"
"k8s.io/kubernetes/pkg/kubelet/cm/topologymanager" "k8s.io/kubernetes/pkg/kubelet/cm/topologymanager"
@ -216,11 +216,11 @@ func (cm *containerManagerImpl) GetPodCgroupRoot() string {
return "" return ""
} }
func (cm *containerManagerImpl) GetDevices(podUID, containerName string) devicemanager.ResourceDeviceInstances { func (cm *containerManagerImpl) GetDevices(podUID, containerName string) []*podresourcesapi.ContainerDevices {
return cm.deviceManager.GetDevices(podUID, containerName) return containerDevicesFromResourceDeviceInstances(cm.deviceManager.GetDevices(podUID, containerName))
} }
func (cm *containerManagerImpl) GetAllocatableDevices() devicemanager.ResourceDeviceInstances { func (cm *containerManagerImpl) GetAllocatableDevices() []*podresourcesapi.ContainerDevices {
return nil return nil
} }
@ -236,10 +236,10 @@ func (cm *containerManagerImpl) UpdateAllocatedDevices() {
return return
} }
func (cm *containerManagerImpl) GetCPUs(_, _ string) cpuset.CPUSet { func (cm *containerManagerImpl) GetCPUs(_, _ string) []int64 {
return cpuset.CPUSet{} return nil
} }
func (cm *containerManagerImpl) GetAllocatableCPUs() cpuset.CPUSet { func (cm *containerManagerImpl) GetAllocatableCPUs() []int64 {
return cpuset.CPUSet{} return nil
} }

View File

@ -23,9 +23,8 @@ import (
"k8s.io/apimachinery/pkg/api/resource" "k8s.io/apimachinery/pkg/api/resource"
internalapi "k8s.io/cri-api/pkg/apis" internalapi "k8s.io/cri-api/pkg/apis"
podresourcesapi "k8s.io/kubelet/pkg/apis/podresources/v1"
"k8s.io/kubernetes/pkg/kubelet/cm/cpumanager" "k8s.io/kubernetes/pkg/kubelet/cm/cpumanager"
"k8s.io/kubernetes/pkg/kubelet/cm/cpuset"
"k8s.io/kubernetes/pkg/kubelet/cm/devicemanager"
"k8s.io/kubernetes/pkg/kubelet/cm/memorymanager" "k8s.io/kubernetes/pkg/kubelet/cm/memorymanager"
"k8s.io/kubernetes/pkg/kubelet/cm/topologymanager" "k8s.io/kubernetes/pkg/kubelet/cm/topologymanager"
"k8s.io/kubernetes/pkg/kubelet/config" "k8s.io/kubernetes/pkg/kubelet/config"
@ -168,14 +167,14 @@ func (cm *FakeContainerManager) GetPodCgroupRoot() string {
return "" return ""
} }
func (cm *FakeContainerManager) GetDevices(_, _ string) devicemanager.ResourceDeviceInstances { func (cm *FakeContainerManager) GetDevices(_, _ string) []*podresourcesapi.ContainerDevices {
cm.Lock() cm.Lock()
defer cm.Unlock() defer cm.Unlock()
cm.CalledFunctions = append(cm.CalledFunctions, "GetDevices") cm.CalledFunctions = append(cm.CalledFunctions, "GetDevices")
return nil return nil
} }
func (cm *FakeContainerManager) GetAllocatableDevices() devicemanager.ResourceDeviceInstances { func (cm *FakeContainerManager) GetAllocatableDevices() []*podresourcesapi.ContainerDevices {
cm.Lock() cm.Lock()
defer cm.Unlock() defer cm.Unlock()
cm.CalledFunctions = append(cm.CalledFunctions, "GetAllocatableDevices") cm.CalledFunctions = append(cm.CalledFunctions, "GetAllocatableDevices")
@ -203,16 +202,15 @@ func (cm *FakeContainerManager) UpdateAllocatedDevices() {
return return
} }
func (cm *FakeContainerManager) GetCPUs(_, _ string) cpuset.CPUSet { func (cm *FakeContainerManager) GetCPUs(_, _ string) []int64 {
cm.Lock() cm.Lock()
defer cm.Unlock() defer cm.Unlock()
cm.CalledFunctions = append(cm.CalledFunctions, "GetCPUs") cm.CalledFunctions = append(cm.CalledFunctions, "GetCPUs")
return cpuset.CPUSet{} return nil
} }
func (cm *FakeContainerManager) GetAllocatableCPUs() cpuset.CPUSet { func (cm *FakeContainerManager) GetAllocatableCPUs() []int64 {
cm.Lock() cm.Lock()
defer cm.Unlock() defer cm.Unlock()
cm.CalledFunctions = append(cm.CalledFunctions, "GetAllocatableCPUs") return nil
return cpuset.CPUSet{}
} }