Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 873af48

Browse files
committed
remove unnecessary mutations in validation
These mutations are already done in the strategy
1 parent e1e4c5e commit 873af48

File tree

1 file changed

+2
-20
lines changed

1 file changed

+2
-20
lines changed

pkg/apis/core/validation/validation.go

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1942,13 +1942,11 @@ func ValidatePersistentVolumeUpdate(newPv, oldPv *core.PersistentVolume) field.E
19421942
}
19431943

19441944
// ValidatePersistentVolumeStatusUpdate tests to see if the status update is legal for an end user to make.
1945-
// newPv is updated with fields that cannot be changed.
19461945
func ValidatePersistentVolumeStatusUpdate(newPv, oldPv *core.PersistentVolume) field.ErrorList {
19471946
allErrs := ValidateObjectMetaUpdate(&newPv.ObjectMeta, &oldPv.ObjectMeta, field.NewPath("metadata"))
19481947
if len(newPv.ResourceVersion) == 0 {
19491948
allErrs = append(allErrs, field.Required(field.NewPath("resourceVersion"), ""))
19501949
}
1951-
newPv.Spec = oldPv.Spec
19521950
return allErrs
19531951
}
19541952

@@ -2094,7 +2092,6 @@ func ValidatePersistentVolumeClaimStatusUpdate(newPvc, oldPvc *core.PersistentVo
20942092
for r, qty := range newPvc.Status.Capacity {
20952093
allErrs = append(allErrs, validateBasicResource(qty, capPath.Key(string(r)))...)
20962094
}
2097-
newPvc.Spec = oldPvc.Spec
20982095
return allErrs
20992096
}
21002097

@@ -4030,8 +4027,7 @@ func ValidateContainerStateTransition(newStatuses, oldStatuses []core.ContainerS
40304027
return allErrs
40314028
}
40324029

4033-
// ValidatePodStatusUpdate tests to see if the update is legal for an end user to make. newPod is updated with fields
4034-
// that cannot be changed.
4030+
// ValidatePodStatusUpdate tests to see if the update is legal for an end user to make.
40354031
func ValidatePodStatusUpdate(newPod, oldPod *core.Pod) field.ErrorList {
40364032
fldPath := field.NewPath("metadata")
40374033
allErrs := ValidateObjectMetaUpdate(&newPod.ObjectMeta, &oldPod.ObjectMeta, fldPath)
@@ -4062,9 +4058,6 @@ func ValidatePodStatusUpdate(newPod, oldPod *core.Pod) field.ErrorList {
40624058
}
40634059
}
40644060

4065-
// For status update we ignore changes to pod spec.
4066-
newPod.Spec = oldPod.Spec
4067-
40684061
return allErrs
40694062
}
40704063

@@ -5511,7 +5504,6 @@ func ValidateResourceQuantityValue(resource string, value resource.Quantity, fld
55115504
}
55125505

55135506
// ValidateResourceQuotaUpdate tests to see if the update is legal for an end user to make.
5514-
// newResourceQuota is updated with fields that cannot be changed.
55155507
func ValidateResourceQuotaUpdate(newResourceQuota, oldResourceQuota *core.ResourceQuota) field.ErrorList {
55165508
allErrs := ValidateObjectMetaUpdate(&newResourceQuota.ObjectMeta, &oldResourceQuota.ObjectMeta, field.NewPath("metadata"))
55175509
allErrs = append(allErrs, ValidateResourceQuotaSpec(&newResourceQuota.Spec, field.NewPath("spec"))...)
@@ -5530,12 +5522,10 @@ func ValidateResourceQuotaUpdate(newResourceQuota, oldResourceQuota *core.Resour
55305522
allErrs = append(allErrs, field.Invalid(fldPath, newResourceQuota.Spec.Scopes, fieldImmutableErrorMsg))
55315523
}
55325524

5533-
newResourceQuota.Status = oldResourceQuota.Status
55345525
return allErrs
55355526
}
55365527

