Change:
<!-- Please use this template while reporting a bug and provide as much info as possible. Not doing so may result in your bug not being addressed in a timely manner. Thanks! If the matter is security related, please disclose it privately via --What happened: Maybe it should be What you expected to happen: How to reproduce it (as minimally and precisely as possible): Anything else we need to know?: Environment: Kubernetes version (use ): Cloud provider or hardware configuration: OS (e.g: ): Kernel (e.g. ): Install tools: Network plugin and version (if this is a network-related bug): Others:
/sig Scheduling
I feel it is a valid error. But need confirmation from sig-scheduling maintainers. ... is it okay if I work on this?
ok
Yeah, this is a bug in preemption
/assign

Discussion:
affinity := pod.Spec.Affinity podNodeName := updatedPod.Spec.NodeName if affinity != nil && len(podNodeName) > 0 { <del> if affinity.PodAffinity == nil { </del> <ins> if affinity.PodAffinity != nil { </ins> affinityTerms, err := getAffinityTerms(pod, schedutil.GetPodAffinityTerms(affinity.PodAffinity)) if err != nil { return fmt.Errorf("error in getting affinity terms of Pod %v: %v", pod.Name, err)

} tests := []struct { <del> name         string pendingPod   *v1.Pod addedPod     *v1.Pod existingPods []*v1.Pod nodes        []*v1.Node services     []*v1.Service </del> <ins> name                 string pendingPod           *v1.Pod addedPod             *v1.Pod existingPods         []*v1.Pod nodes                []*v1.Node services             []*v1.Service expectedAntiAffinity topologyToMatchedTermCount expectedAffinity     topologyToMatchedTermCount </ins> }{ { name: "no affinity exist",

{ObjectMeta: metav1.ObjectMeta{Name: "nodeB", Labels: label2}}, {ObjectMeta: metav1.ObjectMeta{Name: "nodeC", Labels: label3}}, }, <ins> expectedAntiAffinity: topologyToMatchedTermCount{}, expectedAffinity:     topologyToMatchedTermCount{}, </ins> }, { name: "preFilterState anti-affinity terms are updated correctly after adding and removing a pod", pendingPod: &v1.Pod{ ObjectMeta: metav1.ObjectMeta{Name: "pending", Labels: selector1}, <ins> Spec: v1.PodSpec{ Affinity: &v1.Affinity{ PodAntiAffinity: antiAffinityFooBar, }, }, </ins> }, existingPods: []*v1.Pod{ {ObjectMeta: metav1.ObjectMeta{Name: "p1", Labels: selector1},

{ObjectMeta: metav1.ObjectMeta{Name: "nodeB", Labels: label2}}, {ObjectMeta: metav1.ObjectMeta{Name: "nodeC", Labels: label3}}, }, <ins> expectedAntiAffinity: topologyToMatchedTermCount{ {key: "region", value: "r1"}: 2, }, expectedAffinity: topologyToMatchedTermCount{}, </ins> }, { name: "preFilterState anti-affinity terms are updated correctly after adding and removing a pod", pendingPod: &v1.Pod{ ObjectMeta: metav1.ObjectMeta{Name: "pending", Labels: selector1}, <ins> Spec: v1.PodSpec{ Affinity: &v1.Affinity{ PodAntiAffinity: antiAffinityComplex, }, }, </ins> }, existingPods: []*v1.Pod{ {ObjectMeta: metav1.ObjectMeta{Name: "p1", Labels: selector1},

{ObjectMeta: metav1.ObjectMeta{Name: "nodeB", Labels: label2}}, {ObjectMeta: metav1.ObjectMeta{Name: "nodeC", Labels: label3}}, }, <ins> expectedAntiAffinity: topologyToMatchedTermCount{ {key: "region", value: "r1"}: 2, {key: "zone", value: "z11"}:  2, {key: "zone", value: "z21"}:  1, }, expectedAffinity: topologyToMatchedTermCount{}, </ins> }, { name: "preFilterState matching pod affinity and anti-affinity are updated correctly after adding and removing a pod", pendingPod: &v1.Pod{ ObjectMeta: metav1.ObjectMeta{Name: "pending", Labels: selector1}, <ins> Spec: v1.PodSpec{ Affinity: &v1.Affinity{ PodAffinity: affinityComplex, }, }, </ins> }, existingPods: []*v1.Pod{ {ObjectMeta: metav1.ObjectMeta{Name: "p1", Labels: selector1},

{ObjectMeta: metav1.ObjectMeta{Name: "nodeB", Labels: label2}}, {ObjectMeta: metav1.ObjectMeta{Name: "nodeC", Labels: label3}}, }, <ins> expectedAntiAffinity: topologyToMatchedTermCount{}, expectedAffinity: topologyToMatchedTermCount{ {key: "region", value: "r1"}: 2, {key: "zone", value: "z11"}:  2, }, </ins> }, }

t.Errorf("error adding pod to meta: %v", err) } <ins> newState, err := getPreFilterState(cycleState) if err != nil { t.Errorf("failed to get preFilterState from cycleState: %v", err) } if !reflect.DeepEqual(newState.topologyToMatchedAntiAffinityTerms, test.expectedAntiAffinity) { t.Errorf("State is not equal, got: %v, want: %v", newState.topologyToMatchedAntiAffinityTerms, test.expectedAntiAffinity) } if !reflect.DeepEqual(newState.topologyToMatchedAffinityTerms, test.expectedAffinity) { t.Errorf("State is not equal, got: %v, want: %v", newState.topologyToMatchedAffinityTerms, test.expectedAffinity) } </ins> if !reflect.DeepEqual(allPodsState, state) { t.Errorf("State is not equal, got: %v, want: %v", state, allPodsState) }