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.
This commit is contained in:
hurf
2015-09-18 11:22:47 +08:00
parent 09cf38e9a8
commit 5cc909afe7
2 changed files with 8 additions and 3 deletions

View File

@@ -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
}

View File

@@ -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("", ""))),