Skip to content

Commit

Permalink
remove pod toleration toleration seconds mutation
Browse files Browse the repository at this point in the history
  • Loading branch information
deads2k committed Mar 16, 2021
1 parent bc25538 commit 6a1fff6
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions pkg/apis/core/validation/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -3084,10 +3084,11 @@ func validateOnlyAddedTolerations(newTolerations []core.Toleration, oldToleratio
allErrs := field.ErrorList{}
for _, old := range oldTolerations {
found := false
old.TolerationSeconds = nil
for _, new := range newTolerations {
new.TolerationSeconds = nil
if reflect.DeepEqual(old, new) {
oldTolerationClone := old.DeepCopy()
for _, newToleration := range newTolerations {
// assign to our clone before doing a deep equal so we can allow tolerationseconds to change.
oldTolerationClone.TolerationSeconds = newToleration.TolerationSeconds // +k8s:verify-mutation:reason=clone
if reflect.DeepEqual(*oldTolerationClone, newToleration) {
found = true
break
}
Expand Down Expand Up @@ -3965,6 +3966,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"))
}

// 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.
mungedPod := *newPod
// munge spec.containers[*].image
Expand All @@ -3988,10 +3992,6 @@ func ValidatePodUpdate(newPod, oldPod *core.Pod, opts PodValidationOptions) fiel
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) {
// 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
Expand Down

0 comments on commit 6a1fff6

Please sign in to comment.