Skip to content

Commit

Permalink
Merge branch 'master' into secure
Browse files Browse the repository at this point in the history
  • Loading branch information
alexec committed Apr 13, 2021
2 parents f4e28ac + 46ec302 commit 09d6de4
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 9 deletions.
3 changes: 1 addition & 2 deletions cmd/argoexec/commands/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func NewRootCommand() *cobra.Command {
func initExecutor() *executor.WorkflowExecutor {
version := argo.GetVersion()
executorType := os.Getenv(common.EnvVarContainerRuntimeExecutor)
log.WithFields(log.Fields{"version": version, "executorType": executorType}).Info("Starting Workflow Executor")
log.WithFields(log.Fields{"version": version.Version, "executorType": executorType}).Info("Starting Workflow Executor")
config, err := clientConfig.ClientConfig()
checkErr(err)
config = restclient.AddUserAgent(config, fmt.Sprintf("argo-workflows/%s argo-executor/%s", version.Version, executorType))
Expand All @@ -91,7 +91,6 @@ func initExecutor() *executor.WorkflowExecutor {
checkErr(err)

restClient := clientset.RESTClient()
checkErr(err)

podName, ok := os.LookupEnv(common.EnvVarPodName)
if !ok {
Expand Down
36 changes: 29 additions & 7 deletions workflow/controller/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -2340,14 +2340,35 @@ func hasOutputResultRef(name string, parentTmpl *wfv1.Template) bool {

// getStepOrDAGTaskName will extract the node from NodeStatus Name
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.LastIndex(nodeName, "("); parenthesisIndex >= 0 {
if parenthesisIndex > 0 && nodeName[parenthesisIndex-1] == ')' {
parenthesisIndex = strings.LastIndex(nodeName[:parenthesisIndex], "(")
// Extract the task or step name by ignoring retry IDs and expanded IDs that are included in parenthesis at the end
// of a node. Example: ".fanout1(0:1)(0)[0]" -> "fanout"

// Opener is what opened our current parenthesis. Example: if we see a ")", our opener is a "("
opener := ""
loop:
for i := len(nodeName) - 1; i >= 0; i-- {
char := string(nodeName[i])
switch {
case char == opener:
// If we find the opener, we are no longer inside a parenthesis or bracket
opener = ""
case opener != "":
// If the opener is not empty, then we are inside a parenthesis or bracket
// Do nothing
case char == ")":
// We are going inside a parenthesis
opener = "("
case char == "]":
// We are going inside a bracket
opener = "["
default:
// If the current character is not a parenthesis or bracket, and we are not inside one already, we have found
// the end of the node name.
nodeName = nodeName[:i+1]
break loop
}
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
// name of the node after the last dot.
if lastDotIndex := strings.LastIndex(nodeName, "."); lastDotIndex >= 0 {
Expand Down Expand Up @@ -2822,7 +2843,8 @@ func processItem(tmpl template.Template, name string, index int, item wfv1.Item,

func generateNodeName(name string, index int, desc interface{}) string {
// 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), "(", ""), ")", "")
replacer := strings.NewReplacer("(", "", ")", "")
cleanName := replacer.Replace(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
8 changes: 8 additions & 0 deletions workflow/controller/operator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6299,9 +6299,17 @@ 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/scrip[t.py)"))
assert.Equal(t, "generate-artifact", getStepOrDAGTaskName("data-transformation-gjrt8[0].generate-artifact(2:foo/scrip]t.py)"))
assert.Equal(t, "generate-artifact", getStepOrDAGTaskName("data-transformation-gjrt8[0].generate-artifact(2:foo/scri[p]t.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)"))
assert.Equal(t, "hello-mate", getStepOrDAGTaskName("greet-many-tkcld.greet-many(0:1).greet.hello-mate"))
assert.Equal(t, "hello-mate", getStepOrDAGTaskName("greet.hello-mate"))
assert.Equal(t, "hello-mate", getStepOrDAGTaskName("hello-mate"))
assert.Equal(t, "fanout1", getStepOrDAGTaskName("bug-rqq5f[0].fanout[0].fanout1(0:1)(0)[0]"))
}

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

0 comments on commit 09d6de4

Please sign in to comment.