PV & PVC Client implementation
This commit is contained in:
@@ -364,11 +364,12 @@ func validateNFS(nfs *api.NFSVolumeSource) errs.ValidationErrorList {
|
||||
}
|
||||
|
||||
func ValidatePersistentVolumeName(name string, prefix bool) (bool, string) {
|
||||
return util.IsDNS1123Label(name), name
|
||||
return nameIsDNSSubdomain(name, prefix)
|
||||
}
|
||||
|
||||
func ValidatePersistentVolume(pv *api.PersistentVolume) errs.ValidationErrorList {
|
||||
allErrs := ValidateObjectMeta(&pv.ObjectMeta, false, ValidatePersistentVolumeName)
|
||||
allErrs := errs.ValidationErrorList{}
|
||||
allErrs = append(allErrs, ValidateObjectMeta(&pv.ObjectMeta, false, ValidatePersistentVolumeName).Prefix("metadata")...)
|
||||
|
||||
if len(pv.Spec.Capacity) == 0 {
|
||||
allErrs = append(allErrs, errs.NewFieldRequired("persistentVolume.Capacity"))
|
||||
@@ -393,6 +394,27 @@ func ValidatePersistentVolume(pv *api.PersistentVolume) errs.ValidationErrorList
|
||||
return allErrs
|
||||
}
|
||||
|
||||
// ValidatePersistentVolumeUpdate tests to see if the update is legal for an end user to make.
|
||||
// newPv is updated with fields that cannot be changed.
|
||||
func ValidatePersistentVolumeUpdate(newPv, oldPv *api.PersistentVolume) errs.ValidationErrorList {
|
||||
allErrs := errs.ValidationErrorList{}
|
||||
allErrs = ValidatePersistentVolume(newPv)
|
||||
newPv.Status = oldPv.Status
|
||||
return allErrs
|
||||
}
|
||||
|
||||
// ValidatePersistentVolumeStatusUpdate tests to see if the status update is legal for an end user to make.
|
||||
// newPv is updated with fields that cannot be changed.
|
||||
func ValidatePersistentVolumeStatusUpdate(newPv, oldPv *api.PersistentVolume) errs.ValidationErrorList {
|
||||
allErrs := errs.ValidationErrorList{}
|
||||
allErrs = append(allErrs, ValidateObjectMetaUpdate(&oldPv.ObjectMeta, &newPv.ObjectMeta).Prefix("metadata")...)
|
||||
if newPv.ResourceVersion == "" {
|
||||
allErrs = append(allErrs, fmt.Errorf("ResourceVersion must be specified"))
|
||||
}
|
||||
newPv.Spec = oldPv.Spec
|
||||
return allErrs
|
||||
}
|
||||
|
||||
func ValidatePersistentVolumeClaim(pvc *api.PersistentVolumeClaim) errs.ValidationErrorList {
|
||||
allErrs := ValidateObjectMeta(&pvc.ObjectMeta, true, ValidatePersistentVolumeName)
|
||||
if len(pvc.Spec.AccessModes) == 0 {
|
||||
@@ -404,6 +426,23 @@ func ValidatePersistentVolumeClaim(pvc *api.PersistentVolumeClaim) errs.Validati
|
||||
return allErrs
|
||||
}
|
||||
|
||||
func ValidatePersistentVolumeClaimUpdate(newPvc, oldPvc *api.PersistentVolumeClaim) errs.ValidationErrorList {
|
||||
allErrs := errs.ValidationErrorList{}
|
||||
allErrs = ValidatePersistentVolumeClaim(newPvc)
|
||||
newPvc.Status = oldPvc.Status
|
||||
return allErrs
|
||||
}
|
||||
|
||||
func ValidatePersistentVolumeClaimStatusUpdate(newPvc, oldPvc *api.PersistentVolumeClaim) errs.ValidationErrorList {
|
||||
allErrs := errs.ValidationErrorList{}
|
||||
allErrs = append(allErrs, ValidateObjectMetaUpdate(&oldPvc.ObjectMeta, &newPvc.ObjectMeta).Prefix("metadata")...)
|
||||
if newPvc.ResourceVersion == "" {
|
||||
allErrs = append(allErrs, fmt.Errorf("ResourceVersion must be specified"))
|
||||
}
|
||||
newPvc.Spec = oldPvc.Spec
|
||||
return allErrs
|
||||
}
|
||||
|
||||
var supportedPortProtocols = util.NewStringSet(string(api.ProtocolTCP), string(api.ProtocolUDP))
|
||||
|
||||
func validatePorts(ports []api.ContainerPort) errs.ValidationErrorList {
|
||||
|
Reference in New Issue
Block a user