
Before this fix, hint permutations such as: permutation: [{11 true} {0101 true}] Could result in merged hints of: mergedHint: {01 true} This was possible because both hints in the permutation container a "preferred" allocation (i.e. the full set of NUMA nodes set in the affinity bitmask are *required* to satisfy the allocation). With this in place, the simplified logic we had simply kept the merged hint as preferred as well. However, what we really want is to ensure that the merged hint is only preferred if *true* alignment of all resources is possible (i.e. if all hints in the permutation are preferred AND their affinities are exactly equal). The only exception to this is if *no* topology information is provided by a given hint provider. In this case, we assume alignment doesn't matter and only consider the resources that actually have hints provided for them. This changes the semantics of permutations of the form: permutation: [{111 true} {011 true}] To now result in the merged hint of: mergedHint: {011 false} Instead of: mergedHint: {011 true} This is arguably how it should always have been though (because a hint should not be preferred if true alignment isn't possible), and two tests have had to change to accomodate these new semantics. This commit changes the merge function to implement the updated logic, adds a test to verify it is functioning correctly, and updates the two tests mentioned above to adjust to the new semantics. Signed-off-by: Kevin Klues <kklues@nvidia.com>
167 lines
4.5 KiB
Go
167 lines
4.5 KiB
Go
/*
|
|
Copyright 2019 The Kubernetes Authors.
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
you may not use this file except in compliance with the License.
|
|
You may obtain a copy of the License at
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
See the License for the specific language governing permissions and
|
|
limitations under the License.
|
|
*/
|
|
|
|
package topologymanager
|
|
|
|
import (
|
|
"reflect"
|
|
"testing"
|
|
)
|
|
|
|
func TestPolicySingleNumaNodeCanAdmitPodResult(t *testing.T) {
|
|
tcases := []struct {
|
|
name string
|
|
hint TopologyHint
|
|
expected bool
|
|
}{
|
|
{
|
|
name: "Preferred is set to false in topology hints",
|
|
hint: TopologyHint{nil, false},
|
|
expected: false,
|
|
},
|
|
}
|
|
|
|
for _, tc := range tcases {
|
|
numaNodes := []int{0, 1}
|
|
policy := NewSingleNumaNodePolicy(numaNodes)
|
|
result := policy.(*singleNumaNodePolicy).canAdmitPodResult(&tc.hint)
|
|
|
|
if result != tc.expected {
|
|
t.Errorf("Expected result to be %t, got %t", tc.expected, result)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestPolicySingleNumaNodeFilterHints(t *testing.T) {
|
|
tcases := []struct {
|
|
name string
|
|
allResources [][]TopologyHint
|
|
expectedResources [][]TopologyHint
|
|
}{
|
|
{
|
|
name: "filter empty resources",
|
|
allResources: [][]TopologyHint{},
|
|
expectedResources: [][]TopologyHint(nil),
|
|
},
|
|
{
|
|
name: "filter hints with nil socket mask 1/2",
|
|
allResources: [][]TopologyHint{
|
|
{
|
|
{NUMANodeAffinity: nil, Preferred: false},
|
|
},
|
|
{
|
|
{NUMANodeAffinity: nil, Preferred: true},
|
|
},
|
|
},
|
|
expectedResources: [][]TopologyHint{
|
|
[]TopologyHint(nil),
|
|
{
|
|
{NUMANodeAffinity: nil, Preferred: true},
|
|
},
|
|
},
|
|
},
|
|
{
|
|
name: "filter hints with nil socket mask 2/2",
|
|
allResources: [][]TopologyHint{
|
|
{
|
|
{NUMANodeAffinity: NewTestBitMask(0), Preferred: true},
|
|
{NUMANodeAffinity: nil, Preferred: false},
|
|
},
|
|
{
|
|
{NUMANodeAffinity: NewTestBitMask(1), Preferred: true},
|
|
{NUMANodeAffinity: nil, Preferred: true},
|
|
},
|
|
},
|
|
expectedResources: [][]TopologyHint{
|
|
{
|
|
{NUMANodeAffinity: NewTestBitMask(0), Preferred: true},
|
|
},
|
|
{
|
|
{NUMANodeAffinity: NewTestBitMask(1), Preferred: true},
|
|
{NUMANodeAffinity: nil, Preferred: true},
|
|
},
|
|
},
|
|
},
|
|
{
|
|
name: "filter hints with empty resource socket mask",
|
|
allResources: [][]TopologyHint{
|
|
{
|
|
{NUMANodeAffinity: NewTestBitMask(1), Preferred: true},
|
|
{NUMANodeAffinity: NewTestBitMask(0), Preferred: true},
|
|
{NUMANodeAffinity: nil, Preferred: false},
|
|
},
|
|
{},
|
|
},
|
|
expectedResources: [][]TopologyHint{
|
|
{
|
|
{NUMANodeAffinity: NewTestBitMask(1), Preferred: true},
|
|
{NUMANodeAffinity: NewTestBitMask(0), Preferred: true},
|
|
},
|
|
[]TopologyHint(nil),
|
|
},
|
|
},
|
|
{
|
|
name: "filter hints with wide sockemask",
|
|
allResources: [][]TopologyHint{
|
|
{
|
|
{NUMANodeAffinity: NewTestBitMask(0), Preferred: true},
|
|
{NUMANodeAffinity: NewTestBitMask(1), Preferred: true},
|
|
{NUMANodeAffinity: NewTestBitMask(1, 2), Preferred: false},
|
|
{NUMANodeAffinity: NewTestBitMask(0, 1, 2), Preferred: false},
|
|
{NUMANodeAffinity: nil, Preferred: false},
|
|
},
|
|
{
|
|
{NUMANodeAffinity: NewTestBitMask(1, 2), Preferred: false},
|
|
{NUMANodeAffinity: NewTestBitMask(0, 1, 2), Preferred: false},
|
|
{NUMANodeAffinity: NewTestBitMask(0, 2), Preferred: false},
|
|
{NUMANodeAffinity: NewTestBitMask(3), Preferred: false},
|
|
},
|
|
{
|
|
{NUMANodeAffinity: NewTestBitMask(1, 2), Preferred: false},
|
|
{NUMANodeAffinity: NewTestBitMask(0, 1, 2), Preferred: false},
|
|
{NUMANodeAffinity: NewTestBitMask(0, 2), Preferred: false},
|
|
},
|
|
},
|
|
expectedResources: [][]TopologyHint{
|
|
{
|
|
{NUMANodeAffinity: NewTestBitMask(0), Preferred: true},
|
|
{NUMANodeAffinity: NewTestBitMask(1), Preferred: true},
|
|
},
|
|
[]TopologyHint(nil),
|
|
[]TopologyHint(nil),
|
|
},
|
|
},
|
|
}
|
|
|
|
for _, tc := range tcases {
|
|
actual := filterSingleNumaHints(tc.allResources)
|
|
if !reflect.DeepEqual(tc.expectedResources, actual) {
|
|
t.Errorf("Test Case: %s", tc.name)
|
|
t.Errorf("Expected result to be %v, got %v", tc.expectedResources, actual)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestPolicySingleNumaNodeMerge(t *testing.T) {
|
|
numaNodes := []int{0, 1, 2, 3}
|
|
policy := NewSingleNumaNodePolicy(numaNodes)
|
|
|
|
tcases := commonPolicyMergeTestCases(numaNodes)
|
|
tcases = append(tcases, policy.(*singleNumaNodePolicy).mergeTestCases(numaNodes)...)
|
|
|
|
testPolicyMerge(policy, tcases, t)
|
|
}
|