Skip to content

Commit

Permalink
Revert "feat(cli): add selector and field-selector option to the stop…
Browse files Browse the repository at this point in the history
… command. (argoproj#4853)"

This reverts commit 53f7998.

Signed-off-by: Alex Collins <[email protected]>
  • Loading branch information
alexec committed Jan 17, 2021
1 parent 53f7998 commit 16f25ba
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 110 deletions.
71 changes: 12 additions & 59 deletions cmd/argo/commands/stop.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,49 +3,24 @@ package commands
import (
"fmt"
"log"
"os"

"github.com/argoproj/pkg/errors"
"github.com/spf13/cobra"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/fields"

"github.com/argoproj/argo/cmd/argo/commands/client"
workflowpkg "github.com/argoproj/argo/pkg/apiclient/workflow"
wfv1 "github.com/argoproj/argo/pkg/apis/workflow/v1alpha1"
)

type stopOps struct {
namespace string
labelSelector string
fieldSelector string
message string // --message
nodeFieldSelector string // --node-field-selector
dryRun bool
}

func (o *stopOps) isList() bool {
if o.labelSelector != "" || o.fieldSelector != "" {
return true
}

return false
}

func (o *stopOps) convertToWorkflows(names []string) wfv1.Workflows {
var wfs wfv1.Workflows

for _, n := range names {
wfs = append(wfs, wfv1.Workflow{
ObjectMeta: metav1.ObjectMeta{Name: n, Namespace: o.namespace},
})
}

return wfs
}

func NewStopCommand() *cobra.Command {
o := &stopOps{}
var (
stopArgs stopOps
)

var command = &cobra.Command{
Use: "stop WORKFLOW WORKFLOW2...",
Expand All @@ -58,51 +33,29 @@ func NewStopCommand() *cobra.Command {
argo stop @latest
`,
Run: func(cmd *cobra.Command, args []string) {
if len(args) == 0 && !o.isList() {
cmd.HelpFunc()(cmd, args)
os.Exit(1)
}

ctx, apiClient := client.NewAPIClient()
serviceClient := apiClient.NewWorkflowServiceClient()
o.namespace = client.Namespace()
namespace := client.Namespace()

selector, err := fields.ParseSelector(o.nodeFieldSelector)
selector, err := fields.ParseSelector(stopArgs.nodeFieldSelector)
if err != nil {
log.Fatalf("Unable to parse node field selector '%s': %s", o.nodeFieldSelector, err)
log.Fatalf("Unable to parse node field selector '%s': %s", stopArgs.nodeFieldSelector, err)
}

workflows := o.convertToWorkflows(args)

listed, err := listWorkflows(ctx, serviceClient, listFlags{
namespace: o.namespace,
fields: o.fieldSelector,
labels: o.labelSelector,
})
errors.CheckError(err)
workflows = append(workflows, listed...)

for _, w := range workflows {
if o.dryRun {
fmt.Printf("workflow %s stopped (dry-run)\n", w.Name)
continue
}

for _, name := range args {
wf, err := serviceClient.StopWorkflow(ctx, &workflowpkg.WorkflowStopRequest{
Name: w.Name,
Namespace: w.Namespace,
Name: name,
Namespace: namespace,
NodeFieldSelector: selector.String(),
Message: o.message,
Message: stopArgs.message,
})
errors.CheckError(err)
fmt.Printf("workflow %s stopped\n", wf.Name)
}
},
}
command.Flags().StringVarP(&o.labelSelector, "selector", "l", "", "Selector (label query) to filter on, not including uninitialized ones")
command.Flags().StringVar(&o.fieldSelector, "field-selector", "", "Selector (field query) to filter on, supports '=', '==', and '!='.(e.g. --field-selectorkey1=value1,key2=value2). The server only supports a limited number of field queries per type.")
command.Flags().StringVar(&o.message, "message", "", "Message to add to previously running nodes")
command.Flags().StringVar(&o.nodeFieldSelector, "node-field-selector", "", "selector of node to stop, eg: --node-field-selector inputs.paramaters.myparam.value=abc")
command.Flags().BoolVar(&o.dryRun, "dry-run", false, "Do not stop the workflow, only print what would happen")
command.Flags().StringVar(&stopArgs.message, "message", "", "Message to add to previously running nodes")
command.Flags().StringVar(&stopArgs.nodeFieldSelector, "node-field-selector", "", "selector of node to stop, eg: --node-field-selector inputs.paramaters.myparam.value=abc")
return command
}
3 changes: 0 additions & 3 deletions docs/cli/argo_stop.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,9 @@ argo stop WORKFLOW WORKFLOW2... [flags]
### Options

```
--dry-run Do not stop the workflow, only print what would happen
--field-selector string Selector (field query) to filter on, supports '=', '==', and '!='.(e.g. --field-selectorkey1=value1,key2=value2). The server only supports a limited number of field queries per type.
-h, --help help for stop
--message string Message to add to previously running nodes
--node-field-selector string selector of node to stop, eg: --node-field-selector inputs.paramaters.myparam.value=abc
-l, --selector string Selector (label query) to filter on, not including uninitialized ones
```

### Options inherited from parent commands
Expand Down
48 changes: 0 additions & 48 deletions test/e2e/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -784,54 +784,6 @@ func (s *CLISuite) TestWorkflowRetry() {
})
}

func (s *CLISuite) TestWorkflowStop() {
s.Given().
Workflow("@testdata/basic-workflow.yaml").
When().
SubmitWorkflow().
RunCli([]string{"stop", "basic"}, func(t *testing.T, output string, err error) {
if assert.NoError(t, err) {
assert.Regexp(t, "workflow basic stopped", output)
}
})
}

func (s *CLISuite) TestWorkflowStopDryRun() {
s.Given().
Workflow("@testdata/basic-workflow.yaml").
When().
SubmitWorkflow().
RunCli([]string{"stop", "--dry-run", "basic"}, func(t *testing.T, output string, err error) {
if assert.NoError(t, err) {
assert.Regexp(t, "workflow basic stopped \\(dry-run\\)", output)
}
})
}

func (s *CLISuite) TestWorkflowStopBySelector() {
s.Given().
Workflow("@testdata/basic-workflow.yaml").
When().
SubmitWorkflow().
RunCli([]string{"stop", "--selector", "argo-e2e=true"}, func(t *testing.T, output string, err error) {
if assert.NoError(t, err) {
assert.Regexp(t, "workflow basic stopped", output)
}
})
}

func (s *CLISuite) TestWorkflowStopByFieldSelector() {
s.Given().
Workflow("@testdata/basic-workflow.yaml").
When().
SubmitWorkflow().
RunCli([]string{"stop", "--field-selector", "metadata.name=basic"}, func(t *testing.T, output string, err error) {
if assert.NoError(t, err) {
assert.Regexp(t, "workflow basic stopped", output)
}
})
}

func (s *CLISuite) TestWorkflowTerminate() {
var name string
s.Given().
Expand Down

0 comments on commit 16f25ba

Please sign in to comment.