Fix besteffort pods for conflicting tolerations

Signed-off-by: ravisantoshgudimetla <ravisantoshgudimetla@gmail.com>
k3s-v1.15.3
ravisantoshgudimetla 2019-04-01 17:04:28 -04:00
parent a8cbb22506
commit 82ffd14c0d
2 changed files with 15 additions and 2 deletions

View File

@ -132,8 +132,9 @@ func (p *podTolerationsPlugin) Admit(a admission.Attributes, o admission.ObjectI
},
})
}
pod.Spec.Tolerations = finalTolerations
// Final merge of tolerations irrespective of pod type, if the user while creating pods gives
// conflicting tolerations(with same key+effect), the existing ones should be overwritten by latest one
pod.Spec.Tolerations = tolerations.MergeTolerations(finalTolerations, []api.Toleration{})
return p.Validate(a, o)
}
func (p *podTolerationsPlugin) Validate(a admission.Attributes, o admission.ObjectInterfaces) error {

View File

@ -201,6 +201,18 @@ func TestPodAdmission(t *testing.T) {
admit: true,
testName: "added memoryPressure/DiskPressure for Burstable pod",
},
{
pod: bestEffortPod,
defaultClusterTolerations: []api.Toleration{},
namespaceTolerations: []api.Toleration{},
whitelist: []api.Toleration{},
podTolerations: []api.Toleration{{Key: "testKey", Operator: "Equal", Value: "testValue", Effect: "NoSchedule", TolerationSeconds: nil}, {Key: "testKey", Operator: "Equal", Value: "testValue1", Effect: "NoSchedule", TolerationSeconds: nil}},
mergedTolerations: []api.Toleration{
{Key: "testKey", Operator: "Equal", Value: "testValue1", Effect: "NoSchedule", TolerationSeconds: nil},
},
admit: true,
testName: "Besteffort pod should overwrite for conflicting tolerations",
},
{
pod: guaranteedPod,
defaultClusterTolerations: []api.Toleration{},