Skip to content

Commit

Permalink
feat: remove all the retried nodes (#25)
Browse files Browse the repository at this point in the history
Co-authored-by: rick <[email protected]>
  • Loading branch information
LinuxSuRen and LinuxSuRen authored Jan 17, 2023
1 parent 234576a commit 62caf5f
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
19 changes: 19 additions & 0 deletions cmd/argoworkflow/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"io"
"net/http"
"os"
"regexp"
"strconv"
"strings"
"time"
Expand Down Expand Up @@ -188,6 +189,8 @@ func (e *DefaultPluginExecutor) Execute(args executor.ExecuteTemplateArgs, wf *w
wf.Annotations["workflow.link"] = targetAddress
wf.Annotations["workflow.templatelink"] = targetTemplateAddress

deleteRetryNodes(wf)

var message string
message, err = template.RenderTemplate(tplText, wf)
if err == nil {
Expand Down Expand Up @@ -228,6 +231,22 @@ func (e *DefaultPluginExecutor) Execute(args executor.ExecuteTemplateArgs, wf *w
return
}

func deleteRetryNodes(wf *wfv1.Workflow) {
var toDeletes []string
reg, err := regexp.Compile(`\(\d*\)`)
if err == nil {
for key, node := range wf.Status.Nodes {
if matched := reg.MatchString(node.DisplayName); matched {
toDeletes = append(toDeletes, key)
}
}

for _, key := range toDeletes {
delete(wf.Status.Nodes, key)
}
}
}

type PluginExecutor interface {
// Execute commands based on the args provided from the workflow
Execute(args executor.ExecuteTemplateArgs, wf *wfv1.Workflow) (executor.ExecuteTemplateResponse, error)
Expand Down
19 changes: 18 additions & 1 deletion cmd/argoworkflow/main_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package main

import (
"github.com/stretchr/testify/assert"
"testing"

wfv1 "github.com/argoproj/argo-workflows/v3/pkg/apis/workflow/v1alpha1"
"github.com/stretchr/testify/assert"
)

func TestEmptyThen(t *testing.T) {
Expand All @@ -29,3 +31,18 @@ func TestEmptyThen(t *testing.T) {
})
}
}

func TestDeleteRetryNodes(t *testing.T) {
wf := &wfv1.Workflow{
Status: wfv1.WorkflowStatus{
Nodes: map[string]wfv1.NodeStatus{},
},
}
wf.Status.Nodes["test"] = wfv1.NodeStatus{DisplayName: "test"}
wf.Status.Nodes["test-0"] = wfv1.NodeStatus{DisplayName: "test-(0)"}
wf.Status.Nodes["test-10"] = wfv1.NodeStatus{DisplayName: "test-(10)"}
wf.Status.Nodes["test-100"] = wfv1.NodeStatus{DisplayName: "test-(100)"}

deleteRetryNodes(wf)
assert.Equal(t, 1, len(wf.Status.Nodes))
}

0 comments on commit 62caf5f

Please sign in to comment.