Skip to content

Commit

Permalink
fix: Support inputs for inline steps templates (#11074)
Browse files Browse the repository at this point in the history
Signed-off-by: Iain Lane <[email protected]>
Co-authored-by: Saravanan Balasubramanian <[email protected]>
  • Loading branch information
2 people authored and terrytangyuan committed Jul 19, 2023
1 parent def9d65 commit 1109ab4
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 11 deletions.
35 changes: 35 additions & 0 deletions workflow/controller/inline_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,38 @@ spec:
woc.operate(context.Background())
assert.Equal(t, wfv1.WorkflowRunning, woc.wf.Status.Phase)
}

func TestInlineSteps(t *testing.T) {
wf := wfv1.MustUnmarshalWorkflow(`
apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
generateName: steps-inline-
spec:
entrypoint: main
templates:
- name: main
steps:
- - name: a
inline:
inputs:
parameters:
- name: message
value: foo
container:
image: docker/whalesay:latest
command:
- cowsay
args:
- '{{inputs.parameters.message}}'
`)
cancel, wfc := newController(wf)
defer cancel()
woc := newWorkflowOperationCtx(wf, wfc)
woc.operate(context.Background())
assert.Equal(t, wfv1.WorkflowRunning, woc.wf.Status.Phase)

node := woc.wf.Status.Nodes.FindByDisplayName("a")
assert.Equal(t, "message", node.Inputs.Parameters[0].Name)
assert.Equal(t, "foo", node.Inputs.Parameters[0].Value.String())
}
32 changes: 21 additions & 11 deletions workflow/validate/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -930,20 +930,30 @@ func (ctx *templateValidationCtx) validateSteps(scope map[string]interface{}, tm
if err != nil {
return err
}
}

stepBytes, err := json.Marshal(stepGroup)
if err != nil {
return errors.InternalWrapError(err)
}
err = resolveAllVariables(scope, ctx.globalParams, string(stepBytes), workflowTemplateValidation)
if err != nil {
return errors.Errorf(errors.CodeBadRequest, "templates.%s.steps %s", tmpl.Name, err.Error())
}
stepBytes, err := json.Marshal(step)
if err != nil {
return errors.InternalWrapError(err)
}

stepScope := make(map[string]interface{})
for k, v := range scope {
stepScope[k] = v
}

if i := step.Inline; i != nil {
for _, p := range i.Inputs.Parameters {
stepScope["inputs.parameters."+p.Name] = placeholderGenerator.NextPlaceholder()
}
}

err = resolveAllVariables(stepScope, ctx.globalParams, string(stepBytes), workflowTemplateValidation)
if err != nil {
return errors.Errorf(errors.CodeBadRequest, "templates.%s.steps %s", tmpl.Name, err.Error())
}

for _, step := range stepGroup.Steps {
aggregate := len(step.WithItems) > 0 || step.WithParam != ""
resolvedTmpl := resolvedTemplates[step.Name]

ctx.addOutputsToScope(resolvedTmpl, fmt.Sprintf("steps.%s", step.Name), scope, aggregate, false)

// Validate the template again with actual arguments.
Expand Down

0 comments on commit 1109ab4

Please sign in to comment.