Skip to content

Commit

Permalink
feat(cli): List only resubmitted workflows option (argoproj#3357)
Browse files Browse the repository at this point in the history
  • Loading branch information
terrytangyuan authored Jul 14, 2020
1 parent 25e9c0c commit 48e15d6
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
6 changes: 6 additions & 0 deletions cmd/argo/commands/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ type listFlags struct {
status []string
completed bool
running bool
resubmitted bool
prefix string
output string
createdSince string
Expand Down Expand Up @@ -66,6 +67,7 @@ func NewListCommand() *cobra.Command {
command.Flags().StringSliceVar(&listArgs.status, "status", []string{}, "Filter by status (comma separated)")
command.Flags().BoolVar(&listArgs.completed, "completed", false, "Show only completed workflows")
command.Flags().BoolVar(&listArgs.running, "running", false, "Show only running workflows")
command.Flags().BoolVar(&listArgs.resubmitted, "resubmitted", false, "Show only resubmitted workflows")
command.Flags().StringVarP(&listArgs.output, "output", "o", "", "Output format. One of: wide|name")
command.Flags().StringVar(&listArgs.createdSince, "since", "", "Show only workflows created after than a relative duration")
command.Flags().Int64VarP(&listArgs.chunkSize, "chunk-size", "", 0, "Return large lists in chunks rather than all at once. Pass 0 to disable.")
Expand Down Expand Up @@ -95,6 +97,10 @@ func listWorkflows(ctx context.Context, serviceClient workflowpkg.WorkflowServic
req, _ := labels.NewRequirement(common.LabelKeyCompleted, selection.NotEquals, []string{"true"})
labelSelector = labelSelector.Add(*req)
}
if flags.resubmitted {
req, _ := labels.NewRequirement(common.LabelKeyPreviousWorkflowName, selection.Exists, []string{})
labelSelector = labelSelector.Add(*req)
}
listOpts.LabelSelector = labelSelector.String()
listOpts.FieldSelector = flags.fields
var workflows wfv1.Workflows
Expand Down
13 changes: 13 additions & 0 deletions cmd/argo/commands/list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
"testing"
"time"

"github.com/argoproj/argo/workflow/common"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -39,6 +41,12 @@ func Test_listWorkflows(t *testing.T) {
assert.NotNil(t, workflows)
}
})
t.Run("Resubmitted", func(t *testing.T) {
workflows, err := list(&metav1.ListOptions{LabelSelector: common.LabelKeyPreviousWorkflowName}, listFlags{resubmitted: true})
if assert.NoError(t, err) {
assert.NotNil(t, workflows)
}
})
t.Run("Labels", func(t *testing.T) {
workflows, err := list(&metav1.ListOptions{LabelSelector: "foo"}, listFlags{labels: "foo"})
if assert.NoError(t, err) {
Expand Down Expand Up @@ -70,6 +78,11 @@ func list(listOptions *metav1.ListOptions, flags listFlags) (wfv1.Workflows, err
c.On("ListWorkflows", mock.Anything, &workflow.WorkflowListRequest{ListOptions: listOptions}).Return(&wfv1.WorkflowList{Items: wfv1.Workflows{
{ObjectMeta: metav1.ObjectMeta{Name: "foo-", CreationTimestamp: metav1.Time{Time: time.Now().Add(-2 * time.Hour)}}, Status: wfv1.WorkflowStatus{FinishedAt: metav1.Time{Time: time.Now().Add(-2 * time.Hour)}}},
{ObjectMeta: metav1.ObjectMeta{Name: "bar-", CreationTimestamp: metav1.Time{Time: time.Now()}}},
{ObjectMeta: metav1.ObjectMeta{
Name: "baz-",
CreationTimestamp: metav1.Time{Time: time.Now().Add(-2 * time.Hour)},
Labels: map[string]string{common.LabelKeyPreviousWorkflowName: "foo-"},
}},
}}, nil)
workflows, err := listWorkflows(context.Background(), c, flags)
return workflows, err
Expand Down

0 comments on commit 48e15d6

Please sign in to comment.