Skip to content

Commit

Permalink
fix(controller): Consider nested expanded task in reference (#5594)
Browse files Browse the repository at this point in the history
Signed-off-by: Simon Behar <simbeh7@gmail.com>
  • Loading branch information
simster7 authored Apr 5, 2021
1 parent 79eb50b commit 7276bc3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
9 changes: 7 additions & 2 deletions workflow/controller/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -2360,7 +2360,10 @@ func hasOutputResultRef(name string, parentTmpl *wfv1.Template) bool {
func getStepOrDAGTaskName(nodeName string) string {
// If our name contains an open parenthesis, this node is a child of a Retry node or an expanded node
// (e.g. withItems, withParams, etc.). Ignore anything after the parenthesis.
if parenthesisIndex := strings.Index(nodeName, "("); parenthesisIndex >= 0 {
if parenthesisIndex := strings.LastIndex(nodeName, "("); parenthesisIndex >= 0 {
if parenthesisIndex > 0 && nodeName[parenthesisIndex-1] == ')' {
parenthesisIndex = strings.LastIndex(nodeName[:parenthesisIndex], "(")
}
nodeName = nodeName[:parenthesisIndex]
}
// If our node contains a dot, we're a child node. We're only interested in the step that called us, so return the
Expand Down Expand Up @@ -2836,7 +2839,9 @@ func processItem(tmpl template.Template, name string, index int, item wfv1.Item,
}

func generateNodeName(name string, index int, desc interface{}) string {
newName := fmt.Sprintf("%s(%d:%v)", name, index, desc)
// Do not display parentheses in node name. Nodes are still guaranteed to be unique due to the index number
cleanName := strings.ReplaceAll(strings.ReplaceAll(fmt.Sprint(desc), "(", ""), ")", "")
newName := fmt.Sprintf("%s(%d:%v)", name, index, cleanName)
if out := util.RecoverIndexFromNodeName(newName); out != index {
panic(fmt.Sprintf("unrecoverable digit in generateName; wanted '%d' and got '%d'", index, out))
}
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 @@ -6300,7 +6300,8 @@ func TestStepsFailFast(t *testing.T) {

func TestGetStepOrDAGTaskName(t *testing.T) {
assert.Equal(t, "generate-artifact", getStepOrDAGTaskName("data-transformation-gjrt8[0].generate-artifact(2:foo/script.py)"))
assert.Equal(t, "generate-artifact", getStepOrDAGTaskName("data-transformation-gjrt8[0].generate-artifact(2:foo/script(.)py)"))
assert.Equal(t, "step3", getStepOrDAGTaskName("bug-rqq5f[0].fanout[0].fanout1(0:1)(0)[0].fanout2(0:1).step3(0)"))
assert.Equal(t, "divide-by-2", getStepOrDAGTaskName("parameter-aggregation[0].divide-by-2(0:1)(0)"))
}

func TestGenerateOutputResultRegex(t *testing.T) {
Expand Down

0 comments on commit 7276bc3

Please sign in to comment.