Skip to content
This repository has been archived by the owner on Oct 9, 2023. It is now read-only.

Inject task generated name #265

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go/tasks/pluginmachinery/core/exec_metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
12 changes: 11 additions & 1 deletion go/tasks/pluginmachinery/flytek8s/k8s_resource_adds.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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{
Expand All @@ -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{
Expand All @@ -110,7 +121,6 @@ func GetExecutionEnvVars(id pluginsCore.TaskExecutionID) []v1.EnvVar {
Name: "FLYTE_INTERNAL_VERSION",
Value: taskID.Version,
})

}
return envVars
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,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) {
Expand Down