Skip to content

Commit

Permalink
fix: Fix validation with Argo Variable in activeDeadlineSeconds (argo…
Browse files Browse the repository at this point in the history
…proj#4451)

Signed-off-by: Simon Behar <[email protected]>
  • Loading branch information
simster7 committed Nov 3, 2020
1 parent dedf052 commit 3960a0e
Show file tree
Hide file tree
Showing 2 changed files with 45 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 @@ -702,7 +702,7 @@ func (ctx *templateValidationCtx) validateLeaf(scope map[string]interface{}, tmp
}
}
if tmpl.ActiveDeadlineSeconds != nil {
if !intstr.IsValidIntOrArgoVariable(tmpl.ActiveDeadlineSeconds) {
if !intstr.IsValidIntOrArgoVariable(tmpl.ActiveDeadlineSeconds) && !placeholderGenerator.IsPlaceholder(tmpl.ActiveDeadlineSeconds.StrVal) {
return errors.Errorf(errors.CodeBadRequest, "templates.%s.activeDeadlineSeconds must be a positive integer > 0 or an argo variable", tmpl.Name)
}
if i, err := intstr.Int(tmpl.ActiveDeadlineSeconds); err == nil && i != nil && *i < 0 {
Expand Down
44 changes: 44 additions & 0 deletions workflow/validate/validate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2854,3 +2854,47 @@ func TestWorkflowTemplateWithArgumentValueNotFromEnumList(t *testing.T) {
err := validateWorkflowTemplate(workflowTemplateWithArgumentValueNotFromEnumList)
assert.EqualError(t, err, "spec.arguments.message.value should be present in spec.arguments.message.enum list")
}

var validActiveDeadlineSecondsArgoVariable = `
apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
generateName: timeout-bug-
spec:
entrypoint: main
templates:
- name: main
dag:
tasks:
- name: print-timeout
template: print-timeout
- name: use-timeout
template: use-timeout
dependencies: [print-timeout]
arguments:
parameters:
- name: timeout
value: "{{tasks.print-timeout.outputs.result}}"
- name: print-timeout
container:
image: alpine
command: [sh, -c]
args: ['echo 5']
- name: use-timeout
inputs:
parameters:
- name: timeout
activeDeadlineSeconds: "{{inputs.parameters.timeout}}"
container:
image: alpine
command: [sh, -c]
args: ["echo sleeping for 1m; sleep 60; echo done"]
`

func TestValidActiveDeadlineSecondsArgoVariable(t *testing.T) {
err := validateWorkflowTemplate(validActiveDeadlineSecondsArgoVariable)
assert.NoError(t, err)
}

0 comments on commit 3960a0e

Please sign in to comment.