mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-28 14:07:14 +00:00
Update topology hints tests to use pod object for devicemanager
Pod object is more flexible to use and construct * Update TestGetTopologyHints() to work according to new test cases * Update topologyHintTestCase{} to include proper field Signed-off-by: Krzysztof Wiatrzyk <k.wiatrzyk@samsung.com>
This commit is contained in:
parent
7ad65bf22d
commit
1c4a1ba6ae
@ -24,7 +24,7 @@ import (
|
|||||||
|
|
||||||
v1 "k8s.io/api/core/v1"
|
v1 "k8s.io/api/core/v1"
|
||||||
"k8s.io/apimachinery/pkg/api/resource"
|
"k8s.io/apimachinery/pkg/api/resource"
|
||||||
"k8s.io/apimachinery/pkg/types"
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
"k8s.io/apimachinery/pkg/util/sets"
|
"k8s.io/apimachinery/pkg/util/sets"
|
||||||
pluginapi "k8s.io/kubelet/pkg/apis/deviceplugin/v1beta1"
|
pluginapi "k8s.io/kubelet/pkg/apis/deviceplugin/v1beta1"
|
||||||
"k8s.io/kubernetes/pkg/kubelet/cm/topologymanager"
|
"k8s.io/kubernetes/pkg/kubelet/cm/topologymanager"
|
||||||
@ -55,22 +55,13 @@ func TestGetTopologyHints(t *testing.T) {
|
|||||||
tcases := getCommonTestCases()
|
tcases := getCommonTestCases()
|
||||||
|
|
||||||
for _, tc := range tcases {
|
for _, tc := range tcases {
|
||||||
resourceList := v1.ResourceList{}
|
|
||||||
for r := range tc.request {
|
|
||||||
resourceList[v1.ResourceName(r)] = resource.MustParse(tc.request[r])
|
|
||||||
}
|
|
||||||
|
|
||||||
pod := makePod(resourceList)
|
|
||||||
pod.UID = types.UID(tc.podUID)
|
|
||||||
pod.Spec.Containers[0].Name = tc.containerName
|
|
||||||
|
|
||||||
m := ManagerImpl{
|
m := ManagerImpl{
|
||||||
allDevices: make(map[string]map[string]pluginapi.Device),
|
allDevices: make(map[string]map[string]pluginapi.Device),
|
||||||
healthyDevices: make(map[string]sets.String),
|
healthyDevices: make(map[string]sets.String),
|
||||||
allocatedDevices: make(map[string]sets.String),
|
allocatedDevices: make(map[string]sets.String),
|
||||||
podDevices: newPodDevices(),
|
podDevices: newPodDevices(),
|
||||||
sourcesReady: &sourcesReadyStub{},
|
sourcesReady: &sourcesReadyStub{},
|
||||||
activePods: func() []*v1.Pod { return []*v1.Pod{pod} },
|
activePods: func() []*v1.Pod { return []*v1.Pod{tc.pod} },
|
||||||
numaNodes: []int{0, 1},
|
numaNodes: []int{0, 1},
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -97,7 +88,7 @@ func TestGetTopologyHints(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
hints := m.GetTopologyHints(pod, &pod.Spec.Containers[0])
|
hints := m.GetTopologyHints(tc.pod, &tc.pod.Spec.Containers[0])
|
||||||
|
|
||||||
for r := range tc.expectedHints {
|
for r := range tc.expectedHints {
|
||||||
sort.SliceStable(hints[r], func(i, j int) bool {
|
sort.SliceStable(hints[r], func(i, j int) bool {
|
||||||
@ -666,9 +657,7 @@ func TestGetPreferredAllocationParameters(t *testing.T) {
|
|||||||
|
|
||||||
type topologyHintTestCase struct {
|
type topologyHintTestCase struct {
|
||||||
description string
|
description string
|
||||||
podUID string
|
pod *v1.Pod
|
||||||
containerName string
|
|
||||||
request map[string]string
|
|
||||||
devices map[string][]pluginapi.Device
|
devices map[string][]pluginapi.Device
|
||||||
allocatedDevices map[string]map[string]map[string][]string
|
allocatedDevices map[string]map[string]map[string][]string
|
||||||
expectedHints map[string][]topologymanager.TopologyHint
|
expectedHints map[string][]topologymanager.TopologyHint
|
||||||
@ -678,10 +667,22 @@ func getCommonTestCases() []topologyHintTestCase {
|
|||||||
return []topologyHintTestCase{
|
return []topologyHintTestCase{
|
||||||
{
|
{
|
||||||
description: "Single Request, no alignment",
|
description: "Single Request, no alignment",
|
||||||
podUID: "fakePod",
|
pod: &v1.Pod{
|
||||||
containerName: "fakeContainer",
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
request: map[string]string{
|
UID: "fakePod",
|
||||||
"testdevice": "1",
|
},
|
||||||
|
Spec: v1.PodSpec{
|
||||||
|
Containers: []v1.Container{
|
||||||
|
{
|
||||||
|
Name: "fakeContainer",
|
||||||
|
Resources: v1.ResourceRequirements{
|
||||||
|
Limits: v1.ResourceList{
|
||||||
|
v1.ResourceName("testdevice"): resource.MustParse("1"),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
devices: map[string][]pluginapi.Device{
|
devices: map[string][]pluginapi.Device{
|
||||||
"testdevice": {
|
"testdevice": {
|
||||||
@ -695,10 +696,22 @@ func getCommonTestCases() []topologyHintTestCase {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
description: "Single Request, only one with alignment",
|
description: "Single Request, only one with alignment",
|
||||||
podUID: "fakePod",
|
pod: &v1.Pod{
|
||||||
containerName: "fakeContainer",
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
request: map[string]string{
|
UID: "fakePod",
|
||||||
"testdevice": "1",
|
},
|
||||||
|
Spec: v1.PodSpec{
|
||||||
|
Containers: []v1.Container{
|
||||||
|
{
|
||||||
|
Name: "fakeContainer",
|
||||||
|
Resources: v1.ResourceRequirements{
|
||||||
|
Limits: v1.ResourceList{
|
||||||
|
v1.ResourceName("testdevice"): resource.MustParse("1"),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
devices: map[string][]pluginapi.Device{
|
devices: map[string][]pluginapi.Device{
|
||||||
"testdevice": {
|
"testdevice": {
|
||||||
@ -721,10 +734,22 @@ func getCommonTestCases() []topologyHintTestCase {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
description: "Single Request, one device per socket",
|
description: "Single Request, one device per socket",
|
||||||
podUID: "fakePod",
|
pod: &v1.Pod{
|
||||||
containerName: "fakeContainer",
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
request: map[string]string{
|
UID: "fakePod",
|
||||||
"testdevice": "1",
|
},
|
||||||
|
Spec: v1.PodSpec{
|
||||||
|
Containers: []v1.Container{
|
||||||
|
{
|
||||||
|
Name: "fakeContainer",
|
||||||
|
Resources: v1.ResourceRequirements{
|
||||||
|
Limits: v1.ResourceList{
|
||||||
|
v1.ResourceName("testdevice"): resource.MustParse("1"),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
devices: map[string][]pluginapi.Device{
|
devices: map[string][]pluginapi.Device{
|
||||||
"testdevice": {
|
"testdevice": {
|
||||||
@ -751,10 +776,22 @@ func getCommonTestCases() []topologyHintTestCase {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
description: "Request for 2, one device per socket",
|
description: "Request for 2, one device per socket",
|
||||||
podUID: "fakePod",
|
pod: &v1.Pod{
|
||||||
containerName: "fakeContainer",
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
request: map[string]string{
|
UID: "fakePod",
|
||||||
"testdevice": "2",
|
},
|
||||||
|
Spec: v1.PodSpec{
|
||||||
|
Containers: []v1.Container{
|
||||||
|
{
|
||||||
|
Name: "fakeContainer",
|
||||||
|
Resources: v1.ResourceRequirements{
|
||||||
|
Limits: v1.ResourceList{
|
||||||
|
v1.ResourceName("testdevice"): resource.MustParse("2"),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
devices: map[string][]pluginapi.Device{
|
devices: map[string][]pluginapi.Device{
|
||||||
"testdevice": {
|
"testdevice": {
|
||||||
@ -773,10 +810,22 @@ func getCommonTestCases() []topologyHintTestCase {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
description: "Request for 2, 2 devices per socket",
|
description: "Request for 2, 2 devices per socket",
|
||||||
podUID: "fakePod",
|
pod: &v1.Pod{
|
||||||
containerName: "fakeContainer",
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
request: map[string]string{
|
UID: "fakePod",
|
||||||
"testdevice": "2",
|
},
|
||||||
|
Spec: v1.PodSpec{
|
||||||
|
Containers: []v1.Container{
|
||||||
|
{
|
||||||
|
Name: "fakeContainer",
|
||||||
|
Resources: v1.ResourceRequirements{
|
||||||
|
Limits: v1.ResourceList{
|
||||||
|
v1.ResourceName("testdevice"): resource.MustParse("2"),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
devices: map[string][]pluginapi.Device{
|
devices: map[string][]pluginapi.Device{
|
||||||
"testdevice": {
|
"testdevice": {
|
||||||
@ -805,10 +854,22 @@ func getCommonTestCases() []topologyHintTestCase {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
description: "Request for 2, optimal on 1 NUMA node, forced cross-NUMA",
|
description: "Request for 2, optimal on 1 NUMA node, forced cross-NUMA",
|
||||||
podUID: "fakePod",
|
pod: &v1.Pod{
|
||||||
containerName: "fakeContainer",
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
request: map[string]string{
|
UID: "fakePod",
|
||||||
"testdevice": "2",
|
},
|
||||||
|
Spec: v1.PodSpec{
|
||||||
|
Containers: []v1.Container{
|
||||||
|
{
|
||||||
|
Name: "fakeContainer",
|
||||||
|
Resources: v1.ResourceRequirements{
|
||||||
|
Limits: v1.ResourceList{
|
||||||
|
v1.ResourceName("testdevice"): resource.MustParse("2"),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
devices: map[string][]pluginapi.Device{
|
devices: map[string][]pluginapi.Device{
|
||||||
"testdevice": {
|
"testdevice": {
|
||||||
@ -836,11 +897,23 @@ func getCommonTestCases() []topologyHintTestCase {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
description: "2 device types, mixed configuration",
|
description: "2 device types, mixed configuration",
|
||||||
podUID: "fakePod",
|
pod: &v1.Pod{
|
||||||
containerName: "fakeContainer",
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
request: map[string]string{
|
UID: "fakePod",
|
||||||
"testdevice1": "2",
|
},
|
||||||
"testdevice2": "1",
|
Spec: v1.PodSpec{
|
||||||
|
Containers: []v1.Container{
|
||||||
|
{
|
||||||
|
Name: "fakeContainer",
|
||||||
|
Resources: v1.ResourceRequirements{
|
||||||
|
Limits: v1.ResourceList{
|
||||||
|
v1.ResourceName("testdevice1"): resource.MustParse("2"),
|
||||||
|
v1.ResourceName("testdevice2"): resource.MustParse("1"),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
devices: map[string][]pluginapi.Device{
|
devices: map[string][]pluginapi.Device{
|
||||||
"testdevice1": {
|
"testdevice1": {
|
||||||
@ -882,10 +955,22 @@ func getCommonTestCases() []topologyHintTestCase {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
description: "Single device type, more requested than available",
|
description: "Single device type, more requested than available",
|
||||||
podUID: "fakePod",
|
pod: &v1.Pod{
|
||||||
containerName: "fakeContainer",
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
request: map[string]string{
|
UID: "fakePod",
|
||||||
"testdevice": "6",
|
},
|
||||||
|
Spec: v1.PodSpec{
|
||||||
|
Containers: []v1.Container{
|
||||||
|
{
|
||||||
|
Name: "fakeContainer",
|
||||||
|
Resources: v1.ResourceRequirements{
|
||||||
|
Limits: v1.ResourceList{
|
||||||
|
v1.ResourceName("testdevice"): resource.MustParse("6"),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
devices: map[string][]pluginapi.Device{
|
devices: map[string][]pluginapi.Device{
|
||||||
"testdevice": {
|
"testdevice": {
|
||||||
@ -901,10 +986,22 @@ func getCommonTestCases() []topologyHintTestCase {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
description: "Single device type, all already allocated to container",
|
description: "Single device type, all already allocated to container",
|
||||||
podUID: "fakePod",
|
pod: &v1.Pod{
|
||||||
containerName: "fakeContainer",
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
request: map[string]string{
|
UID: "fakePod",
|
||||||
"testdevice": "2",
|
},
|
||||||
|
Spec: v1.PodSpec{
|
||||||
|
Containers: []v1.Container{
|
||||||
|
{
|
||||||
|
Name: "fakeContainer",
|
||||||
|
Resources: v1.ResourceRequirements{
|
||||||
|
Limits: v1.ResourceList{
|
||||||
|
v1.ResourceName("testdevice"): resource.MustParse("2"),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
devices: map[string][]pluginapi.Device{
|
devices: map[string][]pluginapi.Device{
|
||||||
"testdevice": {
|
"testdevice": {
|
||||||
@ -934,10 +1031,22 @@ func getCommonTestCases() []topologyHintTestCase {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
description: "Single device type, less already allocated to container than requested",
|
description: "Single device type, less already allocated to container than requested",
|
||||||
podUID: "fakePod",
|
pod: &v1.Pod{
|
||||||
containerName: "fakeContainer",
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
request: map[string]string{
|
UID: "fakePod",
|
||||||
"testdevice": "4",
|
},
|
||||||
|
Spec: v1.PodSpec{
|
||||||
|
Containers: []v1.Container{
|
||||||
|
{
|
||||||
|
Name: "fakeContainer",
|
||||||
|
Resources: v1.ResourceRequirements{
|
||||||
|
Limits: v1.ResourceList{
|
||||||
|
v1.ResourceName("testdevice"): resource.MustParse("4"),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
devices: map[string][]pluginapi.Device{
|
devices: map[string][]pluginapi.Device{
|
||||||
"testdevice": {
|
"testdevice": {
|
||||||
@ -960,10 +1069,22 @@ func getCommonTestCases() []topologyHintTestCase {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
description: "Single device type, more already allocated to container than requested",
|
description: "Single device type, more already allocated to container than requested",
|
||||||
podUID: "fakePod",
|
pod: &v1.Pod{
|
||||||
containerName: "fakeContainer",
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
request: map[string]string{
|
UID: "fakePod",
|
||||||
"testdevice": "2",
|
},
|
||||||
|
Spec: v1.PodSpec{
|
||||||
|
Containers: []v1.Container{
|
||||||
|
{
|
||||||
|
Name: "fakeContainer",
|
||||||
|
Resources: v1.ResourceRequirements{
|
||||||
|
Limits: v1.ResourceList{
|
||||||
|
v1.ResourceName("testdevice"): resource.MustParse("2"),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
devices: map[string][]pluginapi.Device{
|
devices: map[string][]pluginapi.Device{
|
||||||
"testdevice": {
|
"testdevice": {
|
||||||
|
Loading…
Reference in New Issue
Block a user