@@ -34,6 +34,134 @@ func TestFillPodDevicesAllocatedByKoord(t *testing.T) {
34
34
podList * corev1.PodList
35
35
expectedResult * podresourcesapi.ListPodResourcesResponse
36
36
}{
37
+ {
38
+ name : "MatchingPodWithDeviceAllocationsWithVf" ,
39
+ response : & podresourcesapi.ListPodResourcesResponse {
40
+ PodResources : []* podresourcesapi.PodResources {
41
+ {
42
+ Name : "test-pod" ,
43
+ Namespace : "test-namespace" ,
44
+ Containers : []* podresourcesapi.ContainerResources {
45
+ {
46
+ Name : "test-container" ,
47
+ },
48
+ },
49
+ },
50
+ },
51
+ },
52
+ podList : & corev1.PodList {
53
+ Items : []corev1.Pod {
54
+ {
55
+ ObjectMeta : metav1.ObjectMeta {
56
+ Name : "test-pod" ,
57
+ Namespace : "test-namespace" ,
58
+ Annotations : map [string ]string {
59
+ apiext .AnnotationDeviceAllocated : `{"gpu":[{"minor":0,"resources":{"koordinator.sh/gpu-core":"100","koordinator.sh/gpu-memory":"23040Mi","koordinator.sh/gpu-memory-ratio":"100"},"id":"0"}],"rdma":[{"minor":0,"resources":{"koordinator.sh/rdma":"1"},"id":"0000:01:00.0","extension":{"vfs":[{"minor":-1,"busID":"0000:01:00.2"}]}}]}` ,
60
+ },
61
+ },
62
+ },
63
+ },
64
+ },
65
+ expectedResult : & podresourcesapi.ListPodResourcesResponse {
66
+ PodResources : []* podresourcesapi.PodResources {
67
+ {
68
+ Name : "test-pod" ,
69
+ Namespace : "test-namespace" ,
70
+ Containers : []* podresourcesapi.ContainerResources {
71
+ {
72
+ Name : "test-container" ,
73
+ Devices : []* podresourcesapi.ContainerDevices {
74
+ {
75
+ ResourceName : string (apiext .ResourceNvidiaGPU ),
76
+ DeviceIds : []string {"0" },
77
+ },
78
+ {
79
+ ResourceName : string (apiext .ResourceRDMA ),
80
+ DeviceIds : []string {"0000:01:00.2" },
81
+ },
82
+ },
83
+ },
84
+ },
85
+ },
86
+ },
87
+ },
88
+ },
89
+ {
90
+ name : "MatchingPodWithDeviceAllocationsWithVfAndMMultiplePod" ,
91
+ response : & podresourcesapi.ListPodResourcesResponse {
92
+ PodResources : []* podresourcesapi.PodResources {
93
+ {
94
+ Name : "test-pod-1" ,
95
+ Namespace : "test-namespace" ,
96
+ Containers : []* podresourcesapi.ContainerResources {
97
+ {
98
+ Name : "test-container" ,
99
+ },
100
+ },
101
+ },
102
+ {
103
+ Name : "test-pod" ,
104
+ Namespace : "test-namespace" ,
105
+ Containers : []* podresourcesapi.ContainerResources {
106
+ {
107
+ Name : "test-container" ,
108
+ },
109
+ },
110
+ },
111
+ },
112
+ },
113
+ podList : & corev1.PodList {
114
+ Items : []corev1.Pod {
115
+ {
116
+ ObjectMeta : metav1.ObjectMeta {
117
+ Name : "test-pod-1" ,
118
+ Namespace : "test-namespace" ,
119
+ },
120
+ },
121
+ {
122
+ ObjectMeta : metav1.ObjectMeta {
123
+ Name : "test-pod" ,
124
+ Namespace : "test-namespace" ,
125
+ Annotations : map [string ]string {
126
+ apiext .AnnotationDeviceAllocated : `{"gpu":[{"minor":0,"resources":{"koordinator.sh/gpu-core":"100","koordinator.sh/gpu-memory":"23040Mi","koordinator.sh/gpu-memory-ratio":"100"},"id":"0"}],"rdma":[{"minor":0,"resources":{"koordinator.sh/rdma":"1"},"id":"0000:01:00.0","extension":{"vfs":[{"minor":-1,"busID":"0000:01:00.2"}]}}]}` ,
127
+ },
128
+ },
129
+ },
130
+ },
131
+ },
132
+ expectedResult : & podresourcesapi.ListPodResourcesResponse {
133
+ PodResources : []* podresourcesapi.PodResources {
134
+ {
135
+ Name : "test-pod-1" ,
136
+ Namespace : "test-namespace" ,
137
+ Containers : []* podresourcesapi.ContainerResources {
138
+ {
139
+ Name : "test-container" ,
140
+ },
141
+ },
142
+ },
143
+ {
144
+ Name : "test-pod" ,
145
+ Namespace : "test-namespace" ,
146
+ Containers : []* podresourcesapi.ContainerResources {
147
+ {
148
+ Name : "test-container" ,
149
+ Devices : []* podresourcesapi.ContainerDevices {
150
+ {
151
+ ResourceName : string (apiext .ResourceNvidiaGPU ),
152
+ DeviceIds : []string {"0" },
153
+ },
154
+ {
155
+ ResourceName : string (apiext .ResourceRDMA ),
156
+ DeviceIds : []string {"0000:01:00.2" },
157
+ },
158
+ },
159
+ },
160
+ },
161
+ },
162
+ },
163
+ },
164
+ },
37
165
{
38
166
name : "MatchingPodWithDeviceAllocations" ,
39
167
response : & podresourcesapi.ListPodResourcesResponse {
@@ -168,7 +296,7 @@ func TestFillPodDevicesAllocatedByKoord(t *testing.T) {
168
296
for _ , test := range tests {
169
297
t .Run (test .name , func (t * testing.T ) {
170
298
fillPodDevicesAllocatedByKoord (test .response , test .podList )
171
- assert .Equal (t , test .response , test .expectedResult )
299
+ assert .Equal (t , test .expectedResult , test .response )
172
300
})
173
301
}
174
302
}
0 commit comments