func ValidateResourceRequirements(requirements *v1.ResourceRequirements, fldPath *field.Path) field.ErrorList {
	allErrs := field.ErrorList{}
	limPath := fldPath.Child("limits")
	reqPath := fldPath.Child("requests")
	for resourceName, quantity := range requirements.Limits {
		fldPath := limPath.Key(string(resourceName))
		// Validate resource name.
		allErrs = append(allErrs, validateContainerResourceName(string(resourceName), fldPath)...)

		// Validate resource quantity.
		allErrs = append(allErrs, ValidateResourceQuantityValue(string(resourceName), quantity, fldPath)...)

	}
	for resourceName, quantity := range requirements.Requests {
		fldPath := reqPath.Key(string(resourceName))
		// Validate resource name.
		allErrs = append(allErrs, validateContainerResourceName(string(resourceName), fldPath)...)
		// Validate resource quantity.
		allErrs = append(allErrs, ValidateResourceQuantityValue(string(resourceName), quantity, fldPath)...)

		// Check that request <= limit.
		limitQuantity, exists := requirements.Limits[resourceName]
		if exists {
			// For GPUs, not only requests can't exceed limits, they also can't be lower, i.e. must be equal.
			if quantity.Cmp(limitQuantity) != 0 && !v1helper.IsOvercommitAllowed(resourceName) {
				allErrs = append(allErrs, field.Invalid(reqPath, quantity.String(), fmt.Sprintf("must be equal to %s limit", resourceName)))
			} else if quantity.Cmp(limitQuantity) > 0 {
				allErrs = append(allErrs, field.Invalid(reqPath, quantity.String(), fmt.Sprintf("must be less than or equal to %s limit", resourceName)))
			}
		}
	}

	return allErrs
}
// ValidateResourceRequirements will check if any of the resource
// Limits/Requests are of a valid value. Any incorrect value will be added to
// the ErrorList.
ValidateResourceRequirements will check if any of the resource
Limits/Requests are of a valid value. Any incorrect value will be added to
the ErrorList.
// ValidateResourceRequirements will check if any of the resource // Limits / Requests are of a valid value . Any incorrect value will be added to // the ErrorList .
func ValidateResourceRequirements(requirements *v1.ResourceRequirements, fldPath *field.Path) field.ErrorList {
	allErrs := field.ErrorList{}
	limPath := fldPath.Child("limits")
	reqPath := fldPath.Child("requests")
	for resourceName, quantity := range requirements.Limits {
		fldPath := limPath.Key(string(resourceName))
		allErrs = append(allErrs, validateContainerResourceName(string(resourceName), fldPath)...)
		allErrs = append(allErrs, ValidateResourceQuantityValue(string(resourceName), quantity, fldPath)...)
	}
	for resourceName, quantity := range requirements.Requests {
		fldPath := reqPath.Key(string(resourceName))
		allErrs = append(allErrs, validateContainerResourceName(string(resourceName), fldPath)...)
		allErrs = append(allErrs, ValidateResourceQuantityValue(string(resourceName), quantity, fldPath)...)
		limitQuantity, exists := requirements.Limits[resourceName]
		if exists {
			if quantity.Cmp(limitQuantity) != 0 && !v1helper.IsOvercommitAllowed(resourceName) {
				allErrs = append(allErrs, field.Invalid(reqPath, quantity.String(), fmt.Sprintf("must be equal to %s limit", resourceName)))
			} else if quantity.Cmp(limitQuantity) > 0 {
				allErrs = append(allErrs, field.Invalid(reqPath, quantity.String(), fmt.Sprintf("must be less than or equal to %s limit", resourceName)))
			}
		}
	}
	return allErrs
}
func ValidateResourceRequirements ( requirements * v1 . ResourceRequirements , fldPath * field . Path ) field . ErrorList { allErrs := field . ErrorList { } limPath := fldPath . Child ( " " ) reqPath := fldPath . Child ( " " ) for resourceName , quantity := range requirements . Limits { fldPath := limPath . Key ( string ( resourceName ) ) allErrs = append ( allErrs , validateContainerResourceName ( string ( resourceName ) , fldPath ) ... ) allErrs = append ( allErrs , ValidateResourceQuantityValue ( string ( resourceName ) , quantity , fldPath ) ... ) } for resourceName , quantity := range requirements . Requests { fldPath := reqPath . Key ( string ( resourceName ) ) allErrs = append ( allErrs , validateContainerResourceName ( string ( resourceName ) , fldPath ) ... ) allErrs = append ( allErrs , ValidateResourceQuantityValue ( string ( resourceName ) , quantity , fldPath ) ... ) limitQuantity , exists := requirements . Limits [ resourceName ] if exists { if quantity . Cmp ( limitQuantity ) != 0 && ! v1helper . IsOvercommitAllowed ( resourceName ) { allErrs = append ( allErrs , field . Invalid ( reqPath , quantity . String ( ) , fmt . Sprintf ( " " , resourceName ) ) ) } else if quantity . Cmp ( limitQuantity ) > 0 { allErrs = append ( allErrs , field . Invalid ( reqPath , quantity . String ( ) , fmt . Sprintf ( " " , resourceName ) ) ) } } } return allErrs }
ValidateResourceRequirements will check if any of the resource
Limits/Requests are of a valid value.
ValidateResourceRequirements will check if any of the resource Limits / Requests are of a valid value .
// Validate resource name. // Validate resource quantity. // Validate resource name. // Validate resource quantity. // Check that request <= limit. // For GPUs, not only requests can't exceed limits, they also can't be lower, i.e. must be equal.