mirror of
https://github.com/k8snetworkplumbingwg/multus-cni.git
synced 2026-03-18 10:56:22 +00:00
Merge pull request #1481 from cathy-zhou/sortedResourcesUpstream
Sort DeviceIDs in GetPodResourceMap for deterministic ordering
This commit is contained in:
@@ -108,5 +108,6 @@ func (cp *checkpoint) GetPodResourceMap(pod *v1.Pod) (map[string]*types.Resource
|
||||
}
|
||||
}
|
||||
}
|
||||
types.SortDeviceIDs(resourceMap)
|
||||
return resourceMap, nil
|
||||
}
|
||||
|
||||
@@ -132,12 +132,13 @@ var _ = Describe("Kubelet checkpoint data read operations", func() {
|
||||
Expect(len(resourceInfo.DeviceIDs)).To(BeEquivalentTo(2))
|
||||
})
|
||||
|
||||
It("should have \"0000:03:02.3\" in deviceIDs[0]", func() {
|
||||
Expect(resourceInfo.DeviceIDs[0]).To(BeEquivalentTo("0000:03:02.3"))
|
||||
// DeviceIDs are sorted for deterministic order across callers
|
||||
It("should have \"0000:03:02.0\" in deviceIDs[0] (sorted order)", func() {
|
||||
Expect(resourceInfo.DeviceIDs[0]).To(BeEquivalentTo("0000:03:02.0"))
|
||||
})
|
||||
|
||||
It("should have \"0000:03:02.0\" in deviceIDs[1]", func() {
|
||||
Expect(resourceInfo.DeviceIDs[1]).To(BeEquivalentTo("0000:03:02.0"))
|
||||
It("should have \"0000:03:02.3\" in deviceIDs[1] (sorted order)", func() {
|
||||
Expect(resourceInfo.DeviceIDs[1]).To(BeEquivalentTo("0000:03:02.3"))
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
@@ -143,6 +143,7 @@ func (rc *kubeletClient) GetPodResourceMap(pod *v1.Pod) (map[string]*types.Resou
|
||||
}
|
||||
}
|
||||
}
|
||||
types.SortDeviceIDs(resourceMap)
|
||||
return resourceMap, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -17,6 +17,7 @@ package types
|
||||
|
||||
import (
|
||||
"net"
|
||||
"sort"
|
||||
|
||||
"github.com/containernetworking/cni/libcni"
|
||||
"github.com/containernetworking/cni/pkg/types"
|
||||
@@ -178,6 +179,16 @@ type ResourceInfo struct {
|
||||
DeviceIDs []string
|
||||
}
|
||||
|
||||
// SortDeviceIDs sorts DeviceIDs in each ResourceInfo in place so that device
|
||||
// order is deterministic across GetPodResourceMap callers (e.g. Multus and OVN-Kubernetes).
|
||||
func SortDeviceIDs(resourceMap map[string]*ResourceInfo) {
|
||||
for _, rInfo := range resourceMap {
|
||||
if rInfo.DeviceIDs != nil {
|
||||
sort.Strings(rInfo.DeviceIDs)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ResourceClient provides a kubelet Pod resource handle
|
||||
type ResourceClient interface {
|
||||
// GetPodResourceMap returns an instance of a map of Pod ResourceInfo given a (Pod name, namespace) tuple
|
||||
|
||||
Reference in New Issue
Block a user