From 292cec53b3101659ea46afb37ed502a2a3379d95 Mon Sep 17 00:00:00 2001 From: Sanooj Date: Thu, 31 Oct 2019 21:40:31 +0530 Subject: [PATCH 1/6] Filter workflows in list based on name prefix --- cmd/argo/commands/list.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/cmd/argo/commands/list.go b/cmd/argo/commands/list.go index fa2bf7ae705f..9091b15c61dc 100644 --- a/cmd/argo/commands/list.go +++ b/cmd/argo/commands/list.go @@ -38,7 +38,7 @@ func NewListCommand() *cobra.Command { listArgs listFlags ) var command = &cobra.Command{ - Use: "list", + Use: "list [WORKFLOW]", Short: "list workflows", Run: func(cmd *cobra.Command, args []string) { var wfClient v1alpha1.WorkflowInterface @@ -101,7 +101,7 @@ func NewListCommand() *cobra.Command { switch listArgs.output { case "", "wide": - printTable(workflows, &listArgs) + printTable(args, workflows, &listArgs) case "name": for _, wf := range workflows { fmt.Println(wf.ObjectMeta.Name) @@ -121,7 +121,7 @@ func NewListCommand() *cobra.Command { return command } -func printTable(wfList []wfv1.Workflow, listArgs *listFlags) { +func printTable(args []string, wfList []wfv1.Workflow, listArgs *listFlags) { w := tabwriter.NewWriter(os.Stdout, 0, 0, 3, ' ', 0) if listArgs.allNamespaces { fmt.Fprint(w, "NAMESPACE\t") @@ -132,6 +132,9 @@ func printTable(wfList []wfv1.Workflow, listArgs *listFlags) { } fmt.Fprint(w, "\n") for _, wf := range wfList { + if len(args) !=0 && ! strings.HasPrefix(wf.ObjectMeta.Name, args[0]) { + continue + } ageStr := humanize.RelativeDurationShort(wf.ObjectMeta.CreationTimestamp.Time, time.Now()) durationStr := humanize.RelativeDurationShort(wf.Status.StartedAt.Time, wf.Status.FinishedAt.Time) if listArgs.allNamespaces { From db22c3ecc74cdb25347292498bb19d557655e347 Mon Sep 17 00:00:00 2001 From: Sanooj Date: Thu, 31 Oct 2019 22:12:53 +0530 Subject: [PATCH 2/6] Fixing lint --- cmd/argo/commands/list.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/argo/commands/list.go b/cmd/argo/commands/list.go index 9091b15c61dc..8b439e0d68aa 100644 --- a/cmd/argo/commands/list.go +++ b/cmd/argo/commands/list.go @@ -132,7 +132,7 @@ func printTable(args []string, wfList []wfv1.Workflow, listArgs *listFlags) { } fmt.Fprint(w, "\n") for _, wf := range wfList { - if len(args) !=0 && ! strings.HasPrefix(wf.ObjectMeta.Name, args[0]) { + if len(args) != 0 && !strings.HasPrefix(wf.ObjectMeta.Name, args[0]) { continue } ageStr := humanize.RelativeDurationShort(wf.ObjectMeta.CreationTimestamp.Time, time.Now()) From e4a562801e5c09dc5ca5d7c348272acd0677e3ed Mon Sep 17 00:00:00 2001 From: Sanooj Date: Sat, 2 Nov 2019 12:44:13 +0530 Subject: [PATCH 3/6] Adding prefix filter rules --- cmd/argo/commands/list.go | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/cmd/argo/commands/list.go b/cmd/argo/commands/list.go index 8b439e0d68aa..b947346c33ca 100644 --- a/cmd/argo/commands/list.go +++ b/cmd/argo/commands/list.go @@ -25,6 +25,7 @@ import ( type listFlags struct { allNamespaces bool // --all-namespaces + prefix string // --prefix status []string // --status completed bool // --completed running bool // --running @@ -38,10 +39,11 @@ func NewListCommand() *cobra.Command { listArgs listFlags ) var command = &cobra.Command{ - Use: "list [WORKFLOW]", + Use: "list", Short: "list workflows", Run: func(cmd *cobra.Command, args []string) { var wfClient v1alpha1.WorkflowInterface + if listArgs.allNamespaces { wfClient = InitWorkflowClient(apiv1.NamespaceAll) } else { @@ -82,16 +84,28 @@ func NewListCommand() *cobra.Command { tmpWorkFlows = append(tmpWorkFlows, wfList.Items...) } + var tmpWorkFlowsSelcted []wfv1.Workflow + if listArgs.prefix == "" { + tmpWorkFlowsSelcted = tmpWorkFlows + } else { + tmpWorkFlowsSelcted = make([]wfv1.Workflow, 0) + for _, wf := range tmpWorkFlows { + if strings.HasPrefix(wf.ObjectMeta.Name, listArgs.prefix) { + tmpWorkFlowsSelcted = append(tmpWorkFlowsSelcted, wf) + } + } + } + var workflows []wfv1.Workflow if listArgs.since == "" { - workflows = tmpWorkFlows + workflows = tmpWorkFlowsSelcted } 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 tmpWorkFlowsSelcted { if wf.Status.FinishedAt.IsZero() || wf.ObjectMeta.CreationTimestamp.After(*minTime) { workflows = append(workflows, wf) } @@ -101,7 +115,7 @@ func NewListCommand() *cobra.Command { switch listArgs.output { case "", "wide": - printTable(args, workflows, &listArgs) + printTable(workflows, &listArgs) case "name": for _, wf := range workflows { fmt.Println(wf.ObjectMeta.Name) @@ -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", "", "Show only workflows with names has 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") @@ -121,7 +136,7 @@ func NewListCommand() *cobra.Command { return command } -func printTable(args []string, wfList []wfv1.Workflow, listArgs *listFlags) { +func printTable(wfList []wfv1.Workflow, listArgs *listFlags) { w := tabwriter.NewWriter(os.Stdout, 0, 0, 3, ' ', 0) if listArgs.allNamespaces { fmt.Fprint(w, "NAMESPACE\t") @@ -132,9 +147,6 @@ func printTable(args []string, wfList []wfv1.Workflow, listArgs *listFlags) { } fmt.Fprint(w, "\n") for _, wf := range wfList { - if len(args) != 0 && !strings.HasPrefix(wf.ObjectMeta.Name, args[0]) { - continue - } ageStr := humanize.RelativeDurationShort(wf.ObjectMeta.CreationTimestamp.Time, time.Now()) durationStr := humanize.RelativeDurationShort(wf.Status.StartedAt.Time, wf.Status.FinishedAt.Time) if listArgs.allNamespaces { From dcf247de8c81dad9e3fe695f1dfbb81bda371875 Mon Sep 17 00:00:00 2001 From: Sanooj Date: Sat, 2 Nov 2019 12:45:27 +0530 Subject: [PATCH 4/6] Adding prefix filter rules --- cmd/argo/commands/list.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/cmd/argo/commands/list.go b/cmd/argo/commands/list.go index b947346c33ca..027947b2a4ca 100644 --- a/cmd/argo/commands/list.go +++ b/cmd/argo/commands/list.go @@ -84,28 +84,28 @@ func NewListCommand() *cobra.Command { tmpWorkFlows = append(tmpWorkFlows, wfList.Items...) } - var tmpWorkFlowsSelcted []wfv1.Workflow + var tmpWorkFlowsSelected []wfv1.Workflow if listArgs.prefix == "" { - tmpWorkFlowsSelcted = tmpWorkFlows + tmpWorkFlowsSelected = tmpWorkFlows } else { - tmpWorkFlowsSelcted = make([]wfv1.Workflow, 0) + tmpWorkFlowsSelected = make([]wfv1.Workflow, 0) for _, wf := range tmpWorkFlows { if strings.HasPrefix(wf.ObjectMeta.Name, listArgs.prefix) { - tmpWorkFlowsSelcted = append(tmpWorkFlowsSelcted, wf) + tmpWorkFlowsSelected = append(tmpWorkFlowsSelected, wf) } } } var workflows []wfv1.Workflow if listArgs.since == "" { - workflows = tmpWorkFlowsSelcted + workflows = tmpWorkFlowsSelected } else { workflows = make([]wfv1.Workflow, 0) minTime, err := argotime.ParseSince(listArgs.since) if err != nil { log.Fatal(err) } - for _, wf := range tmpWorkFlowsSelcted { + for _, wf := range tmpWorkFlowsSelected { if wf.Status.FinishedAt.IsZero() || wf.ObjectMeta.CreationTimestamp.After(*minTime) { workflows = append(workflows, wf) } From e2e9736f2ac2a64e26b9b7ce175a5e2dda080c32 Mon Sep 17 00:00:00 2001 From: Sanooj Date: Sat, 2 Nov 2019 12:45:27 +0530 Subject: [PATCH 5/6] Adding prefix filter rules --- cmd/argo/commands/list.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/argo/commands/list.go b/cmd/argo/commands/list.go index 027947b2a4ca..20dba3a43a07 100644 --- a/cmd/argo/commands/list.go +++ b/cmd/argo/commands/list.go @@ -25,10 +25,10 @@ import ( type listFlags struct { allNamespaces bool // --all-namespaces - prefix string // --prefix status []string // --status completed bool // --completed running bool // --running + prefix string // --prefix output string // --output since string // --since chunkSize int64 // --chunk-size From 3681086741c255becd29785fd0f98f5c696dc27e Mon Sep 17 00:00:00 2001 From: Sanooj Date: Sun, 3 Nov 2019 03:51:55 +0530 Subject: [PATCH 6/6] Prefix help statement --- cmd/argo/commands/list.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/argo/commands/list.go b/cmd/argo/commands/list.go index 20dba3a43a07..218c35404228 100644 --- a/cmd/argo/commands/list.go +++ b/cmd/argo/commands/list.go @@ -126,7 +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", "", "Show only workflows with names has prefix") + 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")