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 all commits
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
21 changes: 19 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
chunkSize int64 // --chunk-size
}

func NewListCommand() *cobra.Command {
Expand Down Expand Up @@ -61,20 +62,35 @@ func NewListCommand() *cobra.Command {
labelSelector = labelSelector.Add(*req)
}
listOpts.LabelSelector = labelSelector.String()
if listArgs.chunkSize != 0 {
listOpts.Limit = listArgs.chunkSize
}
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 +116,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.chunkSize, "chunk-size", "", 500, "Return large lists in chunks rather than all at once. Pass 0 to disable.")
return command
}

Expand Down