From 2c8ab7a7903d7b982d06ce19bbb265bc2b00e937 Mon Sep 17 00:00:00 2001 From: Eduardo Apolinario Date: Wed, 6 Mar 2024 19:03:14 -0800 Subject: [PATCH] Simplify the code and add a comment. Signed-off-by: Eduardo Apolinario --- flyteadmin/pkg/manager/impl/validation/task_validator.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/flyteadmin/pkg/manager/impl/validation/task_validator.go b/flyteadmin/pkg/manager/impl/validation/task_validator.go index 758ff78cef..9afb51e474 100644 --- a/flyteadmin/pkg/manager/impl/validation/task_validator.go +++ b/flyteadmin/pkg/manager/impl/validation/task_validator.go @@ -166,12 +166,13 @@ 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 { - var resourceName = core.Resources_UNKNOWN + // 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 == "ephemeral-storage" { - resourceName = core.Resources_ResourceName(core.Resources_ResourceName_value["EPHEMERAL_STORAGE"]) - } else { - resourceName = core.Resources_ResourceName(core.Resources_ResourceName_value[strings.ToUpper(name.String())]) + name = "EPHEMERAL_STORAGE" } + resourceName := core.Resources_ResourceName(core.Resources_ResourceName_value[strings.ToUpper(name.String())]) requestedToQuantity[resourceName] = quantity } return requestedToQuantity