Allow toleration updates via pod spec.
This commit is contained in:
@@ -1848,6 +1848,29 @@ func validateTaintEffect(effect *api.TaintEffect, allowEmpty bool, fldPath *fiel
|
||||
return allErrors
|
||||
}
|
||||
|
||||
// validateOnlyAddedTolerations validates updated pod tolerations.
|
||||
func validateOnlyAddedTolerations(newTolerations []api.Toleration, oldTolerations []api.Toleration, fldPath *field.Path) field.ErrorList {
|
||||
allErrs := field.ErrorList{}
|
||||
for _, old := range oldTolerations {
|
||||
found := false
|
||||
old.TolerationSeconds = nil
|
||||
for _, new := range newTolerations {
|
||||
new.TolerationSeconds = nil
|
||||
if reflect.DeepEqual(old, new) {
|
||||
found = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if !found {
|
||||
allErrs = append(allErrs, field.Forbidden(fldPath, "existing toleration can not be modified except its tolerationSeconds"))
|
||||
return allErrs
|
||||
}
|
||||
}
|
||||
|
||||
allErrs = append(allErrs, validateTolerations(newTolerations, fldPath)...)
|
||||
return allErrs
|
||||
}
|
||||
|
||||
// validateTolerations tests if given tolerations have valid data.
|
||||
func validateTolerations(tolerations []api.Toleration, fldPath *field.Path) field.ErrorList {
|
||||
allErrors := field.ErrorList{}
|
||||
@@ -2348,9 +2371,14 @@ func ValidatePodUpdate(newPod, oldPod *api.Pod) field.ErrorList {
|
||||
activeDeadlineSeconds := *oldPod.Spec.ActiveDeadlineSeconds
|
||||
mungedPod.Spec.ActiveDeadlineSeconds = &activeDeadlineSeconds
|
||||
}
|
||||
|
||||
// Allow only additions to tolerations updates.
|
||||
mungedPod.Spec.Tolerations = oldPod.Spec.Tolerations
|
||||
allErrs = append(allErrs, validateOnlyAddedTolerations(newPod.Spec.Tolerations, oldPod.Spec.Tolerations, specPath.Child("tolerations"))...)
|
||||
|
||||
if !apiequality.Semantic.DeepEqual(mungedPod.Spec, oldPod.Spec) {
|
||||
//TODO: Pinpoint the specific field that causes the invalid error after we have strategic merge diff
|
||||
allErrs = append(allErrs, field.Forbidden(specPath, "pod updates may not change fields other than `containers[*].image` or `spec.activeDeadlineSeconds`"))
|
||||
allErrs = append(allErrs, field.Forbidden(specPath, "pod updates may not change fields other than `containers[*].image` or `spec.activeDeadlineSeconds` or `spec.tolerations` (only additions to existing tolerations)"))
|
||||
}
|
||||
|
||||
return allErrs
|
||||
|
Reference in New Issue
Block a user