remove pod toleration toleration seconds mutation

This commit is contained in:
David Eads
2021-02-15 17:33:34 -05:00
parent 5570a81040
commit 5130ea0da3

View File

@@ -3100,10 +3100,11 @@ func validateOnlyAddedTolerations(newTolerations []core.Toleration, oldToleratio
allErrs := field.ErrorList{} allErrs := field.ErrorList{}
for _, old := range oldTolerations { for _, old := range oldTolerations {
found := false found := false
old.TolerationSeconds = nil oldTolerationClone := old.DeepCopy()
for _, new := range newTolerations { for _, newToleration := range newTolerations {
new.TolerationSeconds = nil // assign to our clone before doing a deep equal so we can allow tolerationseconds to change.
if reflect.DeepEqual(old, new) { oldTolerationClone.TolerationSeconds = newToleration.TolerationSeconds // +k8s:verify-mutation:reason=clone
if reflect.DeepEqual(*oldTolerationClone, newToleration) {
found = true found = true
break break
} }
@@ -3987,6 +3988,9 @@ func ValidatePodUpdate(newPod, oldPod *core.Pod, opts PodValidationOptions) fiel
allErrs = append(allErrs, field.Invalid(specPath.Child("activeDeadlineSeconds"), newPod.Spec.ActiveDeadlineSeconds, "must not update from a positive integer to nil value")) allErrs = append(allErrs, field.Invalid(specPath.Child("activeDeadlineSeconds"), newPod.Spec.ActiveDeadlineSeconds, "must not update from a positive integer to nil value"))
} }
// Allow only additions to tolerations updates.
allErrs = append(allErrs, validateOnlyAddedTolerations(newPod.Spec.Tolerations, oldPod.Spec.Tolerations, specPath.Child("tolerations"))...)
// handle updateable fields by munging those fields prior to deep equal comparison. // handle updateable fields by munging those fields prior to deep equal comparison.
mungedPod := *newPod mungedPod := *newPod
// munge spec.containers[*].image // munge spec.containers[*].image
@@ -4010,10 +4014,6 @@ func ValidatePodUpdate(newPod, oldPod *core.Pod, opts PodValidationOptions) fiel
mungedPod.Spec.ActiveDeadlineSeconds = &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) { if !apiequality.Semantic.DeepEqual(mungedPod.Spec, oldPod.Spec) {
// This diff isn't perfect, but it's a helluva lot better an "I'm not going to tell you what the difference is". // This diff isn't perfect, but it's a helluva lot better an "I'm not going to tell you what the difference is".
//TODO: Pinpoint the specific field that causes the invalid error after we have strategic merge diff //TODO: Pinpoint the specific field that causes the invalid error after we have strategic merge diff