Skip to content

Commit 98e6595

Browse files
authored
Merge pull request kubernetes#89300 from huffmanca/expand_pvc_validation_message
Expand the PVC validation messages
2 parents 1130e89 + cb230dc commit 98e6595

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

pkg/apis/core/validation/validation.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1857,7 +1857,8 @@ func ValidatePersistentVolumeUpdate(newPv, oldPv *core.PersistentVolume) field.E
18571857

18581858
// PersistentVolumeSource should be immutable after creation.
18591859
if !apiequality.Semantic.DeepEqual(newPv.Spec.PersistentVolumeSource, oldPv.Spec.PersistentVolumeSource) {
1860-
allErrs = append(allErrs, field.Forbidden(field.NewPath("spec", "persistentvolumesource"), "is immutable after creation"))
1860+
pvcSourceDiff := diff.ObjectDiff(newPv.Spec.PersistentVolumeSource, oldPv.Spec.PersistentVolumeSource)
1861+
allErrs = append(allErrs, field.Forbidden(field.NewPath("spec", "persistentvolumesource"), fmt.Sprintf("spec.persistentvolumesource is immutable after creation\n%v", pvcSourceDiff)))
18611862
}
18621863
allErrs = append(allErrs, ValidateImmutableField(newPv.Spec.VolumeMode, oldPv.Spec.VolumeMode, field.NewPath("volumeMode"))...)
18631864

@@ -1972,7 +1973,8 @@ func ValidatePersistentVolumeClaimUpdate(newPvc, oldPvc *core.PersistentVolumeCl
19721973
newSize := newPvc.Spec.Resources.Requests["storage"]
19731974

19741975
if !apiequality.Semantic.DeepEqual(newPvcClone.Spec, oldPvcClone.Spec) {
1975-
allErrs = append(allErrs, field.Forbidden(field.NewPath("spec"), "is immutable after creation except resources.requests for bound claims"))
1976+
specDiff := diff.ObjectDiff(newPvcClone.Spec, oldPvcClone.Spec)
1977+
allErrs = append(allErrs, field.Forbidden(field.NewPath("spec"), fmt.Sprintf("spec is immutable after creation except resources.requests for bound claims\n%v", specDiff)))
19761978
}
19771979
if newSize.Cmp(oldSize) < 0 {
19781980
allErrs = append(allErrs, field.Forbidden(field.NewPath("spec", "resources", "requests", "storage"), "field can not be less than previous value"))
@@ -1982,7 +1984,8 @@ func ValidatePersistentVolumeClaimUpdate(newPvc, oldPvc *core.PersistentVolumeCl
19821984
// changes to Spec are not allowed, but updates to label/and some annotations are OK.
19831985
// no-op updates pass validation.
19841986
if !apiequality.Semantic.DeepEqual(newPvcClone.Spec, oldPvcClone.Spec) {
1985-
allErrs = append(allErrs, field.Forbidden(field.NewPath("spec"), "field is immutable after creation"))
1987+
specDiff := diff.ObjectDiff(newPvcClone.Spec, oldPvcClone.Spec)
1988+
allErrs = append(allErrs, field.Forbidden(field.NewPath("spec"), fmt.Sprintf("field is immutable after creation\n%v", specDiff)))
19861989
}
19871990
}
19881991

0 commit comments

Comments
 (0)