Skip to content

Commit

Permalink
chore(cli): Migrate argo terminate to use API client. See argoproj#…
Browse files Browse the repository at this point in the history
  • Loading branch information
alexec committed Feb 25, 2020
1 parent 9ed3246 commit 34d436d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 27 deletions.
39 changes: 12 additions & 27 deletions cmd/argo/commands/terminate.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
},
}
Expand Down
13 changes: 13 additions & 0 deletions test/e2e/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 34d436d

Please sign in to comment.