From 992641c5e076e9e5c608a8a50f7fbb0a8cbb9d7c Mon Sep 17 00:00:00 2001 From: Eduardo Apolinario <653394+eapolinario@users.noreply.github.com> Date: Thu, 7 Mar 2024 17:16:53 -0800 Subject: [PATCH] Fix ephemeral storage validation in the case of pod templates (#5019) * Fix ephemeral storage validation in the case of pod templates Signed-off-by: Eduardo Apolinario * Simplify the code and add a comment. Signed-off-by: Eduardo Apolinario * Use constants in the comparison Signed-off-by: Eduardo Apolinario --------- Signed-off-by: Eduardo Apolinario Co-authored-by: Eduardo Apolinario --- flyteadmin/pkg/manager/impl/validation/task_validator.go | 6 ++++++ .../pkg/manager/impl/validation/task_validator_test.go | 5 +++++ 2 files changed, 11 insertions(+) diff --git a/flyteadmin/pkg/manager/impl/validation/task_validator.go b/flyteadmin/pkg/manager/impl/validation/task_validator.go index c50e3311b3..02f2dcded0 100644 --- a/flyteadmin/pkg/manager/impl/validation/task_validator.go +++ b/flyteadmin/pkg/manager/impl/validation/task_validator.go @@ -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 } diff --git a/flyteadmin/pkg/manager/impl/validation/task_validator_test.go b/flyteadmin/pkg/manager/impl/validation/task_validator_test.go index c82d2e5f58..108a651517 100644 --- a/flyteadmin/pkg/manager/impl/validation/task_validator_test.go +++ b/flyteadmin/pkg/manager/impl/validation/task_validator_test.go @@ -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) {