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

Filter workflows in list based on name prefix #1721

Merged
merged 7 commits into from Nov 5, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 17 additions & 2 deletions cmd/argo/commands/list.go
Expand Up @@ -28,6 +28,7 @@ type listFlags struct {
status []string // --status
completed bool // --completed
running bool // --running
prefix string // --prefix
output string // --output
since string // --since
chunkSize int64 // --chunk-size
Expand All @@ -42,6 +43,7 @@ func NewListCommand() *cobra.Command {
Short: "list workflows",
Run: func(cmd *cobra.Command, args []string) {
var wfClient v1alpha1.WorkflowInterface

if listArgs.allNamespaces {
wfClient = InitWorkflowClient(apiv1.NamespaceAll)
} else {
Expand Down Expand Up @@ -82,16 +84,28 @@ func NewListCommand() *cobra.Command {
tmpWorkFlows = append(tmpWorkFlows, wfList.Items...)
}

var tmpWorkFlowsSelected []wfv1.Workflow
if listArgs.prefix == "" {
tmpWorkFlowsSelected = tmpWorkFlows
} else {
tmpWorkFlowsSelected = make([]wfv1.Workflow, 0)
for _, wf := range tmpWorkFlows {
if strings.HasPrefix(wf.ObjectMeta.Name, listArgs.prefix) {
tmpWorkFlowsSelected = append(tmpWorkFlowsSelected, wf)
}
}
}

var workflows []wfv1.Workflow
if listArgs.since == "" {
workflows = tmpWorkFlows
workflows = tmpWorkFlowsSelected
} else {
workflows = make([]wfv1.Workflow, 0)
minTime, err := argotime.ParseSince(listArgs.since)
if err != nil {
log.Fatal(err)
}
for _, wf := range tmpWorkFlows {
for _, wf := range tmpWorkFlowsSelected {
if wf.Status.FinishedAt.IsZero() || wf.ObjectMeta.CreationTimestamp.After(*minTime) {
workflows = append(workflows, wf)
}
Expand All @@ -112,6 +126,7 @@ func NewListCommand() *cobra.Command {
},
}
command.Flags().BoolVar(&listArgs.allNamespaces, "all-namespaces", false, "Show workflows from all namespaces")
command.Flags().StringVar(&listArgs.prefix, "prefix", "", "Filter workflows by prefix")
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")
Expand Down