Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add paging function for list command #1420

Merged
merged 2 commits into from
Jun 19, 2019
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions cmd/argo/commands/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ type listFlags struct {
running bool // --running
output string // --output
since string // --since
limit int64 // --limit
}

func NewListCommand() *cobra.Command {
Expand Down Expand Up @@ -61,20 +62,33 @@ func NewListCommand() *cobra.Command {
labelSelector = labelSelector.Add(*req)
}
listOpts.LabelSelector = labelSelector.String()
listOpts.Limit = listArgs.limit
wfList, err := wfClient.List(listOpts)
if err != nil {
log.Fatal(err)
}

var tmpWorkFlows []wfv1.Workflow
tmpWorkFlows = wfList.Items
for wfList.ListMeta.Continue != "" {
listOpts.Continue = wfList.ListMeta.Continue
wfList, err = wfClient.List(listOpts)
if err != nil {
log.Fatal(err)
}
tmpWorkFlows = append(tmpWorkFlows, wfList.Items...)
}

var workflows []wfv1.Workflow
if listArgs.since == "" {
workflows = wfList.Items
workflows = tmpWorkFlows
} else {
workflows = make([]wfv1.Workflow, 0)
minTime, err := argotime.ParseSince(listArgs.since)
if err != nil {
log.Fatal(err)
}
for _, wf := range wfList.Items {
for _, wf := range tmpWorkFlows {
if wf.Status.FinishedAt.IsZero() || wf.ObjectMeta.CreationTimestamp.After(*minTime) {
workflows = append(workflows, wf)
}
Expand All @@ -100,6 +114,7 @@ func NewListCommand() *cobra.Command {
command.Flags().BoolVar(&listArgs.running, "running", false, "Show only running workflows")
command.Flags().StringVarP(&listArgs.output, "output", "o", "", "Output format. One of: wide|name")
command.Flags().StringVar(&listArgs.since, "since", "", "Show only workflows newer than a relative duration")
command.Flags().Int64VarP(&listArgs.limit, "limit", "", 100, "Limit per num in one request")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The limit flag is misleading here. Here the limit flag is used internally request size, not for output. Can you come up with a different name?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think limit flag should have default 100? All user list will have to make multiple API call. Can we leave it to the user to pass the values once they get an error?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can use the same as kubectl
--chunk-size=500: Return large lists in chunks rather than all at once. Pass 0 to disable. This flag is beta and
may change in the future.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sarabala1979 Thank you for your review.

Already change code as your comments, pls help review again , thanks.

return command
}

Expand Down