Merge pull request #43008 from ravisantoshgudimetla/taints_small_changes

Automatic merge from submit-queue (batch tested with PRs 43681, 40423, 43562, 43008, 43381)

Changes for removing deadcode in taint_tolerations

**What this PR does / why we need it**:

**Which issue this PR fixes** *(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)` format, will close that issue when PR gets merged)*: fixes #43007
This commit is contained in:
Kubernetes Submit Queue 2017-03-27 12:49:27 -07:00 committed by GitHub
commit 2d7ecce878
3 changed files with 34 additions and 25 deletions

View File

@ -34,13 +34,10 @@ func PriorityMetadata(pod *v1.Pod, nodeNameToInfo map[string]*schedulercache.Nod
if pod == nil {
return nil
}
tolerations, err := getTolerationListFromPod(pod)
if err != nil {
return nil
}
tolerationsPreferNoSchedule := getAllTolerationPreferNoSchedule(pod.Spec.Tolerations)
return &priorityMetadata{
nonZeroRequest: getNonZeroRequests(pod),
podTolerations: tolerations,
podTolerations: tolerationsPreferNoSchedule,
affinity: schedulercache.ReconcileAffinity(pod),
}
}

View File

@ -27,56 +27,48 @@ import (
// CountIntolerableTaintsPreferNoSchedule gives the count of intolerable taints of a pod with effect PreferNoSchedule
func countIntolerableTaintsPreferNoSchedule(taints []v1.Taint, tolerations []v1.Toleration) (intolerableTaints int) {
for i := range taints {
taint := &taints[i]
for _, taint := range taints {
// check only on taints that have effect PreferNoSchedule
if taint.Effect != v1.TaintEffectPreferNoSchedule {
continue
}
if !v1.TolerationsTolerateTaint(tolerations, taint) {
if !v1.TolerationsTolerateTaint(tolerations, &taint) {
intolerableTaints++
}
}
return
}
// getAllTolerationEffectPreferNoSchedule gets the list of all Toleration with Effect PreferNoSchedule
// getAllTolerationEffectPreferNoSchedule gets the list of all Tolerations with Effect PreferNoSchedule or with no effect.
func getAllTolerationPreferNoSchedule(tolerations []v1.Toleration) (tolerationList []v1.Toleration) {
for i := range tolerations {
toleration := &tolerations[i]
for _, toleration := range tolerations {
// Empty effect means all effects which includes PreferNoSchedule, so we need to collect it as well.
if len(toleration.Effect) == 0 || toleration.Effect == v1.TaintEffectPreferNoSchedule {
tolerationList = append(tolerationList, *toleration)
tolerationList = append(tolerationList, toleration)
}
}
return
}
func getTolerationListFromPod(pod *v1.Pod) ([]v1.Toleration, error) {
return getAllTolerationPreferNoSchedule(pod.Spec.Tolerations), nil
}
// ComputeTaintTolerationPriority prepares the priority list for all the nodes based on the number of intolerable taints on the node
func ComputeTaintTolerationPriorityMap(pod *v1.Pod, meta interface{}, nodeInfo *schedulercache.NodeInfo) (schedulerapi.HostPriority, error) {
node := nodeInfo.Node()
if node == nil {
return schedulerapi.HostPriority{}, fmt.Errorf("node not found")
}
var tolerationList []v1.Toleration
// To hold all the tolerations with Effect PreferNoSchedule
var tolerationsPreferNoSchedule []v1.Toleration
if priorityMeta, ok := meta.(*priorityMetadata); ok {
tolerationList = priorityMeta.podTolerations
tolerationsPreferNoSchedule = priorityMeta.podTolerations
} else {
var err error
tolerationList, err = getTolerationListFromPod(pod)
if err != nil {
return schedulerapi.HostPriority{}, err
}
tolerationsPreferNoSchedule = getAllTolerationPreferNoSchedule(pod.Spec.Tolerations)
}
return schedulerapi.HostPriority{
Host: node.Name,
Score: countIntolerableTaintsPreferNoSchedule(node.Spec.Taints, tolerationList),
Score: countIntolerableTaintsPreferNoSchedule(node.Spec.Taints, tolerationsPreferNoSchedule),
}, nil
}

View File

@ -204,6 +204,26 @@ func TestTaintAndToleration(t *testing.T) {
{Host: "nodeC", Score: 0},
},
},
{
test: "Default behaviour No taints and tolerations, lands on node with no taints",
//pod without tolerations
pod: podWithTolerations([]v1.Toleration{}),
nodes: []*v1.Node{
//Node without taints
nodeWithTaints("nodeA", []v1.Taint{}),
nodeWithTaints("nodeB", []v1.Taint{
{
Key: "cpu-type",
Value: "arm64",
Effect: v1.TaintEffectPreferNoSchedule,
},
}),
},
expectedList: []schedulerapi.HostPriority{
{Host: "nodeA", Score: 10},
{Host: "nodeB", Score: 0},
},
},
}
for _, test := range tests {
nodeNameToInfo := schedulercache.CreateNodeNameToInfoMap(nil, test.nodes)