From 34d436d0675aae29684801bb534ee3537497c166 Mon Sep 17 00:00:00 2001 From: Alex Collins Date: Mon, 24 Feb 2020 11:41:30 -0800 Subject: [PATCH] chore(cli): Migrate `argo terminate` to use API client. See #2116 (#2280) --- cmd/argo/commands/terminate.go | 39 +++++++++++----------------------- test/e2e/cli_test.go | 13 ++++++++++++ 2 files changed, 25 insertions(+), 27 deletions(-) diff --git a/cmd/argo/commands/terminate.go b/cmd/argo/commands/terminate.go index 97c055fba2eb..c39a8559a240 100644 --- a/cmd/argo/commands/terminate.go +++ b/cmd/argo/commands/terminate.go @@ -2,45 +2,30 @@ package commands import ( "fmt" - "os" "github.com/argoproj/pkg/errors" "github.com/spf13/cobra" "github.com/argoproj/argo/cmd/argo/commands/client" workflowpkg "github.com/argoproj/argo/pkg/apiclient/workflow" - "github.com/argoproj/argo/workflow/util" ) func NewTerminateCommand() *cobra.Command { var command = &cobra.Command{ Use: "terminate WORKFLOW WORKFLOW2...", - Short: "terminate a workflow", + Short: "terminate zero or more workflows", Run: func(cmd *cobra.Command, args []string) { - if len(args) == 0 { - cmd.HelpFunc()(cmd, args) - os.Exit(1) - } - namespace, _, _ := client.Config.Namespace() - if client.ArgoServer != "" { - conn := client.GetClientConn() - apiGRPCClient, ctx := GetWFApiServerGRPCClient(conn) - for _, wfName := range args { - wfUptReq := workflowpkg.WorkflowTerminateRequest{ - Name: wfName, - Namespace: namespace, - } - wf, err := apiGRPCClient.TerminateWorkflow(ctx, &wfUptReq) - errors.CheckError(err) - fmt.Printf("workflow %s terminated\n", wf.Name) - } - } else { - InitWorkflowClient() - for _, name := range args { - err := util.TerminateWorkflow(wfClient, name) - errors.CheckError(err) - fmt.Printf("Workflow '%s' terminated\n", name) - } + + ctx, apiClient := client.NewAPIClient() + serviceClient := apiClient.NewWorkflowServiceClient() + namespace := client.Namespace() + for _, name := range args { + wf, err := serviceClient.TerminateWorkflow(ctx, &workflowpkg.WorkflowTerminateRequest{ + Name: name, + Namespace: namespace, + }) + errors.CheckError(err) + fmt.Printf("workflow %s terminated\n", wf.Name) } }, } diff --git a/test/e2e/cli_test.go b/test/e2e/cli_test.go index 541583a54f08..86a45a833942 100644 --- a/test/e2e/cli_test.go +++ b/test/e2e/cli_test.go @@ -307,6 +307,19 @@ func (s *CLISuite) TestWorkflowRetry() { }) } +func (s *CLISuite) TestWorkflowTerminate() { + s.Given(). + Workflow("@smoke/basic.yaml"). + When(). + SubmitWorkflow(). + Given(). + RunCli([]string{"terminate", "basic"}, func(t *testing.T, output string, err error) { + if assert.NoError(t, err) { + assert.Contains(t, output, "workflow basic terminated") + } + }) +} + func (s *CLISuite) TestTemplate() { s.Run("Lint", func() { s.Given().RunCli([]string{"template", "lint", "smoke/workflow-template-whalesay-template.yaml"}, func(t *testing.T, output string, err error) {