Skip to content

Commit

Permalink
Fix ephemeral storage validation in the case of pod templates (#5019)
Browse files Browse the repository at this point in the history
* Fix ephemeral storage validation in the case of pod templates

Signed-off-by: Eduardo Apolinario <[email protected]>

* Simplify the code and add a comment.

Signed-off-by: Eduardo Apolinario <[email protected]>

* Use constants in the comparison

Signed-off-by: Eduardo Apolinario <[email protected]>

---------

Signed-off-by: Eduardo Apolinario <[email protected]>
Co-authored-by: Eduardo Apolinario <[email protected]>
  • Loading branch information
eapolinario and eapolinario authored Mar 8, 2024
1 parent b710ca4 commit 992641c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
6 changes: 6 additions & 0 deletions flyteadmin/pkg/manager/impl/validation/task_validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,12 @@ func isWholeNumber(quantity resource.Quantity) bool {
func resourceListToQuantity(resources corev1.ResourceList) map[core.Resources_ResourceName]resource.Quantity {
var requestedToQuantity = make(map[core.Resources_ResourceName]resource.Quantity)
for name, quantity := range resources {
// The name to refer to ephemeral storage defined in k8s (https://github.com/kubernetes/api/blob/05aa4bceed70af2652698a28fb144ee22b2dd2ba/core/v1/types.go#L5988)
// is different from the name defined in Flyte's proto (https://github.com/flyteorg/flyte/blob/fd42f65660069d9c164cda2de579d3a89cac5b0f/flyteidl/protos/flyteidl/core/tasks.proto#L25).
// This is a workaround to handle the conversion.
if name == corev1.ResourceEphemeralStorage {
name = corev1.ResourceName(core.Resources_EPHEMERAL_STORAGE.String())
}
resourceName := core.Resources_ResourceName(core.Resources_ResourceName_value[strings.ToUpper(name.String())])
requestedToQuantity[resourceName] = quantity
}
Expand Down
5 changes: 5 additions & 0 deletions flyteadmin/pkg/manager/impl/validation/task_validator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,11 @@ func TestResourceListToQuantity(t *testing.T) {
gpuQuantity := gpuResources[core.Resources_CPU]
val = gpuQuantity.Value()
assert.Equal(t, val, int64(2))

ephemeralStorageResources := resourceListToQuantity(corev1.ResourceList{corev1.ResourceEphemeralStorage: resource.MustParse("500Mi")})
ephemeralStorageQuantity := ephemeralStorageResources[core.Resources_EPHEMERAL_STORAGE]
val = ephemeralStorageQuantity.Value()
assert.Equal(t, val, int64(524288000))
}

func TestRequestedResourcesToQuantity(t *testing.T) {
Expand Down

0 comments on commit 992641c

Please sign in to comment.