Skip to content

Commit

Permalink
Merge pull request kubernetes#126427 from pacoxu/fix-TestUpdateAlloca…
Browse files Browse the repository at this point in the history
…tedResourcesStatus

ignore order of containers status allocated resources
  • Loading branch information
k8s-ci-robot authored Jul 29, 2024
2 parents e8588e6 + 78d3830 commit b5b2171
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions pkg/kubelet/cm/devicemanager/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"path/filepath"
"reflect"
goruntime "runtime"
"sort"
"sync"
"sync/atomic"
"testing"
Expand Down Expand Up @@ -1927,7 +1928,28 @@ func TestUpdateAllocatedResourcesStatus(t *testing.T) {
AllocatedResourcesStatus: []v1.ResourceStatus{expectedStatus},
},
}

// Sort the resources for the expected status and actual status
sortContainerStatuses(status.ContainerStatuses)
sortContainerStatuses(expectedContainerStatuses)

if !reflect.DeepEqual(status.ContainerStatuses, expectedContainerStatuses) {
t.Errorf("UpdateAllocatedResourcesStatus failed, expected: %v, got: %v", expectedContainerStatuses, status.ContainerStatuses)
}
}

// Helper function to sort ResourceHealth slices
func sortResourceHealth(resources []v1.ResourceHealth) {
sort.SliceStable(resources, func(i, j int) bool {
return resources[i].ResourceID < resources[j].ResourceID
})
}

// Helper function to sort ContainerStatus slices
func sortContainerStatuses(statuses []v1.ContainerStatus) {
for i := range statuses {
for j := range statuses[i].AllocatedResourcesStatus {
sortResourceHealth(statuses[i].AllocatedResourcesStatus[j].Resources)
}
}
}

0 comments on commit b5b2171

Please sign in to comment.