mirror of
				https://github.com/optim-enterprises-bv/kubernetes.git
				synced 2025-11-04 04:08:16 +00:00 
			
		
		
		
	Adding vSphere volume validation in api
This commit is contained in:
		@@ -555,6 +555,14 @@ func validateVolumeSource(source *api.VolumeSource, fldPath *field.Path) field.E
 | 
				
			|||||||
		numVolumes++
 | 
							numVolumes++
 | 
				
			||||||
		allErrs = append(allErrs, validateAzureFile(source.AzureFile, fldPath.Child("azureFile"))...)
 | 
							allErrs = append(allErrs, validateAzureFile(source.AzureFile, fldPath.Child("azureFile"))...)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
						if source.VsphereVolume != nil {
 | 
				
			||||||
 | 
							if numVolumes > 0 {
 | 
				
			||||||
 | 
								allErrs = append(allErrs, field.Forbidden(fldPath.Child("vsphereVolume"), "may not specify more than 1 volume type"))
 | 
				
			||||||
 | 
							} else {
 | 
				
			||||||
 | 
								numVolumes++
 | 
				
			||||||
 | 
								allErrs = append(allErrs, validateVsphereVolumeSource(source.VsphereVolume, fldPath.Child("vsphereVolume"))...)
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
	if numVolumes == 0 {
 | 
						if numVolumes == 0 {
 | 
				
			||||||
		allErrs = append(allErrs, field.Required(fldPath, "must specify a volume type"))
 | 
							allErrs = append(allErrs, field.Required(fldPath, "must specify a volume type"))
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
@@ -798,6 +806,14 @@ func validateAzureFile(azure *api.AzureFileVolumeSource, fldPath *field.Path) fi
 | 
				
			|||||||
	return allErrs
 | 
						return allErrs
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func validateVsphereVolumeSource(cd *api.VsphereVirtualDiskVolumeSource, fldPath *field.Path) field.ErrorList {
 | 
				
			||||||
 | 
						allErrs := field.ErrorList{}
 | 
				
			||||||
 | 
						if len(cd.VolumePath) == 0 {
 | 
				
			||||||
 | 
							allErrs = append(allErrs, field.Required(fldPath.Child("volumePath"), ""))
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return allErrs
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// ValidatePersistentVolumeName checks that a name is appropriate for a
 | 
					// ValidatePersistentVolumeName checks that a name is appropriate for a
 | 
				
			||||||
// PersistentVolumeName object.
 | 
					// PersistentVolumeName object.
 | 
				
			||||||
var ValidatePersistentVolumeName = NameIsDNSSubdomain
 | 
					var ValidatePersistentVolumeName = NameIsDNSSubdomain
 | 
				
			||||||
@@ -926,6 +942,14 @@ func ValidatePersistentVolume(pv *api.PersistentVolume) field.ErrorList {
 | 
				
			|||||||
		numVolumes++
 | 
							numVolumes++
 | 
				
			||||||
		allErrs = append(allErrs, validateAzureFile(pv.Spec.AzureFile, specPath.Child("azureFile"))...)
 | 
							allErrs = append(allErrs, validateAzureFile(pv.Spec.AzureFile, specPath.Child("azureFile"))...)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
						if pv.Spec.VsphereVolume != nil {
 | 
				
			||||||
 | 
							if numVolumes > 0 {
 | 
				
			||||||
 | 
								allErrs = append(allErrs, field.Forbidden(specPath.Child("vsphereVolume"), "may not specify more than 1 volume type"))
 | 
				
			||||||
 | 
							} else {
 | 
				
			||||||
 | 
								numVolumes++
 | 
				
			||||||
 | 
								allErrs = append(allErrs, validateVsphereVolumeSource(pv.Spec.VsphereVolume, specPath.Child("vsphereVolume"))...)
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
	if numVolumes == 0 {
 | 
						if numVolumes == 0 {
 | 
				
			||||||
		allErrs = append(allErrs, field.Required(specPath, "must specify a volume type"))
 | 
							allErrs = append(allErrs, field.Required(specPath, "must specify a volume type"))
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user