Skip to content

Commit

Permalink
Fixed a bug with the OR operator in Node Affinity
Browse files Browse the repository at this point in the history
  • Loading branch information
ellistarn committed Oct 1, 2021
1 parent 7e86f97 commit 5600237
Showing 1 changed file with 37 additions and 1 deletion.
38 changes: 37 additions & 1 deletion pkg/controllers/allocation/scheduling/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,9 @@ var _ = Describe("Preferential Fallback", func() {
{MatchExpressions: []v1.NodeSelectorRequirement{
{Key: v1.LabelTopologyZone, Operator: v1.NodeSelectorOpIn, Values: []string{"test-zone-1"}},
}},
{MatchExpressions: []v1.NodeSelectorRequirement{
{Key: v1.LabelTopologyZone, Operator: v1.NodeSelectorOpIn, Values: []string{"test-zone-2"}}, // OR operator, never get to this one
}},
}}}}
ExpectCreated(env.Client, provisioner)
ExpectCreatedWithStatus(env.Client, pod)
Expand All @@ -416,7 +419,8 @@ var _ = Describe("Preferential Fallback", func() {
// Success
ExpectReconcileSucceeded(ctx, controller, client.ObjectKeyFromObject(provisioner))
pod = ExpectPodExists(env.Client, pod.Name, pod.Namespace)
ExpectNodeExists(env.Client, pod.Spec.NodeName)
node := ExpectNodeExists(env.Client, pod.Spec.NodeName)
Expect(node.Labels).To(HaveKeyWithValue(v1.LabelTopologyZone, "test-zone-1"))
})
})
Context("Preferred", func() {
Expand Down Expand Up @@ -449,6 +453,38 @@ var _ = Describe("Preferential Fallback", func() {
pod = ExpectPodExists(env.Client, pod.Name, pod.Namespace)
ExpectNodeExists(env.Client, pod.Spec.NodeName)
})
It("should relax to use lighter weights", func() {
provisioner.Spec.Zones = []string{"test-zone-1", "test-zone-2"}
pod := test.UnschedulablePod()
pod.Spec.Affinity = &v1.Affinity{NodeAffinity: &v1.NodeAffinity{PreferredDuringSchedulingIgnoredDuringExecution: []v1.PreferredSchedulingTerm{
{
Weight: 100, Preference: v1.NodeSelectorTerm{MatchExpressions: []v1.NodeSelectorRequirement{
{Key: v1.LabelInstanceTypeStable, Operator: v1.NodeSelectorOpIn, Values: []string{"test-zone-3"}},
}},
},
{
Weight: 50, Preference: v1.NodeSelectorTerm{MatchExpressions: []v1.NodeSelectorRequirement{
{Key: v1.LabelTopologyZone, Operator: v1.NodeSelectorOpIn, Values: []string{"test-zone-2"}},
}},
},
{
Weight: 1, Preference: v1.NodeSelectorTerm{MatchExpressions: []v1.NodeSelectorRequirement{ // OR operator, never get to this one
{Key: v1.LabelTopologyZone, Operator: v1.NodeSelectorOpIn, Values: []string{"test-zone-1"}},
}},
},
}}}
ExpectCreated(env.Client, provisioner)
ExpectCreatedWithStatus(env.Client, pod)
// Remove heaviest term
ExpectReconcileSucceeded(ctx, controller, client.ObjectKeyFromObject(provisioner))
pod = ExpectPodExists(env.Client, pod.Name, pod.Namespace)
Expect(pod.Spec.NodeName).To(BeEmpty())
// Success
ExpectReconcileSucceeded(ctx, controller, client.ObjectKeyFromObject(provisioner))
pod = ExpectPodExists(env.Client, pod.Name, pod.Namespace)
node := ExpectNodeExists(env.Client, pod.Spec.NodeName)
Expect(node.Labels).To(HaveKeyWithValue(v1.LabelTopologyZone, "test-zone-2"))
})
})
})

Expand Down

0 comments on commit 5600237

Please sign in to comment.