mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 11:50:44 +00:00
Added LessThan() and IsEqual() methods for TopologyHints
This commit is contained in:
parent
6a19261e96
commit
b17706b149
@ -29,13 +29,6 @@ import (
|
||||
"k8s.io/kubernetes/pkg/kubelet/cm/topologymanager/bitmask"
|
||||
)
|
||||
|
||||
func topologyHintLessThan(a topologymanager.TopologyHint, b topologymanager.TopologyHint) bool {
|
||||
if a.Preferred != b.Preferred {
|
||||
return a.Preferred == true
|
||||
}
|
||||
return a.NUMANodeAffinity.IsNarrowerThan(b.NUMANodeAffinity)
|
||||
}
|
||||
|
||||
func TestGetTopologyHints(t *testing.T) {
|
||||
testPod1 := makePod("2", "2")
|
||||
testContainer1 := &testPod1.Spec.Containers[0]
|
||||
@ -168,10 +161,10 @@ func TestGetTopologyHints(t *testing.T) {
|
||||
continue
|
||||
}
|
||||
sort.SliceStable(hints, func(i, j int) bool {
|
||||
return topologyHintLessThan(hints[i], hints[j])
|
||||
return hints[i].LessThan(hints[j])
|
||||
})
|
||||
sort.SliceStable(tc.expectedHints, func(i, j int) bool {
|
||||
return topologyHintLessThan(tc.expectedHints[i], tc.expectedHints[j])
|
||||
return tc.expectedHints[i].LessThan(tc.expectedHints[j])
|
||||
})
|
||||
if !reflect.DeepEqual(tc.expectedHints, hints) {
|
||||
t.Errorf("Expected in result to be %v , got %v", tc.expectedHints, hints)
|
||||
|
@ -44,13 +44,6 @@ func makeNUMADevice(id string, numa int) pluginapi.Device {
|
||||
}
|
||||
}
|
||||
|
||||
func topologyHintLessThan(a topologymanager.TopologyHint, b topologymanager.TopologyHint) bool {
|
||||
if a.Preferred != b.Preferred {
|
||||
return a.Preferred == true
|
||||
}
|
||||
return a.NUMANodeAffinity.IsNarrowerThan(b.NUMANodeAffinity)
|
||||
}
|
||||
|
||||
func makeSocketMask(sockets ...int) bitmask.BitMask {
|
||||
mask, _ := bitmask.NewBitMask(sockets...)
|
||||
return mask
|
||||
@ -292,10 +285,10 @@ func TestGetTopologyHints(t *testing.T) {
|
||||
|
||||
for r := range tc.expectedHints {
|
||||
sort.SliceStable(hints[r], func(i, j int) bool {
|
||||
return topologyHintLessThan(hints[r][i], hints[r][j])
|
||||
return hints[r][i].LessThan(hints[r][j])
|
||||
})
|
||||
sort.SliceStable(tc.expectedHints[r], func(i, j int) bool {
|
||||
return topologyHintLessThan(tc.expectedHints[r][i], tc.expectedHints[r][j])
|
||||
return tc.expectedHints[r][i].LessThan(tc.expectedHints[r][j])
|
||||
})
|
||||
if !reflect.DeepEqual(hints[r], tc.expectedHints[r]) {
|
||||
t.Errorf("%v: Expected result to be %v, got %v", tc.description, tc.expectedHints[r], hints[r])
|
||||
|
@ -94,6 +94,27 @@ type TopologyHint struct {
|
||||
Preferred bool
|
||||
}
|
||||
|
||||
// IsEqual checks if TopologyHint are equal
|
||||
func (th *TopologyHint) IsEqual(topologyHint TopologyHint) bool {
|
||||
if th.Preferred == topologyHint.Preferred {
|
||||
if th.NUMANodeAffinity == nil || topologyHint.NUMANodeAffinity == nil {
|
||||
return th.NUMANodeAffinity == topologyHint.NUMANodeAffinity
|
||||
}
|
||||
return th.NUMANodeAffinity.IsEqual(topologyHint.NUMANodeAffinity)
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// LessThan checks if TopologyHint `a` is less than TopologyHint `b`
|
||||
// this means that either `a` is a preferred hint and `b` is not
|
||||
// or `a` NUMANodeAffinity attribute is narrower than `b` NUMANodeAffinity attribute.
|
||||
func (th *TopologyHint) LessThan(other TopologyHint) bool {
|
||||
if th.Preferred != other.Preferred {
|
||||
return th.Preferred == true
|
||||
}
|
||||
return th.NUMANodeAffinity.IsNarrowerThan(other.NUMANodeAffinity)
|
||||
}
|
||||
|
||||
var _ Manager = &manager{}
|
||||
|
||||
//NewManager creates a new TopologyManager based on provided policy
|
||||
|
Loading…
Reference in New Issue
Block a user