Merge pull request #31146 from pmorie/recycle-hostpath-slash

Automatic merge from submit-queue

Add validation preventing recycle of / in a hostPath PV

Adds a validation that prevents a user from recycling `/` when it is used in a hostPath PV

cc @kubernetes/sig-storage
This commit is contained in:
Kubernetes Submit Queue
2016-08-26 18:09:32 -07:00
committed by GitHub
2 changed files with 32 additions and 0 deletions

View File

@@ -1147,6 +1147,12 @@ func ValidatePersistentVolume(pv *api.PersistentVolume) field.ErrorList {
if numVolumes == 0 {
allErrs = append(allErrs, field.Required(specPath, "must specify a volume type"))
}
// do not allow hostPath mounts of '/' to have a 'recycle' reclaim policy
if pv.Spec.HostPath != nil && path.Clean(pv.Spec.HostPath.Path) == "/" && pv.Spec.PersistentVolumeReclaimPolicy == api.PersistentVolumeReclaimRecycle {
allErrs = append(allErrs, field.Forbidden(specPath.Child("persistentVolumeReclaimPolicy"), "may not be 'recycle' for a hostPath mount of '/'"))
}
return allErrs
}