From feb56cc4869f3f25e9b1bfb1aa7ecb0dd1a7ecb5 Mon Sep 17 00:00:00 2001 From: Wojciech Tyczynski Date: Wed, 26 Oct 2016 10:21:54 +0200 Subject: [PATCH] Revert "Move resource.Quantity rounding to defaulter" This reverts commit 5b18b4e515d6793740607f3a4fc99a6a1822fe25. --- pkg/api/v1/conversion.go | 6 +++--- pkg/api/v1/defaults.go | 12 ------------ pkg/api/v1/defaults_test.go | 25 ------------------------- 3 files changed, 3 insertions(+), 40 deletions(-) diff --git a/pkg/api/v1/conversion.go b/pkg/api/v1/conversion.go index 160b063b010..74970df08e9 100644 --- a/pkg/api/v1/conversion.go +++ b/pkg/api/v1/conversion.go @@ -739,15 +739,15 @@ func Convert_v1_ResourceList_To_api_ResourceList(in *ResourceList, out *api.Reso if *in == nil { return nil } + if *out == nil { *out = make(api.ResourceList, len(*in)) } for key, val := range *in { - // Moved to defaults // TODO(#18538): We round up resource values to milli scale to maintain API compatibility. // In the future, we should instead reject values that need rounding. - // const milliScale = -3 - // val.RoundUp(milliScale) + const milliScale = -3 + val.RoundUp(milliScale) (*out)[api.ResourceName(key)] = val } diff --git a/pkg/api/v1/defaults.go b/pkg/api/v1/defaults.go index c1ea75c445f..2c910ec95fe 100644 --- a/pkg/api/v1/defaults.go +++ b/pkg/api/v1/defaults.go @@ -52,21 +52,9 @@ func addDefaultingFuncs(scheme *runtime.Scheme) error { SetDefaults_LimitRangeItem, SetDefaults_ConfigMap, SetDefaults_RBDVolumeSource, - SetDefaults_ResourceList, ) } -func SetDefaults_ResourceList(obj *ResourceList) { - for key, val := range *obj { - // TODO(#18538): We round up resource values to milli scale to maintain API compatibility. - // In the future, we should instead reject values that need rounding. - const milliScale = -3 - val.RoundUp(milliScale) - - (*obj)[ResourceName(key)] = val - } -} - func SetDefaults_PodExecOptions(obj *PodExecOptions) { obj.Stdout = true obj.Stderr = true diff --git a/pkg/api/v1/defaults_test.go b/pkg/api/v1/defaults_test.go index bcc1de67301..e7c802f6166 100644 --- a/pkg/api/v1/defaults_test.go +++ b/pkg/api/v1/defaults_test.go @@ -574,31 +574,6 @@ func TestSetDefaultObjectFieldSelectorAPIVersion(t *testing.T) { } } -func TestSetMinimumScalePod(t *testing.T) { - // verify we default if limits are specified (and that request=0 is preserved) - s := versioned.PodSpec{} - s.Containers = []versioned.Container{ - { - Resources: versioned.ResourceRequirements{ - Requests: versioned.ResourceList{ - versioned.ResourceMemory: resource.MustParse("1n"), - }, - Limits: versioned.ResourceList{ - versioned.ResourceCPU: resource.MustParse("2n"), - }, - }, - }, - } - pod := &versioned.Pod{ - Spec: s, - } - versioned.SetObjectDefaults_Pod(pod) - - if expect := resource.MustParse("1m"); expect.Cmp(pod.Spec.Containers[0].Resources.Requests[versioned.ResourceMemory]) != 0 { - t.Errorf("did not round resources: %#v", pod.Spec.Containers[0].Resources) - } -} - func TestSetDefaultRequestsPod(t *testing.T) { // verify we default if limits are specified (and that request=0 is preserved) s := versioned.PodSpec{}