From 7e6da9790229baec61578c4ec44f1d29835a7a5a Mon Sep 17 00:00:00 2001 From: Ellis Tarn Date: Fri, 1 Oct 2021 16:51:49 -0700 Subject: [PATCH] Fixed a bug with the OR operator in Node Affinity --- .../allocation/scheduling/suite_test.go | 38 ++++++++++++++++++- .../content/en/docs/getting-started/_index.md | 3 +- 2 files changed, 38 insertions(+), 3 deletions(-) diff --git a/pkg/controllers/allocation/scheduling/suite_test.go b/pkg/controllers/allocation/scheduling/suite_test.go index fe0c8e073122..a92bc5ea4f2a 100644 --- a/pkg/controllers/allocation/scheduling/suite_test.go +++ b/pkg/controllers/allocation/scheduling/suite_test.go @@ -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) @@ -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() { @@ -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")) + }) }) }) diff --git a/website/content/en/docs/getting-started/_index.md b/website/content/en/docs/getting-started/_index.md index cdfb6a5aed37..80bd6dac1bde 100644 --- a/website/content/en/docs/getting-started/_index.md +++ b/website/content/en/docs/getting-started/_index.md @@ -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)