From 1892862e31973241b269cdce764700e4685bf1d7 Mon Sep 17 00:00:00 2001 From: Eduardo Apolinario Date: Fri, 27 May 2022 12:06:38 -0700 Subject: [PATCH] Inject task generated name Signed-off-by: Eduardo Apolinario --- go/tasks/pluginmachinery/core/exec_metadata.go | 2 +- .../pluginmachinery/flytek8s/k8s_resource_adds.go | 12 +++++++++++- .../flytek8s/k8s_resource_adds_test.go | 2 +- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/go/tasks/pluginmachinery/core/exec_metadata.go b/go/tasks/pluginmachinery/core/exec_metadata.go index 2e39dda14..782bc92b7 100644 --- a/go/tasks/pluginmachinery/core/exec_metadata.go +++ b/go/tasks/pluginmachinery/core/exec_metadata.go @@ -16,7 +16,7 @@ type TaskOverrides interface { // TaskExecutionID is a simple Interface to expose the ExecutionID of the running Task type TaskExecutionID interface { // GetGeneratedName returns the computed/generated name for the task id - // deprecated: use GetGeneratedNameWithLength + // deprecated: use GetGeneratedNameWith GetGeneratedName() string // GetGeneratedNameWith returns the generated name within a bounded length. If the name is smaller than minLength, diff --git a/go/tasks/pluginmachinery/flytek8s/k8s_resource_adds.go b/go/tasks/pluginmachinery/flytek8s/k8s_resource_adds.go index bb2b9db23..04d31d35b 100755 --- a/go/tasks/pluginmachinery/flytek8s/k8s_resource_adds.go +++ b/go/tasks/pluginmachinery/flytek8s/k8s_resource_adds.go @@ -15,6 +15,11 @@ import ( pluginsCore "github.com/flyteorg/flyteplugins/go/tasks/pluginmachinery/core" ) +const ( + taskGeneratedNameMinLength = 10 + taskGeneratedNameMaxLength = 100 +) + func GetContextEnvVars(ownerCtx context.Context) []v1.EnvVar { var envVars []v1.EnvVar @@ -74,6 +79,8 @@ func GetExecutionEnvVars(id pluginsCore.TaskExecutionID) []v1.EnvVar { // Task definition Level env variables. if id.GetID().TaskId != nil { taskID := id.GetID().TaskId + // TODO: what's an idiomatic way of handling this error given that we don't propagate errors up in GetExecutionEnvVars? + taskGeneratedName, _ := id.GetGeneratedNameWith(taskGeneratedNameMinLength, taskGeneratedNameMaxLength) envVars = append(envVars, v1.EnvVar{ @@ -92,6 +99,10 @@ func GetExecutionEnvVars(id pluginsCore.TaskExecutionID) []v1.EnvVar { Name: "FLYTE_INTERNAL_TASK_VERSION", Value: taskID.Version, }, + v1.EnvVar{ + Name: "FLYTE_INTERNAL_TASK_GENERATED_NAME", + Value: taskGeneratedName, + }, // Historic Task Definition Level env variables. // Remove these once SDK is migrated to use the new ones. v1.EnvVar{ @@ -110,7 +121,6 @@ func GetExecutionEnvVars(id pluginsCore.TaskExecutionID) []v1.EnvVar { Name: "FLYTE_INTERNAL_VERSION", Value: taskID.Version, }) - } return envVars } diff --git a/go/tasks/pluginmachinery/flytek8s/k8s_resource_adds_test.go b/go/tasks/pluginmachinery/flytek8s/k8s_resource_adds_test.go index 781cdbf41..0aa7ea827 100755 --- a/go/tasks/pluginmachinery/flytek8s/k8s_resource_adds_test.go +++ b/go/tasks/pluginmachinery/flytek8s/k8s_resource_adds_test.go @@ -21,7 +21,7 @@ import ( func TestGetExecutionEnvVars(t *testing.T) { mock := mockTaskExecutionIdentifier{} envVars := GetExecutionEnvVars(mock) - assert.Len(t, envVars, 12) + assert.Len(t, envVars, 13) } func TestGetTolerationsForResources(t *testing.T) {