Skip to content

Commit

Permalink
koordlet: fix UT for podresources (#2345)
Browse files Browse the repository at this point in the history
Signed-off-by: wangjianyu.wjy <[email protected]>
Co-authored-by: wangjianyu.wjy <[email protected]>
  • Loading branch information
ZiMengSheng and wangjianyu.wjy authored Feb 21, 2025
1 parent b95a9bf commit 7a9e18c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
4 changes: 4 additions & 0 deletions pkg/koordlet/statesinformer/impl/states_pod_resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"net"
"os"
"path/filepath"
"sort"

"google.golang.org/grpc"
corev1 "k8s.io/api/core/v1"
Expand Down Expand Up @@ -191,6 +192,9 @@ func fillPodDevicesAllocatedByKoord(response *podresourcesapi.ListPodResourcesRe
DeviceIds: deviceIDs,
})
}
sort.Slice(podResource.Containers[0].Devices, func(i, j int) bool {
return podResource.Containers[0].Devices[i].ResourceName < podResource.Containers[0].Devices[j].ResourceName
})
}
}

Expand Down
22 changes: 14 additions & 8 deletions pkg/koordlet/statesinformer/impl/states_pod_resources_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
package impl

import (
"sort"
"testing"

"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -71,13 +72,12 @@ func TestFillPodDevicesAllocatedByKoord(t *testing.T) {
{
Name: "test-container",
Devices: []*podresourcesapi.ContainerDevices{
{
ResourceName: string(apiext.ResourceNvidiaGPU),
DeviceIds: []string{"0"},
},
{
ResourceName: string(apiext.ResourceRDMA),
DeviceIds: []string{"0000:01:00.2"},
}, {
ResourceName: string(apiext.ResourceNvidiaGPU),
DeviceIds: []string{"0"},
},
},
},
Expand Down Expand Up @@ -147,14 +147,14 @@ func TestFillPodDevicesAllocatedByKoord(t *testing.T) {
{
Name: "test-container",
Devices: []*podresourcesapi.ContainerDevices{
{
ResourceName: string(apiext.ResourceNvidiaGPU),
DeviceIds: []string{"0"},
},
{
ResourceName: string(apiext.ResourceRDMA),
DeviceIds: []string{"0000:01:00.2"},
},
{
ResourceName: string(apiext.ResourceNvidiaGPU),
DeviceIds: []string{"0"},
},
},
},
},
Expand Down Expand Up @@ -296,6 +296,12 @@ func TestFillPodDevicesAllocatedByKoord(t *testing.T) {
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
fillPodDevicesAllocatedByKoord(test.response, test.podList)
sort.Slice(test.response.PodResources, func(i, j int) bool {
return test.response.PodResources[i].Name < test.response.PodResources[j].Name
})
sort.Slice(test.expectedResult.PodResources, func(i, j int) bool {
return test.expectedResult.PodResources[i].Name < test.expectedResult.PodResources[j].Name
})
assert.Equal(t, test.expectedResult, test.response)
})
}
Expand Down

0 comments on commit 7a9e18c

Please sign in to comment.