diff --git a/flytepropeller/pkg/compiler/transformers/k8s/workflow.go b/flytepropeller/pkg/compiler/transformers/k8s/workflow.go index f23b815ca45..21ce22e23a9 100644 --- a/flytepropeller/pkg/compiler/transformers/k8s/workflow.go +++ b/flytepropeller/pkg/compiler/transformers/k8s/workflow.go @@ -34,6 +34,9 @@ const ( ShardKeyLabel = "shard-key" // The fully qualified FlyteWorkflow name WorkflowNameLabel = "workflow-name" + + // Maximum length of a Kubernetes label + allowedExecutionNameLength = 63 ) func requiresInputs(w *core.WorkflowTemplate) bool { @@ -249,15 +252,21 @@ func BuildFlyteWorkflow(wfClosure *core.CompiledWorkflowClosure, inputs *core.Li errs.Collect(errors.NewWorkflowBuildError(err)) } - hashedIdentifier := hashIdentifier(core.Identifier{ - Project: project, - Domain: domain, - Name: name, - }) - rand.Seed(int64(hashedIdentifier)) - if workflowCRNameHashLength := config.GetConfig().WorkflowCRNameHashLength; workflowCRNameHashLength > 0 { - obj.ObjectMeta.Name = rand.String(workflowCRNameHashLength) + // Seed the randomness before generating the name with random suffix + hashedIdentifier := hashIdentifier(core.Identifier{ + Project: project, + Domain: domain, + Name: name, + }) + rand.Seed(int64(hashedIdentifier)) + + base := name + "-" + maxNameLength := allowedExecutionNameLength - workflowCRNameHashLength + if len(base) > maxNameLength { + base = base[:maxNameLength] + } + obj.ObjectMeta.Name = fmt.Sprintf("%s%s", base, rand.String(workflowCRNameHashLength)) } else { obj.ObjectMeta.Name = name } diff --git a/flytepropeller/pkg/controller/config/config.go b/flytepropeller/pkg/controller/config/config.go index 9ff996bb8cd..a0f50683cba 100644 --- a/flytepropeller/pkg/controller/config/config.go +++ b/flytepropeller/pkg/controller/config/config.go @@ -162,7 +162,7 @@ type Config struct { CreateFlyteWorkflowCRD bool `json:"create-flyteworkflow-crd" pflag:",Enable creation of the FlyteWorkflow CRD on startup"` NodeExecutionWorkerCount int `json:"node-execution-worker-count" pflag:",Number of workers to evaluate node executions, currently only used for array nodes"` ArrayNode ArrayNodeConfig `json:"array-node-config,omitempty" pflag:",Configuration for array nodes"` - WorkflowCRNameHashLength int `json:"workflow-cr-name-hash-length" pflag:",If 0, the execution ID will be used as the workflow CR name. Otherwise, a hash of the execution ID, project, domain will be used as the CR name, and WorkflowCRNameHashLength sets the length of this hash. Recommended: 0, or 32-63."` + WorkflowCRNameHashLength int `json:"workflow-cr-name-hash-length" pflag:",If 0, the execution ID will be used as the workflow CR name. Otherwise, a hash of the execution ID, project, domain will be used as the CR name, and WorkflowCRNameHashLength sets the length of this hash. Set between 0 to 63."` } // KubeClientConfig contains the configuration used by flytepropeller to configure its internal Kubernetes Client.