@@ -18,7 +18,6 @@ package validation
1818
1919import (
2020 "fmt"
21- "reflect"
2221 "slices"
2322 "strings"
2423
@@ -579,54 +578,11 @@ func validatePodCliqueUpdate(newCliques, oldCliques []*grovecorev1alpha1.PodCliq
579578 allErrs = append (allErrs , apivalidation .ValidateImmutableField (newClique .Spec .RoleName , oldIndexCliqueTuple .B .Spec .RoleName , cliqueFldPath .Child ("roleName" ))... )
580579 allErrs = append (allErrs , apivalidation .ValidateImmutableField (newClique .Spec .MinAvailable , oldIndexCliqueTuple .B .Spec .MinAvailable , cliqueFldPath .Child ("minAvailable" ))... )
581580 allErrs = append (allErrs , apivalidation .ValidateImmutableField (newClique .Spec .StartsAfter , oldIndexCliqueTuple .B .Spec .StartsAfter , cliqueFldPath .Child ("startsAfter" ))... )
582-
583- allErrs = append (allErrs , validatePodSpecUpdate (& newClique .Spec .PodSpec , & oldIndexCliqueTuple .B .Spec .PodSpec , fldPath .Child ("spec" , "podSpec" ))... )
584- }
585-
586- return allErrs
587- }
588-
589- func validatePodSpecUpdate (newSpec , oldSpec * corev1.PodSpec , fldPath * field.Path ) field.ErrorList {
590- allErrs := field.ErrorList {}
591-
592- // spec: Forbidden: pod updates may not change fields other than:
593- // `spec.containers[*].image`,
594- // `spec.initContainers[*].image`,
595- // `spec.activeDeadlineSeconds`,
596- // `spec.tolerations` (only additions to existing tolerations),
597- // `spec.terminationGracePeriodSeconds` (allow it to be set to 1 if it was previously negative)
598- if len (newSpec .Tolerations ) < len (oldSpec .Tolerations ) || ! reflect .DeepEqual (oldSpec .Tolerations , newSpec .Tolerations [:len (oldSpec .Tolerations )]) {
599- allErrs = append (allErrs , field .Forbidden (fldPath .Child ("tolerations" ), "not allowed to change immutable pod fields" ))
600- }
601- if oldSpec .TerminationGracePeriodSeconds != nil && * oldSpec .TerminationGracePeriodSeconds < 0 {
602- // The only change that is allowed is to set this value to 1. All other modifications should be rejected.
603- if newSpec .TerminationGracePeriodSeconds != nil && * newSpec .TerminationGracePeriodSeconds != 1 {
604- allErrs = append (allErrs , field .Forbidden (fldPath .Child ("terminationGracePeriodSeconds" ), "value can only be set to 1 if previously negative" ))
605- }
606581 }
607- // hide mutable fields
608- spec1 := newSpec .DeepCopy ()
609- spec2 := oldSpec .DeepCopy ()
610-
611- clearContainerImages (spec1 .Containers )
612- clearContainerImages (spec2 .Containers )
613- clearContainerImages (spec1 .InitContainers )
614- clearContainerImages (spec2 .InitContainers )
615- spec1 .ActiveDeadlineSeconds , spec2 .ActiveDeadlineSeconds = nil , nil
616- spec1 .Tolerations , spec2 .Tolerations = []corev1.Toleration {}, []corev1.Toleration {}
617- spec1 .TerminationGracePeriodSeconds , spec2 .TerminationGracePeriodSeconds = nil , nil
618-
619- allErrs = append (allErrs , apivalidation .ValidateImmutableField (spec1 , spec2 , fldPath )... )
620582
621583 return allErrs
622584}
623585
624- func clearContainerImages (containers []corev1.Container ) {
625- for i := range containers {
626- containers [i ].Image = ""
627- }
628- }
629-
630586// validatePodNameConstraints validates Grove pod name component constraints.
631587// This function validates the constraints for component names that will be used
632588// to construct pod names.
0 commit comments