Merge pull request #35437 from markturansky/loosen_pvc_limit_range_validation

Automatic merge from submit-queue

Loosened validation on PVC LimitRanger

This PR loosens validation on PVC LimitRanger so that either Min or Max are required, but not both.

Per @derekwaynecarr  https://github.com/openshift/origin/pull/11396#discussion_r84533061
This commit is contained in:
Kubernetes Submit Queue 2016-11-09 02:01:52 -08:00 committed by GitHub
commit 73e497fb44
2 changed files with 26 additions and 19 deletions

View File

@ -3047,11 +3047,8 @@ func ValidateLimitRange(limitRange *api.LimitRange) field.ErrorList {
if limit.Type == api.LimitTypePersistentVolumeClaim {
_, minQuantityFound := limit.Min[api.ResourceStorage]
_, maxQuantityFound := limit.Max[api.ResourceStorage]
if !minQuantityFound {
allErrs = append(allErrs, field.Required(idxPath.Child("min"), "minimum storage value is required"))
}
if !maxQuantityFound {
allErrs = append(allErrs, field.Required(idxPath.Child("max"), "maximum storage value is required"))
if !minQuantityFound && !maxQuantityFound {
allErrs = append(allErrs, field.Required(idxPath.Child("limits"), "either minimum or maximum storage value is required, but neither was provided"))
}
}

View File

@ -7069,6 +7069,28 @@ func TestValidateLimitRange(t *testing.T) {
},
},
},
{
name: "pvc-min-only",
spec: api.LimitRangeSpec{
Limits: []api.LimitRangeItem{
{
Type: api.LimitTypePersistentVolumeClaim,
Min: getStorageResourceList("5Gi"),
},
},
},
},
{
name: "pvc-max-only",
spec: api.LimitRangeSpec{
Limits: []api.LimitRangeItem{
{
Type: api.LimitTypePersistentVolumeClaim,
Max: getStorageResourceList("10Gi"),
},
},
},
},
{
name: "all-fields-valid-big-numbers",
spec: api.LimitRangeSpec{
@ -7276,27 +7298,15 @@ func TestValidateLimitRange(t *testing.T) {
}},
"must be a standard limit type or fully qualified",
},
"invalid missing required min field": {
"min and max values missing, one required": {
api.LimitRange{ObjectMeta: api.ObjectMeta{Name: "abc", Namespace: "foo"}, Spec: api.LimitRangeSpec{
Limits: []api.LimitRangeItem{
{
Type: api.LimitTypePersistentVolumeClaim,
Max: getStorageResourceList("10000T"),
},
},
}},
"minimum storage value is required",
},
"invalid missing required max field": {
api.LimitRange{ObjectMeta: api.ObjectMeta{Name: "abc", Namespace: "foo"}, Spec: api.LimitRangeSpec{
Limits: []api.LimitRangeItem{
{
Type: api.LimitTypePersistentVolumeClaim,
Min: getStorageResourceList("10000T"),
},
},
}},
"maximum storage value is required",
"either minimum or maximum storage value is required, but neither was provided",
},
"invalid min greater than max": {
api.LimitRange{ObjectMeta: api.ObjectMeta{Name: "abc", Namespace: "foo"}, Spec: api.LimitRangeSpec{