Pass a list of NUMA nodes to the various TopologyManager policies

This is in preparation for a larger refactoring effort that will add a
'Merge()'  API to the TopologyManager policy API.
This commit is contained in:
Adrian Chiris 2019-11-04 10:10:03 +01:00 committed by Kevin Klues
parent 6fd8a6eb69
commit e72847676f
8 changed files with 56 additions and 45 deletions

View File

@ -20,7 +20,10 @@ import (
"k8s.io/kubernetes/pkg/kubelet/lifecycle"
)
type bestEffortPolicy struct{}
type bestEffortPolicy struct {
//List of NUMA Nodes available on the underlying machine
numaNodes []int
}
var _ Policy = &bestEffortPolicy{}
@ -28,8 +31,8 @@ var _ Policy = &bestEffortPolicy{}
const PolicyBestEffort string = "best-effort"
// NewBestEffortPolicy returns best-effort policy.
func NewBestEffortPolicy() Policy {
return &bestEffortPolicy{}
func NewBestEffortPolicy(numaNodes []int) Policy {
return &bestEffortPolicy{numaNodes: numaNodes}
}
func (p *bestEffortPolicy) Name() string {

View File

@ -39,7 +39,8 @@ func TestPolicyBestEffortCanAdmitPodResult(t *testing.T) {
}
for _, tc := range tcases {
policy := NewBestEffortPolicy()
numaNodes := []int{0, 1}
policy := NewBestEffortPolicy(numaNodes)
result := policy.CanAdmitPodResult(&tc.hint)
if result.Admit != tc.expected {

View File

@ -30,8 +30,8 @@ var _ Policy = &restrictedPolicy{}
const PolicyRestricted string = "restricted"
// NewRestrictedPolicy returns restricted policy.
func NewRestrictedPolicy() Policy {
return &restrictedPolicy{bestEffortPolicy{}}
func NewRestrictedPolicy(numaNodes []int) Policy {
return &restrictedPolicy{bestEffortPolicy{numaNodes: numaNodes}}
}
func (p *restrictedPolicy) Name() string {

View File

@ -39,7 +39,8 @@ func TestPolicyRestrictedCanAdmitPodResult(t *testing.T) {
}
for _, tc := range tcases {
policy := NewRestrictedPolicy()
numaNodes := []int{0, 1}
policy := NewRestrictedPolicy(numaNodes)
result := policy.CanAdmitPodResult(&tc.hint)
if result.Admit != tc.expected {

View File

@ -20,7 +20,10 @@ import (
"k8s.io/kubernetes/pkg/kubelet/lifecycle"
)
type singleNumaNodePolicy struct{}
type singleNumaNodePolicy struct {
//List of NUMA Nodes available on the underlying machine
numaNodes []int
}
var _ Policy = &singleNumaNodePolicy{}
@ -28,8 +31,8 @@ var _ Policy = &singleNumaNodePolicy{}
const PolicySingleNumaNode string = "single-numa-node"
// NewSingleNumaNodePolicy returns single-numa-node policy.
func NewSingleNumaNodePolicy() Policy {
return &singleNumaNodePolicy{}
func NewSingleNumaNodePolicy(numaNodes []int) Policy {
return &singleNumaNodePolicy{numaNodes: numaNodes}
}
func (p *singleNumaNodePolicy) Name() string {

View File

@ -34,7 +34,8 @@ func TestPolicySingleNumaNodeCanAdmitPodResult(t *testing.T) {
}
for _, tc := range tcases {
policy := NewSingleNumaNodePolicy()
numaNodes := []int{0, 1}
policy := NewSingleNumaNodePolicy(numaNodes)
result := policy.CanAdmitPodResult(&tc.hint)
if result.Admit != tc.expected {

View File

@ -120,25 +120,6 @@ var _ Manager = &manager{}
//NewManager creates a new TopologyManager based on provided policy
func NewManager(numaNodeInfo cputopology.NUMANodeInfo, topologyPolicyName string) (Manager, error) {
klog.Infof("[topologymanager] Creating topology manager with %s policy", topologyPolicyName)
var policy Policy
switch topologyPolicyName {
case PolicyNone:
policy = NewNonePolicy()
case PolicyBestEffort:
policy = NewBestEffortPolicy()
case PolicyRestricted:
policy = NewRestrictedPolicy()
case PolicySingleNumaNode:
policy = NewSingleNumaNodePolicy()
default:
return nil, fmt.Errorf("unknown policy: \"%s\"", topologyPolicyName)
}
var numaNodes []int
for node := range numaNodeInfo {
@ -149,6 +130,25 @@ func NewManager(numaNodeInfo cputopology.NUMANodeInfo, topologyPolicyName string
return nil, fmt.Errorf("unsupported on machines with more than %v NUMA Nodes", maxAllowableNUMANodes)
}
var policy Policy
switch topologyPolicyName {
case PolicyNone:
policy = NewNonePolicy()
case PolicyBestEffort:
policy = NewBestEffortPolicy(numaNodes)
case PolicyRestricted:
policy = NewRestrictedPolicy(numaNodes)
case PolicySingleNumaNode:
policy = NewSingleNumaNodePolicy(numaNodes)
default:
return nil, fmt.Errorf("unknown policy: \"%s\"", topologyPolicyName)
}
var hp []HintProvider
pth := make(map[string]map[string]TopologyHint)
pm := make(map[string]string)

View File

@ -658,7 +658,7 @@ func TestCalculateAffinity(t *testing.T) {
},
{
name: "Special cased PolicySingleNumaNode for single NUMA hint generation",
policy: NewSingleNumaNodePolicy(),
policy: NewSingleNumaNodePolicy(numaNodes),
hp: []HintProvider{
&mockHintProvider{
map[string][]TopologyHint{
@ -692,7 +692,7 @@ func TestCalculateAffinity(t *testing.T) {
},
{
name: "Special cased PolicySingleNumaNode with one no-preference provider",
policy: NewSingleNumaNodePolicy(),
policy: NewSingleNumaNodePolicy(numaNodes),
hp: []HintProvider{
&mockHintProvider{
map[string][]TopologyHint{
@ -835,6 +835,8 @@ func TestAddHintProvider(t *testing.T) {
}
func TestAdmit(t *testing.T) {
numaNodes := []int{0, 1}
tcases := []struct {
name string
result lifecycle.PodAdmitResult
@ -860,7 +862,7 @@ func TestAdmit(t *testing.T) {
{
name: "QOSClass set as BestEffort. single-numa-node Policy. No Hints.",
qosClass: v1.PodQOSBestEffort,
policy: NewRestrictedPolicy(),
policy: NewRestrictedPolicy(numaNodes),
hp: []HintProvider{
&mockHintProvider{},
},
@ -869,7 +871,7 @@ func TestAdmit(t *testing.T) {
{
name: "QOSClass set as BestEffort. Restricted Policy. No Hints.",
qosClass: v1.PodQOSBestEffort,
policy: NewRestrictedPolicy(),
policy: NewRestrictedPolicy(numaNodes),
hp: []HintProvider{
&mockHintProvider{},
},
@ -878,7 +880,7 @@ func TestAdmit(t *testing.T) {
{
name: "QOSClass set as Guaranteed. BestEffort Policy. Preferred Affinity.",
qosClass: v1.PodQOSGuaranteed,
policy: NewBestEffortPolicy(),
policy: NewBestEffortPolicy(numaNodes),
hp: []HintProvider{
&mockHintProvider{
map[string][]TopologyHint{
@ -900,7 +902,7 @@ func TestAdmit(t *testing.T) {
{
name: "QOSClass set as Guaranteed. BestEffort Policy. More than one Preferred Affinity.",
qosClass: v1.PodQOSGuaranteed,
policy: NewBestEffortPolicy(),
policy: NewBestEffortPolicy(numaNodes),
hp: []HintProvider{
&mockHintProvider{
map[string][]TopologyHint{
@ -926,7 +928,7 @@ func TestAdmit(t *testing.T) {
{
name: "QOSClass set as Burstable. BestEffort Policy. More than one Preferred Affinity.",
qosClass: v1.PodQOSBurstable,
policy: NewBestEffortPolicy(),
policy: NewBestEffortPolicy(numaNodes),
hp: []HintProvider{
&mockHintProvider{
map[string][]TopologyHint{
@ -952,7 +954,7 @@ func TestAdmit(t *testing.T) {
{
name: "QOSClass set as Guaranteed. BestEffort Policy. No Preferred Affinity.",
qosClass: v1.PodQOSGuaranteed,
policy: NewBestEffortPolicy(),
policy: NewBestEffortPolicy(numaNodes),
hp: []HintProvider{
&mockHintProvider{
map[string][]TopologyHint{
@ -970,7 +972,7 @@ func TestAdmit(t *testing.T) {
{
name: "QOSClass set as Guaranteed. Restricted Policy. Preferred Affinity.",
qosClass: v1.PodQOSGuaranteed,
policy: NewRestrictedPolicy(),
policy: NewRestrictedPolicy(numaNodes),
hp: []HintProvider{
&mockHintProvider{
map[string][]TopologyHint{
@ -992,7 +994,7 @@ func TestAdmit(t *testing.T) {
{
name: "QOSClass set as Burstable. Restricted Policy. Preferred Affinity.",
qosClass: v1.PodQOSBurstable,
policy: NewRestrictedPolicy(),
policy: NewRestrictedPolicy(numaNodes),
hp: []HintProvider{
&mockHintProvider{
map[string][]TopologyHint{
@ -1014,7 +1016,7 @@ func TestAdmit(t *testing.T) {
{
name: "QOSClass set as Guaranteed. Restricted Policy. More than one Preferred affinity.",
qosClass: v1.PodQOSGuaranteed,
policy: NewRestrictedPolicy(),
policy: NewRestrictedPolicy(numaNodes),
hp: []HintProvider{
&mockHintProvider{
map[string][]TopologyHint{
@ -1040,7 +1042,7 @@ func TestAdmit(t *testing.T) {
{
name: "QOSClass set as Burstable. Restricted Policy. More than one Preferred affinity.",
qosClass: v1.PodQOSBurstable,
policy: NewRestrictedPolicy(),
policy: NewRestrictedPolicy(numaNodes),
hp: []HintProvider{
&mockHintProvider{
map[string][]TopologyHint{
@ -1066,7 +1068,7 @@ func TestAdmit(t *testing.T) {
{
name: "QOSClass set as Guaranteed. Restricted Policy. No Preferred affinity.",
qosClass: v1.PodQOSGuaranteed,
policy: NewRestrictedPolicy(),
policy: NewRestrictedPolicy(numaNodes),
hp: []HintProvider{
&mockHintProvider{
map[string][]TopologyHint{
@ -1084,7 +1086,7 @@ func TestAdmit(t *testing.T) {
{
name: "QOSClass set as Burstable. Restricted Policy. No Preferred affinity.",
qosClass: v1.PodQOSBurstable,
policy: NewRestrictedPolicy(),
policy: NewRestrictedPolicy(numaNodes),
hp: []HintProvider{
&mockHintProvider{
map[string][]TopologyHint{
@ -1105,7 +1107,7 @@ func TestAdmit(t *testing.T) {
policy: tc.policy,
podTopologyHints: make(map[string]map[string]TopologyHint),
hintProviders: tc.hp,
numaNodes: []int{0, 1},
numaNodes: numaNodes,
}
pod := &v1.Pod{