From 5cc909afe732502b2dfec15f0c34b25acc935883 Mon Sep 17 00:00:00 2001 From: hurf Date: Fri, 18 Sep 2015 11:22:47 +0800 Subject: [PATCH] Remove type validation in resource.Quantity.Add The type validation is unnecessary for add and will cause problem. Type will always keep unchanged after new amount is added. --- pkg/api/resource/quantity.go | 3 --- plugin/pkg/admission/resourcequota/admission_test.go | 8 ++++++++ 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/pkg/api/resource/quantity.go b/pkg/api/resource/quantity.go index 577d5b6093c..5b4a99dbc4b 100644 --- a/pkg/api/resource/quantity.go +++ b/pkg/api/resource/quantity.go @@ -323,9 +323,6 @@ func (q *Quantity) Cmp(y Quantity) int { } func (q *Quantity) Add(y Quantity) error { - if q.Format != y.Format { - return fmt.Errorf("format mismatch: %v vs. %v", q.Format, y.Format) - } q.Amount.Add(q.Amount, y.Amount) return nil } diff --git a/plugin/pkg/admission/resourcequota/admission_test.go b/plugin/pkg/admission/resourcequota/admission_test.go index 9628159bb47..c641955c5db 100644 --- a/plugin/pkg/admission/resourcequota/admission_test.go +++ b/plugin/pkg/admission/resourcequota/admission_test.go @@ -127,6 +127,14 @@ func TestIncrementUsagePodResources(t *testing.T) { hard: resource.MustParse("500Mi"), expectedError: true, }, + { + testName: "memory-not-allowed-with-different-format", + existing: validPod("a", 1, getResourceRequirements(getResourceList("", "100M"), getResourceList("", ""))), + input: validPod("b", 1, getResourceRequirements(getResourceList("", "450Mi"), getResourceList("", ""))), + resourceName: api.ResourceMemory, + hard: resource.MustParse("500Mi"), + expectedError: true, + }, { testName: "memory-no-request", existing: validPod("a", 1, getResourceRequirements(getResourceList("", "100Mi"), getResourceList("", ""))),