55375528
// ValidateResourceQuotaStatusUpdate tests to see if the status update is legal for an end user to make.
5538-
// newResourceQuota is updated with fields that cannot be changed.
55395529
func ValidateResourceQuotaStatusUpdate(newResourceQuota, oldResourceQuota *core.ResourceQuota) field.ErrorList {
55405530
allErrs := ValidateObjectMetaUpdate(&newResourceQuota.ObjectMeta, &oldResourceQuota.ObjectMeta, field.NewPath("metadata"))
55415531
if len(newResourceQuota.ResourceVersion) == 0 {
@@ -5553,7 +5543,6 @@ func ValidateResourceQuotaStatusUpdate(newResourceQuota, oldResourceQuota *core.
55535543
allErrs = append(allErrs, ValidateResourceQuotaResourceName(string(k), resPath)...)
55545544
allErrs = append(allErrs, ValidateResourceQuantityValue(string(k), v, resPath)...)
55555545
}
5556-
newResourceQuota.Spec = oldResourceQuota.Spec
55575546
return allErrs
55585547
}
55595548

@@ -5586,19 +5575,14 @@ func validateKubeFinalizerName(stringValue string, fldPath *field.Path) field.Er
55865575
}
55875576

55885577
// ValidateNamespaceUpdate tests to make sure a namespace update can be applied.
5589-
// newNamespace is updated with fields that cannot be changed
55905578
func ValidateNamespaceUpdate(newNamespace *core.Namespace, oldNamespace *core.Namespace) field.ErrorList {
55915579
allErrs := ValidateObjectMetaUpdate(&newNamespace.ObjectMeta, &oldNamespace.ObjectMeta, field.NewPath("metadata"))
5592-
newNamespace.Spec.Finalizers = oldNamespace.Spec.Finalizers
5593-
newNamespace.Status = oldNamespace.Status
55945580
return allErrs
55955581
}
55965582

5597-
// ValidateNamespaceStatusUpdate tests to see if the update is legal for an end user to make. newNamespace is updated with fields
5598-
// that cannot be changed.
5583+
// ValidateNamespaceStatusUpdate tests to see if the update is legal for an end user to make.
55995584
func ValidateNamespaceStatusUpdate(newNamespace, oldNamespace *core.Namespace) field.ErrorList {
56005585
allErrs := ValidateObjectMetaUpdate(&newNamespace.ObjectMeta, &oldNamespace.ObjectMeta, field.NewPath("metadata"))
5601-
newNamespace.Spec = oldNamespace.Spec
56025586
if newNamespace.DeletionTimestamp.IsZero() {
56035587
if newNamespace.Status.Phase != core.NamespaceActive {
56045588
allErrs = append(allErrs, field.Invalid(field.NewPath("status", "Phase"), newNamespace.Status.Phase, "may only be 'Active' if `deletionTimestamp` is empty"))
@@ -5612,7 +5596,6 @@ func ValidateNamespaceStatusUpdate(newNamespace, oldNamespace *core.Namespace) f
56125596
}
56135597

56145598
// ValidateNamespaceFinalizeUpdate tests to see if the update is legal for an end user to make.
5615-
// newNamespace is updated with fields that cannot be changed.
56165599
func ValidateNamespaceFinalizeUpdate(newNamespace, oldNamespace *core.Namespace) field.ErrorList {
56175600
allErrs := ValidateObjectMetaUpdate(&newNamespace.ObjectMeta, &oldNamespace.ObjectMeta, field.NewPath("metadata"))
56185601

@@ -5621,7 +5604,6 @@ func ValidateNamespaceFinalizeUpdate(newNamespace, oldNamespace *core.Namespace)
56215604
idxPath := fldPath.Index(i)
56225605
allErrs = append(allErrs, validateFinalizerName(string(newNamespace.Spec.Finalizers[i]), idxPath)...)
56235606
}
5624-
newNamespace.Status = oldNamespace.Status
56255607
return allErrs
56265608
}
56275609

0 commit comments

Comments
 (0)