mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-27 21:47:07 +00:00
Adding taint toleration error reasons
This commit is contained in:
parent
c5982d03cf
commit
22bd26fefb
@ -395,22 +395,37 @@ type taintsFilterFunc func(*v1.Taint) bool
|
|||||||
|
|
||||||
// TolerationsTolerateTaintsWithFilter checks if given tolerations tolerates
|
// TolerationsTolerateTaintsWithFilter checks if given tolerations tolerates
|
||||||
// all the taints that apply to the filter in given taint list.
|
// all the taints that apply to the filter in given taint list.
|
||||||
|
// DEPRECATED: Please use FindMatchingUntoleratedTaint instead.
|
||||||
func TolerationsTolerateTaintsWithFilter(tolerations []v1.Toleration, taints []v1.Taint, applyFilter taintsFilterFunc) bool {
|
func TolerationsTolerateTaintsWithFilter(tolerations []v1.Toleration, taints []v1.Taint, applyFilter taintsFilterFunc) bool {
|
||||||
if len(taints) == 0 {
|
_, isUntolerated := FindMatchingUntoleratedTaint(taints, tolerations, applyFilter)
|
||||||
return true
|
return !isUntolerated
|
||||||
}
|
}
|
||||||
|
|
||||||
for i := range taints {
|
// FindMatchingUntoleratedTaint checks if the given tolerations tolerates
|
||||||
if applyFilter != nil && !applyFilter(&taints[i]) {
|
// all the filtered taints, and returns the first taint without a toleration
|
||||||
|
func FindMatchingUntoleratedTaint(taints []v1.Taint, tolerations []v1.Toleration, inclusionFilter taintsFilterFunc) (v1.Taint, bool) {
|
||||||
|
filteredTaints := getFilteredTaints(taints, inclusionFilter)
|
||||||
|
for _, taint := range filteredTaints {
|
||||||
|
if !TolerationsTolerateTaint(tolerations, &taint) {
|
||||||
|
return taint, true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return v1.Taint{}, false
|
||||||
|
}
|
||||||
|
|
||||||
|
// getFilteredTaints returns a list of taints satisfying the filter predicate
|
||||||
|
func getFilteredTaints(taints []v1.Taint, inclusionFilter taintsFilterFunc) []v1.Taint {
|
||||||
|
if inclusionFilter == nil {
|
||||||
|
return taints
|
||||||
|
}
|
||||||
|
filteredTaints := []v1.Taint{}
|
||||||
|
for _, taint := range taints {
|
||||||
|
if !inclusionFilter(&taint) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
filteredTaints = append(filteredTaints, taint)
|
||||||
if !TolerationsTolerateTaint(tolerations, &taints[i]) {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
return filteredTaints
|
||||||
return true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns true and list of Tolerations matching all Taints if all are tolerated, or false otherwise.
|
// Returns true and list of Tolerations matching all Taints if all are tolerated, or false otherwise.
|
||||||
|
@ -62,14 +62,19 @@ func (pl *TaintToleration) Filter(ctx context.Context, state *framework.CycleSta
|
|||||||
return framework.NewStatus(framework.Error, err.Error())
|
return framework.NewStatus(framework.Error, err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
if v1helper.TolerationsTolerateTaintsWithFilter(pod.Spec.Tolerations, taints, func(t *v1.Taint) bool {
|
filterPredicate := func(t *v1.Taint) bool {
|
||||||
// PodToleratesNodeTaints is only interested in NoSchedule and NoExecute taints.
|
// PodToleratesNodeTaints is only interested in NoSchedule and NoExecute taints.
|
||||||
return t.Effect == v1.TaintEffectNoSchedule || t.Effect == v1.TaintEffectNoExecute
|
return t.Effect == v1.TaintEffectNoSchedule || t.Effect == v1.TaintEffectNoExecute
|
||||||
}) {
|
}
|
||||||
|
|
||||||
|
taint, isUntolerated := v1helper.FindMatchingUntoleratedTaint(taints, pod.Spec.Tolerations, filterPredicate)
|
||||||
|
if !isUntolerated {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
return framework.NewStatus(framework.UnschedulableAndUnresolvable, ErrReasonNotMatch)
|
errReason := fmt.Sprintf("node(s) had taint {%s: %s}, that the pod didn't tolerate",
|
||||||
|
taint.Key, taint.Value)
|
||||||
|
return framework.NewStatus(framework.UnschedulableAndUnresolvable, errReason)
|
||||||
}
|
}
|
||||||
|
|
||||||
// postFilterState computed at PostFilter and used at Score.
|
// postFilterState computed at PostFilter and used at Score.
|
||||||
|
@ -260,7 +260,6 @@ func TestTaintTolerationScore(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestTaintTolerationFilter(t *testing.T) {
|
func TestTaintTolerationFilter(t *testing.T) {
|
||||||
unschedulable := framework.NewStatus(framework.UnschedulableAndUnresolvable, ErrReasonNotMatch)
|
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
pod *v1.Pod
|
pod *v1.Pod
|
||||||
@ -268,10 +267,11 @@ func TestTaintTolerationFilter(t *testing.T) {
|
|||||||
wantStatus *framework.Status
|
wantStatus *framework.Status
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
name: "A pod having no tolerations can't be scheduled onto a node with nonempty taints",
|
name: "A pod having no tolerations can't be scheduled onto a node with nonempty taints",
|
||||||
pod: podWithTolerations("pod1", []v1.Toleration{}),
|
pod: podWithTolerations("pod1", []v1.Toleration{}),
|
||||||
node: nodeWithTaints("nodeA", []v1.Taint{{Key: "dedicated", Value: "user1", Effect: "NoSchedule"}}),
|
node: nodeWithTaints("nodeA", []v1.Taint{{Key: "dedicated", Value: "user1", Effect: "NoSchedule"}}),
|
||||||
wantStatus: unschedulable,
|
wantStatus: framework.NewStatus(framework.UnschedulableAndUnresolvable,
|
||||||
|
"node(s) had taint {dedicated: user1}, that the pod didn't tolerate"),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "A pod which can be scheduled on a dedicated node assigned to user1 with effect NoSchedule",
|
name: "A pod which can be scheduled on a dedicated node assigned to user1 with effect NoSchedule",
|
||||||
@ -279,10 +279,11 @@ func TestTaintTolerationFilter(t *testing.T) {
|
|||||||
node: nodeWithTaints("nodeA", []v1.Taint{{Key: "dedicated", Value: "user1", Effect: "NoSchedule"}}),
|
node: nodeWithTaints("nodeA", []v1.Taint{{Key: "dedicated", Value: "user1", Effect: "NoSchedule"}}),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "A pod which can't be scheduled on a dedicated node assigned to user2 with effect NoSchedule",
|
name: "A pod which can't be scheduled on a dedicated node assigned to user2 with effect NoSchedule",
|
||||||
pod: podWithTolerations("pod1", []v1.Toleration{{Key: "dedicated", Operator: "Equal", Value: "user2", Effect: "NoSchedule"}}),
|
pod: podWithTolerations("pod1", []v1.Toleration{{Key: "dedicated", Operator: "Equal", Value: "user2", Effect: "NoSchedule"}}),
|
||||||
node: nodeWithTaints("nodeA", []v1.Taint{{Key: "dedicated", Value: "user1", Effect: "NoSchedule"}}),
|
node: nodeWithTaints("nodeA", []v1.Taint{{Key: "dedicated", Value: "user1", Effect: "NoSchedule"}}),
|
||||||
wantStatus: unschedulable,
|
wantStatus: framework.NewStatus(framework.UnschedulableAndUnresolvable,
|
||||||
|
"node(s) had taint {dedicated: user1}, that the pod didn't tolerate"),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "A pod can be scheduled onto the node, with a toleration uses operator Exists that tolerates the taints on the node",
|
name: "A pod can be scheduled onto the node, with a toleration uses operator Exists that tolerates the taints on the node",
|
||||||
@ -303,9 +304,10 @@ func TestTaintTolerationFilter(t *testing.T) {
|
|||||||
{
|
{
|
||||||
name: "A pod has a toleration that keys and values match the taint on the node, but (non-empty) effect doesn't match, " +
|
name: "A pod has a toleration that keys and values match the taint on the node, but (non-empty) effect doesn't match, " +
|
||||||
"can't be scheduled onto the node",
|
"can't be scheduled onto the node",
|
||||||
pod: podWithTolerations("pod1", []v1.Toleration{{Key: "foo", Operator: "Equal", Value: "bar", Effect: "PreferNoSchedule"}}),
|
pod: podWithTolerations("pod1", []v1.Toleration{{Key: "foo", Operator: "Equal", Value: "bar", Effect: "PreferNoSchedule"}}),
|
||||||
node: nodeWithTaints("nodeA", []v1.Taint{{Key: "foo", Value: "bar", Effect: "NoSchedule"}}),
|
node: nodeWithTaints("nodeA", []v1.Taint{{Key: "foo", Value: "bar", Effect: "NoSchedule"}}),
|
||||||
wantStatus: unschedulable,
|
wantStatus: framework.NewStatus(framework.UnschedulableAndUnresolvable,
|
||||||
|
"node(s) had taint {foo: bar}, that the pod didn't tolerate"),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "The pod has a toleration that keys and values match the taint on the node, the effect of toleration is empty, " +
|
name: "The pod has a toleration that keys and values match the taint on the node, the effect of toleration is empty, " +
|
||||||
@ -315,13 +317,13 @@ func TestTaintTolerationFilter(t *testing.T) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "The pod has a toleration that key and value don't match the taint on the node, " +
|
name: "The pod has a toleration that key and value don't match the taint on the node, " +
|
||||||
"but the effect of taint on node is PreferNochedule. Pod can be scheduled onto the node",
|
"but the effect of taint on node is PreferNoSchedule. Pod can be scheduled onto the node",
|
||||||
pod: podWithTolerations("pod1", []v1.Toleration{{Key: "dedicated", Operator: "Equal", Value: "user2", Effect: "NoSchedule"}}),
|
pod: podWithTolerations("pod1", []v1.Toleration{{Key: "dedicated", Operator: "Equal", Value: "user2", Effect: "NoSchedule"}}),
|
||||||
node: nodeWithTaints("nodeA", []v1.Taint{{Key: "dedicated", Value: "user1", Effect: "PreferNoSchedule"}}),
|
node: nodeWithTaints("nodeA", []v1.Taint{{Key: "dedicated", Value: "user1", Effect: "PreferNoSchedule"}}),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "The pod has no toleration, " +
|
name: "The pod has no toleration, " +
|
||||||
"but the effect of taint on node is PreferNochedule. Pod can be scheduled onto the node",
|
"but the effect of taint on node is PreferNoSchedule. Pod can be scheduled onto the node",
|
||||||
pod: podWithTolerations("pod1", []v1.Toleration{}),
|
pod: podWithTolerations("pod1", []v1.Toleration{}),
|
||||||
node: nodeWithTaints("nodeA", []v1.Taint{{Key: "dedicated", Value: "user1", Effect: "PreferNoSchedule"}}),
|
node: nodeWithTaints("nodeA", []v1.Taint{{Key: "dedicated", Value: "user1", Effect: "PreferNoSchedule"}}),
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user