Skip to content

Commit

Permalink
Fix: Support the List within List type in withParam argoproj#1471 (ar…
Browse files Browse the repository at this point in the history
…goproj#1473)

Fix: Support the List within List type in withParam argoproj#1471 (argoproj#1473)
  • Loading branch information
sarabala1979 committed Jul 22, 2019
1 parent 75cb8b9 commit ca1d5e6
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 1 deletion.
9 changes: 8 additions & 1 deletion workflow/controller/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -1640,8 +1640,15 @@ func processItem(fstTmpl *fasttemplate.Template, name string, index int, item wf
// sort the values so that the name is deterministic
sort.Strings(vals)
newName = fmt.Sprintf("%s(%d:%v)", name, index, strings.Join(vals, ","))
case []interface{}:
byteVal, err := json.Marshal(val)
if err != nil {
return "", errors.InternalWrapError(err)
}
replaceMap["item"] = string(byteVal)
newName = fmt.Sprintf("%s(%d:%v)", name, index, val)
default:
return "", errors.Errorf(errors.CodeBadRequest, "withItems[%d] expected string, number, or map. received: %s", index, val)
return "", errors.Errorf(errors.CodeBadRequest, "withItems[%d] expected string, number, list, or map. received: %s", index, val)
}
newStepStr, err := common.Replace(fstTmpl, replaceMap, false)
if err != nil {
Expand Down
46 changes: 46 additions & 0 deletions workflow/controller/operator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1159,3 +1159,49 @@ func TestResourceWithOwnerReferenceTemplate(t *testing.T) {
assert.Equal(t, "resource-with-ownerreference-template", objectMetas["resource-cm-3"].OwnerReferences[1].Name)
}
}

var withParamAsJsonList = `
apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
name: expand-with-items
spec:
entrypoint: expand-with-items
arguments:
parameters:
- name: input
value: '[[1,2],[3,4],[4,5],[6,7]]'
templates:
- name: expand-with-items
steps:
- - name: whalesay
template: whalesay
arguments:
parameters:
- name: message
value: "{{item}}"
withParam: "{{workflow.parameters.input}}"
- name: whalesay
inputs:
parameters:
- name: message
container:
image: alpine:latest
command: [sh, -c]
args: ["echo "]
`

func TestWithParamAsJsonList(t *testing.T) {
controller := newController()
wfcset := controller.wfclientset.ArgoprojV1alpha1().Workflows("")

// Test list expansion
wf := unmarshalWF(withParamAsJsonList)
wf, err := wfcset.Create(wf)
assert.Nil(t, err)
woc := newWorkflowOperationCtx(wf, controller)
woc.operate()
pods, err := controller.kubeclientset.CoreV1().Pods("").List(metav1.ListOptions{})
assert.Nil(t, err)
assert.Equal(t, 4, len(pods.Items))
}

0 comments on commit ca1d5e6

Please sign in to comment.