diff --git a/pkg/api/validation/validation.go b/pkg/api/validation/validation.go index e14da40d992..c29dbf34b8f 100644 --- a/pkg/api/validation/validation.go +++ b/pkg/api/validation/validation.go @@ -976,6 +976,8 @@ var ValidatePersistentVolumeName = NameIsDNSSubdomain var supportedAccessModes = sets.NewString(string(api.ReadWriteOnce), string(api.ReadOnlyMany), string(api.ReadWriteMany)) +var supportedReclaimPolicy = sets.NewString(string(api.PersistentVolumeReclaimDelete), string(api.PersistentVolumeReclaimRecycle), string(api.PersistentVolumeReclaimRetain)) + func ValidatePersistentVolume(pv *api.PersistentVolume) field.ErrorList { allErrs := ValidateObjectMeta(&pv.ObjectMeta, false, ValidatePersistentVolumeName, field.NewPath("metadata")) @@ -1000,6 +1002,11 @@ func ValidatePersistentVolume(pv *api.PersistentVolume) field.ErrorList { for r, qty := range pv.Spec.Capacity { allErrs = append(allErrs, validateBasicResource(qty, capPath.Key(string(r)))...) } + if len(string(pv.Spec.PersistentVolumeReclaimPolicy)) > 0 { + if !supportedReclaimPolicy.Has(string(pv.Spec.PersistentVolumeReclaimPolicy)) { + allErrs = append(allErrs, field.NotSupported(specPath.Child("persistentVolumeReclaimPolicy"), pv.Spec.PersistentVolumeReclaimPolicy, supportedReclaimPolicy.List())) + } + } numVolumes := 0 if pv.Spec.HostPath != nil {