Skip to content

Commit

Permalink
fix(controller): Prevent tasks with names starting with digit to use …
Browse files Browse the repository at this point in the history
…either 'depends' or 'dependencies' (#4598)

Signed-off-by: terrytangyuan <terrytangyuan@gmail.com>
  • Loading branch information
terrytangyuan authored Nov 30, 2020
1 parent 5bf7044 commit 6c46aab
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 3 deletions.
4 changes: 2 additions & 2 deletions workflow/validate/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -1204,8 +1204,8 @@ 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 usingDepends && '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 'depends'", tmpl.Name, task.Name)
if '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)
}

if usingDepends && len(task.Dependencies) > 0 {
Expand Down
56 changes: 55 additions & 1 deletion workflow/validate/validate_dag_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -740,6 +740,60 @@ spec:
func TestDAGDependsDigit(t *testing.T) {
_, err := validate(dagDependsDigit)
if assert.NotNil(t, err) {
assert.Contains(t, err.Error(), "templates.diamond.tasks.5A name cannot begin with a digit when using 'depends'")
assert.Contains(t, err.Error(), "templates.diamond.tasks.5A name cannot begin with a digit when using either 'depends' or 'dependencies'")
}
}

var dagDependenciesDigit = `
apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
generateName: dag-diamond-
spec:
entrypoint: diamond
templates:
- name: diamond
dag:
tasks:
- name: 5A
template: pass
- name: B
dependencies: [5A]
template: pass
- name: C
dependencies: [5A]
template: fail
- name: should-execute-1
depends: "'5A' && (C.Succeeded || C.Failed)" # For more information about this depends field, see: docs/enhanced-depends-logic.md
template: pass
- name: should-execute-2
depends: B || C
template: pass
- name: should-not-execute
depends: B && C
template: pass
- name: should-execute-3
depends: should-execute-2.Succeeded || should-not-execute
template: pass
- name: pass
container:
image: alpine:3.7
command:
- sh
- -c
- exit 0
- name: fail
container:
image: alpine:3.7
command:
- sh
- -c
- exit 1
`

func TestDAGDependenciesDigit(t *testing.T) {
_, err := validate(dagDependenciesDigit)
if assert.NotNil(t, err) {
assert.Contains(t, err.Error(), "templates.diamond.tasks.5A name cannot begin with a digit when using either 'depends' or 'dependencies'")
}
}

0 comments on commit 6c46aab

Please sign in to comment.