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

Commit

Permalink
Using apimachinery rand and changed length to 20 (#379)
Browse files Browse the repository at this point in the history
* Using apimachinery rand and changed length to 20

Signed-off-by: Prafulla Mahindrakar <prafulla.mahindrakar@gmail.com>

* using a static start character similar to flyte-cli and flytectl

Signed-off-by: Prafulla Mahindrakar <prafulla.mahindrakar@gmail.com>

* Changing the start character for admin generated execution names

Signed-off-by: Prafulla Mahindrakar <prafulla.mahindrakar@gmail.com>
  • Loading branch information
pmahindrakar-oss authored Mar 29, 2022
1 parent 0260c17 commit b7b20e4
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 17 deletions.
4 changes: 2 additions & 2 deletions pkg/async/schedule/aws/workflow_executor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ func TestFormulateExecutionCreateRequest(t *testing.T) {
executionRequest := testExecutor.formulateExecutionCreateRequest(launchPlan, time.Unix(1543607788, 0))
assert.Equal(t, "foo", executionRequest.Project)
assert.Equal(t, "bar", executionRequest.Domain)
assert.Equal(t, "o4219lgnsf", executionRequest.Name)
assert.Equal(t, "a2k4s9v5j246kwmdmh4t", executionRequest.Name)

assert.True(t, proto.Equal(&launchPlanIdentifier, executionRequest.Spec.LaunchPlan))
assert.Equal(t, admin.ExecutionMetadata_SCHEDULED, executionRequest.Spec.Metadata.Mode)
Expand Down Expand Up @@ -238,7 +238,7 @@ func TestRun(t *testing.T) {
*admin.ExecutionCreateResponse, error) {
assert.Equal(t, "project", request.Project)
assert.Equal(t, "domain", request.Domain)
assert.Equal(t, "u1jjtbc5tj", request.Name)
assert.Equal(t, "ar8fphnlc5wh9dksjncj", request.Name)
if messagesSeen == 0 {
assert.Contains(t, request.Inputs.Literals, testKickoffTime)
assert.Equal(t, testKickoffTimeProtoLiteral, *request.Inputs.Literals[testKickoffTime])
Expand Down
21 changes: 6 additions & 15 deletions pkg/common/executions.go
Original file line number Diff line number Diff line change
@@ -1,29 +1,20 @@
package common

import (
"math/rand"
"fmt"

"github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/core"
)

const ExecutionIDLength = 10

// In kubernetes, resource names must comply with this regex: '[a-z]([-a-z0-9]*[a-z0-9])?'
const AllowedExecutionIDStartCharStr = "abcdefghijklmnopqrstuvwxyz"
const AllowedExecutionIDStr = "abcdefghijklmnopqrstuvwxyz1234567890"
"k8s.io/apimachinery/pkg/util/rand"
)

var AllowedExecutionIDStartChars = []rune(AllowedExecutionIDStartCharStr)
var AllowedExecutionIDChars = []rune(AllowedExecutionIDStr)
const ExecutionIDLength = 20
const ExecutionStringFormat = "a%s"

/* #nosec */
func GetExecutionName(seed int64) string {
executionName := make([]rune, ExecutionIDLength)
rand.Seed(seed)
executionName[0] = AllowedExecutionIDStartChars[rand.Intn(len(AllowedExecutionIDStartChars))]
for i := 1; i < len(executionName); i++ {
executionName[i] = AllowedExecutionIDChars[rand.Intn(len(AllowedExecutionIDChars))]
}
return string(executionName)
return fmt.Sprintf(ExecutionStringFormat, rand.String(ExecutionIDLength-1))
}

var terminalExecutionPhases = map[core.WorkflowExecution_Phase]bool{
Expand Down
6 changes: 6 additions & 0 deletions pkg/common/executions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ import (
"github.com/stretchr/testify/assert"
)

const AllowedExecutionIDStartCharStr = "abcdefghijklmnopqrstuvwxyz"
const AllowedExecutionIDStr = "abcdefghijklmnopqrstuvwxyz1234567890"

var AllowedExecutionIDStartChars = []rune(AllowedExecutionIDStartCharStr)
var AllowedExecutionIDChars = []rune(AllowedExecutionIDStr)

func TestGetExecutionName(t *testing.T) {
randString := GetExecutionName(time.Now().UnixNano())
assert.Len(t, randString, ExecutionIDLength)
Expand Down

0 comments on commit b7b20e4

Please sign in to comment.