mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-25 04:33:26 +00:00
Refactor filterHints:
- Restructure function - Remove bug fix for catching {nil true} - To be fixed in later commit - Restore unit tests to original state for testing filterHints
This commit is contained in:
parent
adfd11f38f
commit
5487941485
@ -71,34 +71,20 @@ func (p *singleNumaNodePolicy) mergePermutation(permutation []TopologyHint) Topo
|
|||||||
return TopologyHint{mergedAffinity, preferred}
|
return TopologyHint{mergedAffinity, preferred}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return hints that have valid bitmasks with exactly one bit set. Also return bool
|
// Return hints that have valid bitmasks with exactly one bit set.
|
||||||
// which indicates whether allResourceHints only consists of {nil true} hints.
|
func (p *singleNumaNodePolicy) filterHints(allResourcesHints [][]TopologyHint) [][]TopologyHint {
|
||||||
func (p *singleNumaNodePolicy) filterHints(allResourcesHints [][]TopologyHint) ([][]TopologyHint, bool) {
|
|
||||||
var filteredResourcesHints [][]TopologyHint
|
var filteredResourcesHints [][]TopologyHint
|
||||||
var noAffinityPreferredHints int
|
for _, oneResourceHints := range allResourcesHints {
|
||||||
var totalHints int
|
var filtered []TopologyHint
|
||||||
if len(allResourcesHints) > 0 {
|
for _, hint := range oneResourceHints {
|
||||||
for _, oneResourceHints := range allResourcesHints {
|
if hint.NUMANodeAffinity != nil && hint.NUMANodeAffinity.Count() == 1 && hint.Preferred == true {
|
||||||
var filtered []TopologyHint
|
filtered = append(filtered, hint)
|
||||||
if len(oneResourceHints) > 0 {
|
|
||||||
for _, hint := range oneResourceHints {
|
|
||||||
totalHints++
|
|
||||||
if hint.NUMANodeAffinity != nil && hint.NUMANodeAffinity.Count() == 1 && hint.Preferred == true {
|
|
||||||
filtered = append(filtered, hint)
|
|
||||||
}
|
|
||||||
if hint.NUMANodeAffinity == nil && hint.Preferred == true {
|
|
||||||
noAffinityPreferredHints++
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
filteredResourcesHints = append(filteredResourcesHints, filtered)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
filteredResourcesHints = append(filteredResourcesHints, filtered)
|
||||||
}
|
}
|
||||||
// Check if all resource hints only consist of nil-affinity/preferred hint: {nil true}.
|
return filteredResourcesHints
|
||||||
if noAffinityPreferredHints == totalHints {
|
|
||||||
return filteredResourcesHints, true
|
|
||||||
}
|
|
||||||
return filteredResourcesHints, false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *singleNumaNodePolicy) mergeProvidersHints(providersHints []map[string][]TopologyHint) TopologyHint {
|
func (p *singleNumaNodePolicy) mergeProvidersHints(providersHints []map[string][]TopologyHint) TopologyHint {
|
||||||
@ -139,24 +125,17 @@ func (p *singleNumaNodePolicy) mergeProvidersHints(providersHints []map[string][
|
|||||||
return TopologyHint{nil, true}
|
return TopologyHint{nil, true}
|
||||||
}
|
}
|
||||||
|
|
||||||
var noAffinityPreferredOnly bool
|
allResourcesHints = p.filterHints(allResourcesHints)
|
||||||
allResourcesHints, noAffinityPreferredOnly = p.filterHints(allResourcesHints)
|
// If no hints, or there is a resource with empty hints after filtering, then policy
|
||||||
// If no hints, then policy cannot be satisfied
|
// cannot be satisfied
|
||||||
if len(allResourcesHints) == 0 {
|
if len(allResourcesHints) == 0 {
|
||||||
klog.Infof("[topologymanager] No hints that align to a single NUMA node.")
|
klog.Infof("[topologymanager] No hints that align to a single NUMA node.")
|
||||||
return TopologyHint{}
|
return TopologyHint{}
|
||||||
}
|
}
|
||||||
// If there is a resource with empty hints after filtering, then policy cannot be satisfied.
|
|
||||||
// In the event that the only hints that exist are {nil true} update default hint preferred
|
|
||||||
// to allow scheduling.
|
|
||||||
for _, hints := range allResourcesHints {
|
for _, hints := range allResourcesHints {
|
||||||
if len(hints) == 0 {
|
if len(hints) == 0 {
|
||||||
klog.Infof("[topologymanager] No hints that align to a single NUMA node for resource.")
|
klog.Infof("[topologymanager] No hints that align to a single NUMA node for resource.")
|
||||||
if !noAffinityPreferredOnly {
|
return TopologyHint{}
|
||||||
return TopologyHint{}
|
|
||||||
} else if noAffinityPreferredOnly {
|
|
||||||
return TopologyHint{nil, true}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -59,45 +59,18 @@ func TestPolicySingleNumaNodeFilterHints(t *testing.T) {
|
|||||||
name string
|
name string
|
||||||
allResources [][]TopologyHint
|
allResources [][]TopologyHint
|
||||||
expectedResources [][]TopologyHint
|
expectedResources [][]TopologyHint
|
||||||
expectedExists bool
|
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
name: "filter empty resources",
|
name: "filter empty resources",
|
||||||
allResources: [][]TopologyHint{},
|
allResources: [][]TopologyHint{},
|
||||||
expectedResources: [][]TopologyHint(nil),
|
expectedResources: [][]TopologyHint(nil),
|
||||||
expectedExists: false,
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "filter hints with nil socket mask, preferred true",
|
name: "filter hints with nil socket mask 1/2",
|
||||||
allResources: [][]TopologyHint{
|
|
||||||
{
|
|
||||||
{NUMANodeAffinity: nil, Preferred: true},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
expectedResources: [][]TopologyHint{
|
|
||||||
[]TopologyHint(nil),
|
|
||||||
},
|
|
||||||
expectedExists: true,
|
|
||||||
},
|
|
||||||
|
|
||||||
{
|
|
||||||
name: "filter hints with nil socket mask, preferred false",
|
|
||||||
allResources: [][]TopologyHint{
|
allResources: [][]TopologyHint{
|
||||||
{
|
{
|
||||||
{NUMANodeAffinity: nil, Preferred: false},
|
{NUMANodeAffinity: nil, Preferred: false},
|
||||||
},
|
},
|
||||||
},
|
|
||||||
expectedResources: [][]TopologyHint{
|
|
||||||
[]TopologyHint(nil),
|
|
||||||
},
|
|
||||||
expectedExists: false,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "filter hints with nil socket mask, preferred both true",
|
|
||||||
allResources: [][]TopologyHint{
|
|
||||||
{
|
|
||||||
{NUMANodeAffinity: nil, Preferred: true},
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
{NUMANodeAffinity: nil, Preferred: true},
|
{NUMANodeAffinity: nil, Preferred: true},
|
||||||
},
|
},
|
||||||
@ -106,43 +79,9 @@ func TestPolicySingleNumaNodeFilterHints(t *testing.T) {
|
|||||||
[]TopologyHint(nil),
|
[]TopologyHint(nil),
|
||||||
[]TopologyHint(nil),
|
[]TopologyHint(nil),
|
||||||
},
|
},
|
||||||
expectedExists: true,
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "filter hints with nil socket mask, preferred both false",
|
name: "filter hints with nil socket mask 2/2",
|
||||||
allResources: [][]TopologyHint{
|
|
||||||
{
|
|
||||||
{NUMANodeAffinity: nil, Preferred: false},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
{NUMANodeAffinity: nil, Preferred: false},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
expectedResources: [][]TopologyHint{
|
|
||||||
[]TopologyHint(nil),
|
|
||||||
[]TopologyHint(nil),
|
|
||||||
},
|
|
||||||
expectedExists: false,
|
|
||||||
},
|
|
||||||
|
|
||||||
{
|
|
||||||
name: "filter hints with nil socket mask, preferred true and false",
|
|
||||||
allResources: [][]TopologyHint{
|
|
||||||
{
|
|
||||||
{NUMANodeAffinity: nil, Preferred: true},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
{NUMANodeAffinity: nil, Preferred: false},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
expectedResources: [][]TopologyHint{
|
|
||||||
[]TopologyHint(nil),
|
|
||||||
[]TopologyHint(nil),
|
|
||||||
},
|
|
||||||
expectedExists: false,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "filter hints with nil socket mask",
|
|
||||||
allResources: [][]TopologyHint{
|
allResources: [][]TopologyHint{
|
||||||
{
|
{
|
||||||
{NUMANodeAffinity: NewTestBitMask(0), Preferred: true},
|
{NUMANodeAffinity: NewTestBitMask(0), Preferred: true},
|
||||||
@ -161,7 +100,6 @@ func TestPolicySingleNumaNodeFilterHints(t *testing.T) {
|
|||||||
{NUMANodeAffinity: NewTestBitMask(1), Preferred: true},
|
{NUMANodeAffinity: NewTestBitMask(1), Preferred: true},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
expectedExists: false,
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "filter hints with empty resource socket mask",
|
name: "filter hints with empty resource socket mask",
|
||||||
@ -180,7 +118,6 @@ func TestPolicySingleNumaNodeFilterHints(t *testing.T) {
|
|||||||
},
|
},
|
||||||
[]TopologyHint(nil),
|
[]TopologyHint(nil),
|
||||||
},
|
},
|
||||||
expectedExists: false,
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "filter hints with wide sockemask",
|
name: "filter hints with wide sockemask",
|
||||||
@ -212,22 +149,17 @@ func TestPolicySingleNumaNodeFilterHints(t *testing.T) {
|
|||||||
[]TopologyHint(nil),
|
[]TopologyHint(nil),
|
||||||
[]TopologyHint(nil),
|
[]TopologyHint(nil),
|
||||||
},
|
},
|
||||||
expectedExists: false,
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
numaNodes := []int{0, 1, 2, 3}
|
numaNodes := []int{0, 1, 2, 3}
|
||||||
for _, tc := range tcases {
|
for _, tc := range tcases {
|
||||||
policy := NewSingleNumaNodePolicy(numaNodes)
|
policy := NewSingleNumaNodePolicy(numaNodes)
|
||||||
actual, exists := policy.(*singleNumaNodePolicy).filterHints(tc.allResources)
|
actual := policy.(*singleNumaNodePolicy).filterHints(tc.allResources)
|
||||||
if !reflect.DeepEqual(tc.expectedResources, actual) {
|
if !reflect.DeepEqual(tc.expectedResources, actual) {
|
||||||
t.Errorf("Test Case: %s", tc.name)
|
t.Errorf("Test Case: %s", tc.name)
|
||||||
t.Errorf("Expected result to be %v, got %v", tc.expectedResources, actual)
|
t.Errorf("Expected result to be %v, got %v", tc.expectedResources, actual)
|
||||||
}
|
}
|
||||||
if !reflect.DeepEqual(tc.expectedResources, actual) {
|
|
||||||
t.Errorf("Test Case: %s", tc.name)
|
|
||||||
t.Errorf("Expected result to be %v, got %v", tc.expectedExists, exists)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user