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 7e6da97
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 3 deletions.
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
3 changes: 1 addition & 2 deletions website/content/en/docs/getting-started/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,7 @@ metadata:
spec:
provider:
instanceProfile: KarpenterNodeInstanceProfile-${CLUSTER_NAME}
capacityTypes:
- spot
capacityType: spot
cluster:
name: ${CLUSTER_NAME}
endpoint: $(aws eks describe-cluster --name ${CLUSTER_NAME} --query "cluster.endpoint" --output json)
Expand Down

0 comments on commit 7e6da97

Please sign in to comment.