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

chore(cli): Migrate argo terminate to use API client. See #2116 #2280

Merged
merged 5 commits into from
Feb 24, 2020
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -292,6 +292,19 @@ func (s *CLISuite) TestWorkflowLint() {
})
}

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