From 6c46aab7d54678c21df17d6c885473c17f8c66a6 Mon Sep 17 00:00:00 2001 From: Yuan Tang Date: Mon, 30 Nov 2020 14:16:55 -0500 Subject: [PATCH] fix(controller): Prevent tasks with names starting with digit to use either 'depends' or 'dependencies' (#4598) Signed-off-by: terrytangyuan --- workflow/validate/validate.go | 4 +- workflow/validate/validate_dag_test.go | 56 +++++++++++++++++++++++++- 2 files changed, 57 insertions(+), 3 deletions(-) diff --git a/workflow/validate/validate.go b/workflow/validate/validate.go index da726af83cbc..fc6ac611bfb4 100644 --- a/workflow/validate/validate.go +++ b/workflow/validate/validate.go @@ -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 { diff --git a/workflow/validate/validate_dag_test.go b/workflow/validate/validate_dag_test.go index 334630e295af..ba4c9fd3f7cb 100644 --- a/workflow/validate/validate_dag_test.go +++ b/workflow/validate/validate_dag_test.go @@ -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'") } }