Merge pull request #75985 from ravisantoshgudimetla/fix-pod-toleration

Fix besteffort pods for conflicting tolerations
k3s-v1.15.3
Kubernetes Prow Robot 2019-04-05 07:43:20 -07:00 committed by GitHub
commit 16db83b257
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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{},