Change:
Kubernetes version (use kubectl version): master What happened: Unnecessary always nil return value for function getTolerationListFromPod. What you expected to happen: We need to remove error return value for getTolerationListFromPod function.
/cc
cc

Discussion:
if pod == nil { return nil } <del> tolerations, err := getTolerationListFromPod(pod) if err != nil { return nil } </del> <ins> tolerationsPreferNoSchedule := getAllTolerationPreferNoSchedule(pod.Spec.Tolerations) </ins> return &priorityMetadata{ nonZeroRequest: getNonZeroRequests(pod), <del> podTolerations: tolerations, </del> <ins> podTolerations: tolerationsPreferNoSchedule, </ins> affinity:       schedulercache.ReconcileAffinity(pod), } }

// CountIntolerableTaintsPreferNoSchedule gives the count of intolerable taints of a pod with effect PreferNoSchedule func countIntolerableTaintsPreferNoSchedule(taints []v1.Taint, tolerations []v1.Toleration) (intolerableTaints int) { <del> for i := range taints { taint := &taints[i] </del> <ins> for _, taint := range taints { </ins> // check only on taints that have effect PreferNoSchedule if taint.Effect != v1.TaintEffectPreferNoSchedule { continue } <del> if !v1.TolerationsTolerateTaint(tolerations, taint) { </del> <ins> if !v1.TolerationsTolerateTaint(tolerations, &taint) { </ins> intolerableTaints++ } } return } <del> // getAllTolerationEffectPreferNoSchedule gets the list of all Toleration with Effect PreferNoSchedule </del> <ins> // getAllTolerationEffectPreferNoSchedule gets the list of all Tolerations with Effect PreferNoSchedule or with no effect. </ins> func getAllTolerationPreferNoSchedule(tolerations []v1.Toleration) (tolerationList []v1.Toleration) { <del> for i := range tolerations { toleration := &tolerations[i] </del> <ins> for _, toleration := range tolerations { // Empty effect means all effects which includes PreferNoSchedule, so we need to collect it as well. </ins> if len(toleration.Effect) == 0 || toleration.Effect == v1.TaintEffectPreferNoSchedule { <del> tolerationList = append(tolerationList, *toleration) </del> <ins> tolerationList = append(tolerationList, toleration) </ins> } } return } <del> func getTolerationListFromPod(pod *v1.Pod) ([]v1.Toleration, error) { return getAllTolerationPreferNoSchedule(pod.Spec.Tolerations), nil } </del> // 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") } <del> var tolerationList []v1.Toleration </del> <ins> // To hold all the tolerations with Effect PreferNoSchedule var tolerationsPreferNoSchedule []v1.Toleration </ins> if priorityMeta, ok := meta.(*priorityMetadata); ok { <del> tolerationList = priorityMeta.podTolerations </del> <ins> tolerationsPreferNoSchedule = priorityMeta.podTolerations </ins> } else { <del> var err error tolerationList, err = getTolerationListFromPod(pod) if err != nil { return schedulerapi.HostPriority{}, err } </del> <ins> tolerationsPreferNoSchedule = getAllTolerationPreferNoSchedule(pod.Spec.Tolerations) </ins> } return schedulerapi.HostPriority{ Host:  node.Name, <del> Score: countIntolerableTaintsPreferNoSchedule(node.Spec.Taints, tolerationList), </del> <ins> Score: countIntolerableTaintsPreferNoSchedule(node.Spec.Taints, tolerationsPreferNoSchedule), </ins> }, nil }

{Host: "nodeC", Score: 0}, }, }, <ins> { 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}, }, }, </ins> } for _, test := range tests { nodeNameToInfo := schedulercache.CreateNodeNameToInfoMap(nil, test.nodes)