Skip to content

Commit

Permalink
Move hash to suffix
Browse files Browse the repository at this point in the history
Signed-off-by: ddl-rliu <[email protected]>
  • Loading branch information
ddl-rliu committed Jul 23, 2024
1 parent 856e416 commit 4f897af
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
25 changes: 17 additions & 8 deletions flytepropeller/pkg/compiler/transformers/k8s/workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion flytepropeller/pkg/controller/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 4f897af

Please sign in to comment.