Skip to content

Commit

Permalink
Filter workflows in list based on name prefix (#1721)
Browse files Browse the repository at this point in the history
  • Loading branch information
sanoojm authored and sarabala1979 committed Dec 5, 2019
1 parent e958127 commit 340ab07
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions cmd/argo/commands/list.go
Original file line number Diff line number Diff line change
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

0 comments on commit 340ab07

Please sign in to comment.