mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-27 05:27:21 +00:00
Check the correct value of Quantity in GetResourceRequest
This commit is contained in:
parent
82bfa667ed
commit
2dca643ca1
@ -86,8 +86,10 @@ func GetResourceRequest(pod *v1.Pod, resource v1.ResourceName) int64 {
|
|||||||
// take max_resource(sum_pod, any_init_container)
|
// take max_resource(sum_pod, any_init_container)
|
||||||
for _, container := range pod.Spec.InitContainers {
|
for _, container := range pod.Spec.InitContainers {
|
||||||
if rQuantity, ok := container.Resources.Requests[resource]; ok {
|
if rQuantity, ok := container.Resources.Requests[resource]; ok {
|
||||||
if resource == v1.ResourceCPU && rQuantity.MilliValue() > totalResources {
|
if resource == v1.ResourceCPU {
|
||||||
totalResources = rQuantity.MilliValue()
|
if rQuantity.MilliValue() > totalResources {
|
||||||
|
totalResources = rQuantity.MilliValue()
|
||||||
|
}
|
||||||
} else if rQuantity.Value() > totalResources {
|
} else if rQuantity.Value() > totalResources {
|
||||||
totalResources = rQuantity.Value()
|
totalResources = rQuantity.Value()
|
||||||
}
|
}
|
||||||
|
@ -63,6 +63,31 @@ func TestDefaultResourceHelpers(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestGetResourceRequest(t *testing.T) {
|
||||||
|
cases := []struct {
|
||||||
|
pod *v1.Pod
|
||||||
|
res v1.ResourceName
|
||||||
|
expectedValue int64
|
||||||
|
expectedError error
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
pod: getPod("foo", "9", "", "", ""),
|
||||||
|
res: v1.ResourceCPU,
|
||||||
|
expectedValue: 9000,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
pod: getPod("foo", "", "", "90Mi", ""),
|
||||||
|
res: v1.ResourceMemory,
|
||||||
|
expectedValue: 94371840,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
as := assert.New(t)
|
||||||
|
for idx, tc := range cases {
|
||||||
|
actual := GetResourceRequest(tc.pod, tc.res)
|
||||||
|
as.Equal(actual, tc.expectedValue, "expected test case [%d] to return %q; got %q instead", idx, tc.expectedValue, actual)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestExtractResourceValue(t *testing.T) {
|
func TestExtractResourceValue(t *testing.T) {
|
||||||
cases := []struct {
|
cases := []struct {
|
||||||
fs *v1.ResourceFieldSelector
|
fs *v1.ResourceFieldSelector
|
||||||
|
Loading…
Reference in New Issue
Block a user