Merge pull request #54919 from tianshapjq/validate-limit-range

Automatic merge from submit-queue. If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>.

validation to GPU and hugepages in creating LimitRange

**What this PR does / why we need it**:
validate if default and defaultRequest match when creating LimitRange for GPU and hugepages.

**Which issue(s) this PR fixes** *(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)` format, will close the issue(s) when PR gets merged)*:
Fixes #54917 

**Special notes for your reviewer**:

**Release note**:

```release-note
validate if default and defaultRequest match when creating LimitRange for GPU and hugepages.
```
This commit is contained in:
Kubernetes Submit Queue 2017-11-09 02:58:16 -08:00 committed by GitHub
commit d2b9aa29c3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -3859,6 +3859,11 @@ func ValidateLimitRange(limitRange *api.LimitRange) field.ErrorList {
allErrs = append(allErrs, field.Invalid(idxPath.Child("maxLimitRequestRatio").Key(string(k)), maxRatio, fmt.Sprintf("ratio %s is greater than max/min = %f", maxRatio.String(), maxRatioLimit)))
}
}
// for GPU and hugepages, the default value and defaultRequest value must match if both are specified
if !helper.IsOvercommitAllowed(api.ResourceName(k)) && defaultQuantityFound && defaultRequestQuantityFound && defaultQuantity.Cmp(defaultRequestQuantity) != 0 {
allErrs = append(allErrs, field.Invalid(idxPath.Child("defaultRequest").Key(string(k)), defaultRequestQuantity, fmt.Sprintf("default value %s must equal to defaultRequest value %s in %s", defaultQuantity.String(), defaultRequestQuantity.String(), k)))
}
}
}