diff --git a/flytepropeller/pkg/compiler/transformers/k8s/workflow.go b/flytepropeller/pkg/compiler/transformers/k8s/workflow.go index 21ce22e23a9..73e518c13ed 100644 --- a/flytepropeller/pkg/compiler/transformers/k8s/workflow.go +++ b/flytepropeller/pkg/compiler/transformers/k8s/workflow.go @@ -35,8 +35,10 @@ const ( // The fully qualified FlyteWorkflow name WorkflowNameLabel = "workflow-name" - // Maximum length of a Kubernetes label - allowedExecutionNameLength = 63 + // Length of hash to use as a suffix on the workflow CR name. Used when config.UseWorkflowCRNameSuffix is true. + // The workflow CR name should be at or under 63 characters long, here it is 52 + 1 + 10 = 63 + workflowCRNameHashLength = 10 + workflowCRNameSuffixFmt = "%.52s-%s" ) func requiresInputs(w *core.WorkflowTemplate) bool { @@ -252,7 +254,7 @@ func BuildFlyteWorkflow(wfClosure *core.CompiledWorkflowClosure, inputs *core.Li errs.Collect(errors.NewWorkflowBuildError(err)) } - if workflowCRNameHashLength := config.GetConfig().WorkflowCRNameHashLength; workflowCRNameHashLength > 0 { + if config.GetConfig().UseWorkflowCRNameSuffix { // Seed the randomness before generating the name with random suffix hashedIdentifier := hashIdentifier(core.Identifier{ Project: project, @@ -260,13 +262,7 @@ func BuildFlyteWorkflow(wfClosure *core.CompiledWorkflowClosure, inputs *core.Li 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)) + obj.ObjectMeta.Name = fmt.Sprintf(workflowCRNameSuffixFmt, name, rand.String(workflowCRNameHashLength)) } else { obj.ObjectMeta.Name = name } diff --git a/flytepropeller/pkg/compiler/transformers/k8s/workflow_test.go b/flytepropeller/pkg/compiler/transformers/k8s/workflow_test.go index 9d8c6a746a4..893f81119ff 100644 --- a/flytepropeller/pkg/compiler/transformers/k8s/workflow_test.go +++ b/flytepropeller/pkg/compiler/transformers/k8s/workflow_test.go @@ -254,21 +254,21 @@ func TestBuildFlyteWorkflow_withUnionInputs(t *testing.T) { func TestBuildFlyteWorkflow_setWorkflowCRNameHashLength(t *testing.T) { for name, tt := range map[string]struct { - hashLength int - expected string + useSuffix bool + expected string }{ "default does not use hash as workflow CR name": { - hashLength: 0, - expected: "", + useSuffix: false, + expected: "", }, "use hash as workflow CR name": { - hashLength: 63, - expected: "x6m7gswrdlbj7nmv9zq8nq7ck78qtt8dxv9469q9llblmh9fb2pgggnxfs72n84", + useSuffix: true, + expected: "-x6m7gswrdl", }, } { t.Run(name, func(t *testing.T) { flyteConfig := config.GetConfig() - flyteConfig.WorkflowCRNameHashLength = tt.hashLength + flyteConfig.UseWorkflowCRNameSuffix = tt.useSuffix w := createSampleMockWorkflow() diff --git a/flytepropeller/pkg/controller/config/config.go b/flytepropeller/pkg/controller/config/config.go index a0f50683cba..23591008743 100644 --- a/flytepropeller/pkg/controller/config/config.go +++ b/flytepropeller/pkg/controller/config/config.go @@ -120,7 +120,7 @@ var ( EventVersion: 0, DefaultParallelismBehavior: ParallelismBehaviorUnlimited, }, - WorkflowCRNameHashLength: 0, + UseWorkflowCRNameSuffix: false, } ) @@ -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. Set between 0 to 63."` + UseWorkflowCRNameSuffix bool `json:"use-workflow-cr-name-suffix" pflag:",If false, the execution ID will be used as the workflow CR name. Otherwise, a hash of the execution ID, project, domain will be used as a suffix on the CR name."` } // KubeClientConfig contains the configuration used by flytepropeller to configure its internal Kubernetes Client.