Skip to content

Commit

Permalink
fix: Fix inconsistent ordering of workflows with the list command. Fixes
Browse files Browse the repository at this point in the history
 #7581 (#7594)

Signed-off-by: Peixuan Ding <dingpeixuan911@gmail.com>
  • Loading branch information
dinever authored Jan 20, 2022
1 parent af257c1 commit bc27ada
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
3 changes: 2 additions & 1 deletion cmd/argo/commands/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ type listFlags struct {
}

var (
nameFields = "metadata,items.metadata.name"
// finishedAt and creationTimestamp must be included to have a consistent display order of workflows
nameFields = "metadata,items.metadata.name,items.metadata.creationTimestamp,items.status.finishedAt"
defaultFields = "metadata,items.metadata,items.spec,items.status.phase,items.status.message,items.status.finishedAt,items.status.startedAt,items.status.estimatedDuration,items.status.progress"
)

Expand Down
12 changes: 11 additions & 1 deletion cmd/argo/commands/list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,21 @@ func Test_listWorkflows(t *testing.T) {
assert.Len(t, workflows, 1)
}
})
t.Run("Names", func(t *testing.T) {
workflows, err := list(&metav1.ListOptions{FieldSelector: nameFields}, listFlags{fields: nameFields})
if assert.NoError(t, err) {
assert.Len(t, workflows, 3)
// most recent workflow will be shown first
assert.Equal(t, "bar-", workflows[0].Name)
assert.Equal(t, "baz-", workflows[1].Name)
assert.Equal(t, "foo-", workflows[2].Name)
}
})
}

func list(listOptions *metav1.ListOptions, flags listFlags) (wfv1.Workflows, error) {
c := &workflowmocks.WorkflowServiceClient{}
c.On("ListWorkflows", mock.Anything, &workflow.WorkflowListRequest{ListOptions: listOptions, Fields: defaultFields}).Return(&wfv1.WorkflowList{Items: wfv1.Workflows{
c.On("ListWorkflows", mock.Anything, &workflow.WorkflowListRequest{ListOptions: listOptions, Fields: flags.displayFields()}).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{
Expand Down

0 comments on commit bc27ada

Please sign in to comment.