Skip to content

Commit ed3df24

Browse files
committed
add quantity multiplication
Signed-off-by: b05702117 <[email protected]>
1 parent 885cc11 commit ed3df24

File tree

1 file changed

+21
-3
lines changed
  • flyteplugins/go/tasks/pluginmachinery/flytek8s

1 file changed

+21
-3
lines changed

flyteplugins/go/tasks/pluginmachinery/flytek8s/utils.go

+21-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
package flytek8s
22

33
import (
4-
"github.com/pkg/errors"
4+
"math"
5+
"strconv"
6+
7+
"github.com/pkg/errors" // For decimal arithmetic
58
v1 "k8s.io/api/core/v1"
69
"k8s.io/apimachinery/pkg/api/resource"
710

@@ -35,8 +38,23 @@ func ToK8sResourceList(resources []*core.Resources_ResourceEntry, onOOMConfig pl
3538
case core.Resources_MEMORY:
3639
if !v.IsZero() {
3740
if onOOMConfig != nil && onOOMConfig.GetExponent() > 0 && onOOMConfig.GetFactor() > 1.0 {
38-
// TODO: Create this function
39-
// v.Mul(math.Pow(float64(onOOMConfig.GetFactor()), float64(onOOMConfig.GetExponent())))
41+
// Convert to multiplier into string and parse it to quantity
42+
multiplier := math.Pow(float64(onOOMConfig.GetFactor()), float64(onOOMConfig.GetExponent()))
43+
multiplier_str := strconv.FormatFloat(multiplier, 'f', -1, 64)
44+
multiplier_quantity, err := resource.ParseQuantity(multiplier_str)
45+
if err != nil {
46+
return nil, errors.Wrap(err, "Failed to parse resource as a valid quantity.")
47+
}
48+
49+
// Multiply the value by the multiplier
50+
v.AsDec().Mul(v.AsDec(), multiplier_quantity.AsDec())
51+
52+
// Convert the value to a string and parse it to quantity
53+
v, err := resource.ParseQuantity(v.AsDec().String())
54+
if err != nil {
55+
return nil, errors.Wrap(err, "Failed to parse resource as a valid quantity.")
56+
}
57+
4058
limitVal, err := resource.ParseQuantity(onOOMConfig.GetLimit())
4159
if err != nil {
4260
return nil, errors.Wrap(err, "Failed to parse resource as a valid quantity.")

0 commit comments

Comments
 (0)