Skip to content

Commit

Permalink
fix(controller): Randomly expr expression fail to resolve (#6410)
Browse files Browse the repository at this point in the history
  • Loading branch information
sarabala1979 authored Jul 27, 2021
1 parent f1792f6 commit c29b275
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions workflow/validate/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -769,6 +769,11 @@ func (ctx *templateValidationCtx) validateSteps(scope map[string]interface{}, tm
if err != nil {
return errors.Errorf(errors.CodeBadRequest, "templates.%s.steps[%d].%s %s", tmpl.Name, i, step.Name, err.Error())
}

if !validateWhenExpression(step.When) {
return errors.Errorf(errors.CodeBadRequest, "templates.%s when expression doesn't support 'expr' format '{{='. 'When' expression is only support govaluate format {{", tmpl.Name)
}

if step.HasExitHook() {
ctx.addOutputsToScope(resolvedTmpl, fmt.Sprintf("steps.%s", step.Name), scope, false, false)
}
Expand Down Expand Up @@ -1127,6 +1132,10 @@ func (d *dagValidationContext) GetTaskFinishedAtTime(taskName string) time.Time
return time.Now()
}

func validateWhenExpression(when string) bool {
return !strings.HasPrefix(when, "{{=")
}

func (ctx *templateValidationCtx) validateDAG(scope map[string]interface{}, tmplCtx *templateresolution.Context, tmpl *wfv1.Template) error {
err := validateNonLeaf(tmpl)
if err != nil {
Expand Down Expand Up @@ -1175,6 +1184,10 @@ func (ctx *templateValidationCtx) validateDAG(scope map[string]interface{}, tmpl
return errors.Errorf(errors.CodeBadRequest, "templates.%s cannot use 'continueOn' when using 'depends'. Instead use 'dep-task.Failed'/'dep-task.Errored'", tmpl.Name)
}

if !validateWhenExpression(task.When) {
return errors.Errorf(errors.CodeBadRequest, "templates.%s when doesn't support 'expr' expression '{{='. 'When' expression is only support govaluate format {{", tmpl.Name)
}

resolvedTmpl, err := ctx.validateTemplateHolder(&task, tmplCtx, &FakeArguments{})
if err != nil {
return errors.Errorf(errors.CodeBadRequest, "templates.%s.tasks.%s %s", tmpl.Name, task.Name, err.Error())
Expand Down

0 comments on commit c29b275

Please sign in to comment.