Skip to content

Commit

Permalink
fix(validate): Fix DAG validation on task names when depends/dependen…
Browse files Browse the repository at this point in the history
…cies is not used. Fixes #5993 (#5998)

Signed-off-by: terrytangyuan <[email protected]>
  • Loading branch information
terrytangyuan authored May 25, 2021
1 parent 8b25615 commit a2c6241
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
2 changes: 1 addition & 1 deletion workflow/validate/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -1157,7 +1157,7 @@ func (ctx *templateValidationCtx) validateDAG(scope map[string]interface{}, tmpl
// Verify dependencies for all tasks can be resolved as well as template names
for _, task := range tmpl.DAG.Tasks {

if '0' <= task.Name[0] && task.Name[0] <= '9' {
if (usingDepends || len(task.Dependencies) > 0) && '0' <= task.Name[0] && task.Name[0] <= '9' {
return errors.Errorf(errors.CodeBadRequest, "templates.%s.tasks.%s name cannot begin with a digit when using either 'depends' or 'dependencies'", tmpl.Name, task.Name)
}

Expand Down
29 changes: 29 additions & 0 deletions workflow/validate/validate_dag_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -893,3 +893,32 @@ func TestDAGDependenciesDigit(t *testing.T) {
assert.Contains(t, err.Error(), "templates.diamond.tasks.5A name cannot begin with a digit when using either 'depends' or 'dependencies'")
}
}

var dagWithDigitNoDepends = `
apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
generateName: dag-diamond-
spec:
entrypoint: diamond
templates:
- name: diamond
dag:
tasks:
- name: 5A
template: pass
- name: B
template: pass
- name: pass
container:
image: alpine:3.7
command:
- sh
- -c
- exit 0
`

func TestDAGWithDigitNameNoDepends(t *testing.T) {
_, err := validate(dagWithDigitNoDepends)
assert.NoError(t, err)
}

0 comments on commit a2c6241

Please sign in to comment.