Skip to content

Commit 7a9e18c

Browse files
ZiMengShengwangjianyu.wjy
and
wangjianyu.wjy
authoredFeb 21, 2025··
koordlet: fix UT for podresources (#2345)
Signed-off-by: wangjianyu.wjy <wangjianyu.wjy@alibaba-inc.com> Co-authored-by: wangjianyu.wjy <wangjianyu.wjy@alibaba-inc.com>
1 parent b95a9bf commit 7a9e18c

File tree

2 files changed

+18
-8
lines changed

2 files changed

+18
-8
lines changed
 

‎pkg/koordlet/statesinformer/impl/states_pod_resources.go

+4
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"net"
2222
"os"
2323
"path/filepath"
24+
"sort"
2425

2526
"google.golang.org/grpc"
2627
corev1 "k8s.io/api/core/v1"
@@ -191,6 +192,9 @@ func fillPodDevicesAllocatedByKoord(response *podresourcesapi.ListPodResourcesRe
191192
DeviceIds: deviceIDs,
192193
})
193194
}
195+
sort.Slice(podResource.Containers[0].Devices, func(i, j int) bool {
196+
return podResource.Containers[0].Devices[i].ResourceName < podResource.Containers[0].Devices[j].ResourceName
197+
})
194198
}
195199
}
196200

‎pkg/koordlet/statesinformer/impl/states_pod_resources_test.go

+14-8
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ limitations under the License.
1717
package impl
1818

1919
import (
20+
"sort"
2021
"testing"
2122

2223
"github.com/stretchr/testify/assert"
@@ -71,13 +72,12 @@ func TestFillPodDevicesAllocatedByKoord(t *testing.T) {
7172
{
7273
Name: "test-container",
7374
Devices: []*podresourcesapi.ContainerDevices{
74-
{
75-
ResourceName: string(apiext.ResourceNvidiaGPU),
76-
DeviceIds: []string{"0"},
77-
},
7875
{
7976
ResourceName: string(apiext.ResourceRDMA),
8077
DeviceIds: []string{"0000:01:00.2"},
78+
}, {
79+
ResourceName: string(apiext.ResourceNvidiaGPU),
80+
DeviceIds: []string{"0"},
8181
},
8282
},
8383
},
@@ -147,14 +147,14 @@ func TestFillPodDevicesAllocatedByKoord(t *testing.T) {
147147
{
148148
Name: "test-container",
149149
Devices: []*podresourcesapi.ContainerDevices{
150-
{
151-
ResourceName: string(apiext.ResourceNvidiaGPU),
152-
DeviceIds: []string{"0"},
153-
},
154150
{
155151
ResourceName: string(apiext.ResourceRDMA),
156152
DeviceIds: []string{"0000:01:00.2"},
157153
},
154+
{
155+
ResourceName: string(apiext.ResourceNvidiaGPU),
156+
DeviceIds: []string{"0"},
157+
},
158158
},
159159
},
160160
},
@@ -296,6 +296,12 @@ func TestFillPodDevicesAllocatedByKoord(t *testing.T) {
296296
for _, test := range tests {
297297
t.Run(test.name, func(t *testing.T) {
298298
fillPodDevicesAllocatedByKoord(test.response, test.podList)
299+
sort.Slice(test.response.PodResources, func(i, j int) bool {
300+
return test.response.PodResources[i].Name < test.response.PodResources[j].Name
301+
})
302+
sort.Slice(test.expectedResult.PodResources, func(i, j int) bool {
303+
return test.expectedResult.PodResources[i].Name < test.expectedResult.PodResources[j].Name
304+
})
299305
assert.Equal(t, test.expectedResult, test.response)
300306
})
301307
}

0 commit comments

Comments
 (0)
Please sign in to comment.