forked from argoproj/argo-workflows
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce
argo retry
to retry a failed workflow with the same name (r…
…esolves argoproj#762) onExit and related nodes should never be executed during resubmit/retry (resolves argoproj#780)
- Loading branch information
Showing
4 changed files
with
133 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package commands | ||
|
||
import ( | ||
"os" | ||
|
||
"github.com/argoproj/argo/workflow/common" | ||
log "github.com/sirupsen/logrus" | ||
"github.com/spf13/cobra" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
) | ||
|
||
func NewRetryCommand() *cobra.Command { | ||
var ( | ||
submitArgs submitFlags | ||
) | ||
var command = &cobra.Command{ | ||
Use: "retry WORKFLOW", | ||
Short: "retry a workflow", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
if len(args) == 0 { | ||
cmd.HelpFunc()(cmd, args) | ||
os.Exit(1) | ||
} | ||
kubeClient := initKubeClient() | ||
wfClient := InitWorkflowClient() | ||
wf, err := wfClient.Get(args[0], metav1.GetOptions{}) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
wf, err = common.RetryWorkflow(kubeClient, wfClient, wf) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
printWorkflow(wf, submitArgs.output) | ||
if submitArgs.wait { | ||
wsp := NewWorkflowStatusPoller(wfClient, false, submitArgs.output == "json") | ||
wsp.WaitWorkflows([]string{wf.ObjectMeta.Name}) | ||
} | ||
}, | ||
} | ||
command.Flags().StringVarP(&submitArgs.output, "output", "o", "", "Output format. One of: name|json|yaml|wide") | ||
command.Flags().BoolVarP(&submitArgs.wait, "wait", "w", false, "wait for the workflow to complete") | ||
return command | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package common | ||
|
||
import ( | ||
"testing" | ||
|
||
wfv1 "github.com/argoproj/argo/pkg/apis/workflow/v1alpha1" | ||
"github.com/stretchr/testify/assert" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
) | ||
|
||
// TestResubmitWorkflowWithOnExit ensures we do not carry over the onExit node even if successful | ||
func TestResubmitWorkflowWithOnExit(t *testing.T) { | ||
wfName := "test-wf" | ||
onExitName := wfName + ".onExit" | ||
wf := wfv1.Workflow{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: "test-wf", | ||
}, | ||
Status: wfv1.WorkflowStatus{ | ||
Phase: wfv1.NodeFailed, | ||
Nodes: map[string]wfv1.NodeStatus{}, | ||
}, | ||
} | ||
onExitID := wf.NodeID(onExitName) | ||
wf.Status.Nodes[onExitID] = wfv1.NodeStatus{ | ||
Name: onExitName, | ||
Phase: wfv1.NodeSucceeded, | ||
} | ||
newWF, err := FormulateResubmitWorkflow(&wf, true) | ||
assert.Nil(t, err) | ||
newWFOnExitName := newWF.ObjectMeta.Name + ".onExit" | ||
newWFOneExitID := newWF.NodeID(newWFOnExitName) | ||
_, ok := newWF.Status.Nodes[newWFOneExitID] | ||
assert.False(t, ok) | ||
} |