Skip to content

Commit

Permalink
Provide values of withItems maps as JSON in {{item}}. Fixed argoproj#…
Browse files Browse the repository at this point in the history
  • Loading branch information
markterm committed Jan 6, 2020
1 parent 59a1906 commit 14c004f
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
6 changes: 6 additions & 0 deletions workflow/controller/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -1989,6 +1989,12 @@ func processItem(fstTmpl *fasttemplate.Template, name string, index int, item wf
replaceMap[fmt.Sprintf("item.%s", itemKey)] = fmt.Sprintf("%v", itemVal)
vals = append(vals, fmt.Sprintf("%s:%s", itemKey, itemVal))
}
jsonByteVal, err := json.Marshal(item.MapVal)
if err != nil {
return "", errors.InternalWrapError(err)
}
replaceMap["item"] = string(jsonByteVal)

// sort the values so that the name is deterministic
sort.Strings(vals)
newName = fmt.Sprintf("%s(%d:%v)", name, index, strings.Join(vals, ","))
Expand Down
3 changes: 2 additions & 1 deletion workflow/controller/operator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -897,7 +897,7 @@ spec:
arguments:
parameters:
- name: message
value: "{{item.os}} {{item.version}}"
value: "{{item.os}} {{item.version}} JSON({{item}})"
withItems:
- {os: debian, version: 9.1}
- {os: debian, version: 9.1}
Expand All @@ -924,6 +924,7 @@ func TestExpandWithItemsMap(t *testing.T) {
newSteps, err := woc.expandStep(wf.Spec.Templates[0].Steps[0].Steps[0])
assert.NoError(t, err)
assert.Equal(t, 3, len(newSteps))
assert.Equal(t, "debian 9.1 JSON({\"os\":\"debian\",\"version\":9.1})", *newSteps[0].Arguments.Parameters[0].Value)
}

var suspendTemplate = `
Expand Down
2 changes: 2 additions & 0 deletions workflow/validate/validate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1214,6 +1214,8 @@ spec:
- false
- string
- 1.2
- os: "debian"
version: "9.0"
- name: whalesay
inputs:
Expand Down

2 comments on commit 14c004f

@salanki
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible that this commit broke sequence? https://github.com/argoproj/argo/blob/7864ad36788dc78d035d59ddb27ecd979f7216f4/examples/loops-sequence.yaml, all of those items just return 0.

@markterm
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll take a look into this within the next couple of days.

Please sign in to comment.