Skip to content

Commit

Permalink
update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jmdeal committed Dec 11, 2023
1 parent e729c4a commit b23a605
Showing 1 changed file with 114 additions and 1 deletion.
115 changes: 114 additions & 1 deletion pkg/controllers/provisioning/scheduling/topology_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1319,9 +1319,123 @@ var _ = Describe("Topology", func() {
// and should schedule all of the pods on the same node
ExpectSkew(ctx, env.Client, "default", &topology[0]).To(ConsistOf(5))
})
It("should balance pods across a label when discovered from the provisioner (NodeTaintsPolicy=ignore)", func() {
const spreadLabel = "fake-label"
const taintKey = "taint-key"
nodePool.Spec.Template.Spec.Requirements = append(nodePool.Spec.Template.Spec.Requirements, v1.NodeSelectorRequirement{
Key: spreadLabel,
Operator: v1.NodeSelectorOpIn,
Values: []string{"foo"},
})
taintedNodePool := test.NodePool(v1beta1.NodePool{
Spec: v1beta1.NodePoolSpec{
Template: v1beta1.NodeClaimTemplate{
Spec: v1beta1.NodeClaimSpec{
Taints: []v1.Taint{
{
Key: taintKey,
Value: "taint-value",
Effect: v1.TaintEffectNoSchedule,
},
},
Requirements: []v1.NodeSelectorRequirement{
{
Key: v1beta1.CapacityTypeLabelKey,
Operator: v1.NodeSelectorOpExists,
},
{
Key: spreadLabel,
Operator: v1.NodeSelectorOpIn,
Values: []string{"bar"},
},
},
},
},
},
})

honor := v1.NodeInclusionPolicyIgnore
topology := []v1.TopologySpreadConstraint{{
TopologyKey: spreadLabel,
WhenUnsatisfiable: v1.DoNotSchedule,
LabelSelector: &metav1.LabelSelector{MatchLabels: labels},
MaxSkew: 1,
NodeTaintsPolicy: &honor,
}}

pods := test.UnschedulablePods(test.PodOptions{
ObjectMeta: metav1.ObjectMeta{
Labels: labels,
},
TopologySpreadConstraints: topology,
}, 2)

ExpectApplied(ctx, env.Client, nodePool, taintedNodePool)
ExpectProvisioned(ctx, env.Client, cluster, cloudProvider, prov, pods...)

// should fail to schedule both pods, one pod is scheduled to domain "foo" but the other can't be scheduled to domain "bar"
ExpectSkew(ctx, env.Client, "default", &topology[0]).To(ConsistOf(1))
})
It("should balance pods across a label when discovered from the provisioner (NodeTaintsPolicy=honor)", func() {
const spreadLabel = "fake-label"
const taintKey = "taint-key"
nodePool.Spec.Template.Spec.Requirements = append(nodePool.Spec.Template.Spec.Requirements, v1.NodeSelectorRequirement{
Key: spreadLabel,
Operator: v1.NodeSelectorOpIn,
Values: []string{"foo"},
})
taintedNodePool := test.NodePool(v1beta1.NodePool{
Spec: v1beta1.NodePoolSpec{
Template: v1beta1.NodeClaimTemplate{
Spec: v1beta1.NodeClaimSpec{
Taints: []v1.Taint{
{
Key: taintKey,
Value: "taint-value",
Effect: v1.TaintEffectNoSchedule,
},
},
Requirements: []v1.NodeSelectorRequirement{
{
Key: v1beta1.CapacityTypeLabelKey,
Operator: v1.NodeSelectorOpExists,
},
{
Key: spreadLabel,
Operator: v1.NodeSelectorOpIn,
Values: []string{"bar"},
},
},
},
},
},
})

honor := v1.NodeInclusionPolicyHonor
topology := []v1.TopologySpreadConstraint{{
TopologyKey: spreadLabel,
WhenUnsatisfiable: v1.DoNotSchedule,
LabelSelector: &metav1.LabelSelector{MatchLabels: labels},
MaxSkew: 1,
NodeTaintsPolicy: &honor,
}}

pods := test.UnschedulablePods(test.PodOptions{
ObjectMeta: metav1.ObjectMeta{
Labels: labels,
},
TopologySpreadConstraints: topology,
}, 2)

ExpectApplied(ctx, env.Client, nodePool, taintedNodePool)
ExpectProvisioned(ctx, env.Client, cluster, cloudProvider, prov, pods...)

// should schedule all pods to domain "foo", ignoring bar since pods don't tolerate
ExpectSkew(ctx, env.Client, "default", &topology[0]).To(ConsistOf(2))
})
It("should balance pods across a label when mutually exclusive NodePools (by taints) share domains (NodeTaintsPolicy=honor)", func() {
const spreadLabel = "fake-label"
const taintKey = "taint-key"

nodePools := lo.Map([][]string{{"foo", "bar"}, {"foo", "baz"}}, func(domains []string, i int) *v1beta1.NodePool {
return test.NodePool(v1beta1.NodePool{
Expand Down Expand Up @@ -1377,7 +1491,6 @@ var _ = Describe("Topology", func() {

ExpectApplied(ctx, env.Client, nodePools[0], nodePools[1])
ExpectProvisioned(ctx, env.Client, cluster, cloudProvider, prov, pods...)
ExpectScheduled(ctx, env.Client, pods[0])

// Expect 3 total nodes provisioned, 2 pods schedule to foo, 1 to bar, and 1 to baz
ExpectSkew(ctx, env.Client, "default", &topology[0]).To(ConsistOf(1, 2, 1))
Expand Down

0 comments on commit b23a605

Please sign in to comment.