From 14c004f074f6542a6db5397b27ecb00e8704b0e8 Mon Sep 17 00:00:00 2001 From: Mark White Date: Mon, 6 Jan 2020 06:47:48 +0000 Subject: [PATCH 1/2] Provide values of withItems maps as JSON in {{item}}. Fixed #1905 --- workflow/controller/operator.go | 6 ++++++ workflow/controller/operator_test.go | 3 ++- workflow/validate/validate_test.go | 2 ++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/workflow/controller/operator.go b/workflow/controller/operator.go index 67b9bf660751..9ecead135640 100644 --- a/workflow/controller/operator.go +++ b/workflow/controller/operator.go @@ -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, ",")) diff --git a/workflow/controller/operator_test.go b/workflow/controller/operator_test.go index 653a8d326702..01fb18197484 100644 --- a/workflow/controller/operator_test.go +++ b/workflow/controller/operator_test.go @@ -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} @@ -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 = ` diff --git a/workflow/validate/validate_test.go b/workflow/validate/validate_test.go index 314917d61ba9..b2d89a816c43 100644 --- a/workflow/validate/validate_test.go +++ b/workflow/validate/validate_test.go @@ -1214,6 +1214,8 @@ spec: - false - string - 1.2 + - os: "debian" + version: "9.0" - name: whalesay inputs: From 0e1fcb85323d2eb658368b89225ed116d2b82032 Mon Sep 17 00:00:00 2001 From: Mark White Date: Mon, 6 Jan 2020 22:06:58 +0000 Subject: [PATCH 2/2] fix: Added escape quotes to fix e2e test --- workflow/controller/operator_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/workflow/controller/operator_test.go b/workflow/controller/operator_test.go index 01fb18197484..927b107495bc 100644 --- a/workflow/controller/operator_test.go +++ b/workflow/controller/operator_test.go @@ -910,7 +910,7 @@ spec: container: image: docker/whalesay:latest command: [sh, -c] - args: ["cowsay {{inputs.parameters.message}}"] + args: ["cowsay \"{{inputs.parameters.message}}\""] ` func TestExpandWithItemsMap(t *testing.T) {