Skip to content

Commit

Permalink
feat: add argo delete --force. Fixes #9315. (#9321)
Browse files Browse the repository at this point in the history
Signed-off-by: Dillen Padhiar <dillen_padhiar@intuit.com>
  • Loading branch information
dpadhiar authored Aug 16, 2022
1 parent bcc9ea1 commit 6d08098
Show file tree
Hide file tree
Showing 9 changed files with 168 additions and 97 deletions.
5 changes: 5 additions & 0 deletions api/openapi-spec/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -3081,6 +3081,11 @@
"description": "When present, indicates that modifications should not be\npersisted. An invalid or unrecognized dryRun directive will\nresult in an error response and no further processing of the\nrequest. Valid values are:\n- All: all dry run stages will be processed\n+optional.",
"name": "deleteOptions.dryRun",
"in": "query"
},
{
"type": "boolean",
"name": "force",
"in": "query"
}
],
"responses": {
Expand Down
6 changes: 4 additions & 2 deletions cmd/argo/commands/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@ func NewDeleteCommand() *cobra.Command {
all bool
allNamespaces bool
dryRun bool
force bool
)
command := &cobra.Command{
Use: "delete [--dry-run] [WORKFLOW...|[--all] [--older] [--completed] [--resubmitted] [--prefix PREFIX] [--selector SELECTOR]]",
Use: "delete [--dry-run] [WORKFLOW...|[--all] [--older] [--completed] [--resubmitted] [--prefix PREFIX] [--selector SELECTOR] [--force] ]",
Short: "delete workflows",
Example: `# Delete a workflow:
Expand Down Expand Up @@ -64,7 +65,7 @@ func NewDeleteCommand() *cobra.Command {

for _, wf := range workflows {
if !dryRun {
_, err := serviceClient.DeleteWorkflow(ctx, &workflowpkg.WorkflowDeleteRequest{Name: wf.Name, Namespace: wf.Namespace})
_, err := serviceClient.DeleteWorkflow(ctx, &workflowpkg.WorkflowDeleteRequest{Name: wf.Name, Namespace: wf.Namespace, Force: force})
if err != nil && status.Code(err) == codes.NotFound {
fmt.Printf("Workflow '%s' not found\n", wf.Name)
continue
Expand All @@ -87,5 +88,6 @@ func NewDeleteCommand() *cobra.Command {
command.Flags().StringVarP(&flags.labels, "selector", "l", "", "Selector (label query) to filter on, not including uninitialized ones, supports '=', '==', and '!='.(e.g. -l key1=value1,key2=value2)")
command.Flags().StringVar(&flags.fields, "field-selector", "", "Selector (field query) to filter on, supports '=', '==', and '!='.(e.g. --field-selector key1=value1,key2=value2). The server only supports a limited number of field queries per type.")
command.Flags().BoolVar(&dryRun, "dry-run", false, "Do not delete the workflow, only print what would happen")
command.Flags().BoolVar(&force, "force", false, "Force delete workflows by removing finalizers")
return command
}
3 changes: 2 additions & 1 deletion docs/cli/argo_delete.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
delete workflows

```
argo delete [--dry-run] [WORKFLOW...|[--all] [--older] [--completed] [--resubmitted] [--prefix PREFIX] [--selector SELECTOR]] [flags]
argo delete [--dry-run] [WORKFLOW...|[--all] [--older] [--completed] [--resubmitted] [--prefix PREFIX] [--selector SELECTOR] [--force] ] [flags]
```

### Examples
Expand All @@ -27,6 +27,7 @@ argo delete [--dry-run] [WORKFLOW...|[--all] [--older] [--completed] [--resubmit
--completed Delete completed workflows
--dry-run Do not delete the workflow, only print what would happen
--field-selector string Selector (field query) to filter on, supports '=', '==', and '!='.(e.g. --field-selector key1=value1,key2=value2). The server only supports a limited number of field queries per type.
--force Force delete workflows by removing finalizers
-h, --help help for delete
--older string Delete completed workflows finished before the specified duration (e.g. 10m, 3h, 1d)
--prefix string Delete workflows by prefix
Expand Down
224 changes: 133 additions & 91 deletions pkg/apiclient/workflow/workflow.pb.go

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions pkg/apiclient/workflow/workflow.proto
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ message WorkflowDeleteRequest {
string name = 1;
string namespace = 2;
k8s.io.apimachinery.pkg.apis.meta.v1.DeleteOptions deleteOptions = 3;
bool force = 4;
}

message WorkflowDeleteResponse {
Expand Down
6 changes: 4 additions & 2 deletions sdks/java/client/docs/WorkflowServiceApi.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ Name | Type | Description | Notes

<a name="workflowServiceDeleteWorkflow"></a>
# **workflowServiceDeleteWorkflow**
> Object workflowServiceDeleteWorkflow(namespace, name, deleteOptionsGracePeriodSeconds, deleteOptionsPreconditionsUid, deleteOptionsPreconditionsResourceVersion, deleteOptionsOrphanDependents, deleteOptionsPropagationPolicy, deleteOptionsDryRun)
> Object workflowServiceDeleteWorkflow(namespace, name, deleteOptionsGracePeriodSeconds, deleteOptionsPreconditionsUid, deleteOptionsPreconditionsResourceVersion, deleteOptionsOrphanDependents, deleteOptionsPropagationPolicy, deleteOptionsDryRun, force)


Expand Down Expand Up @@ -129,8 +129,9 @@ public class Example {
Boolean deleteOptionsOrphanDependents = true; // Boolean | Deprecated: please use the PropagationPolicy, this field will be deprecated in 1.7. Should the dependent objects be orphaned. If true/false, the \"orphan\" finalizer will be added to/removed from the object's finalizers list. Either this field or PropagationPolicy may be set, but not both. +optional.
String deleteOptionsPropagationPolicy = "deleteOptionsPropagationPolicy_example"; // String | Whether and how garbage collection will be performed. Either this field or OrphanDependents may be set, but not both. The default policy is decided by the existing finalizer set in the metadata.finalizers and the resource-specific default policy. Acceptable values are: 'Orphan' - orphan the dependents; 'Background' - allow the garbage collector to delete the dependents in the background; 'Foreground' - a cascading policy that deletes all dependents in the foreground. +optional.
List<String> deleteOptionsDryRun = Arrays.asList(); // List<String> | When present, indicates that modifications should not be persisted. An invalid or unrecognized dryRun directive will result in an error response and no further processing of the request. Valid values are: - All: all dry run stages will be processed +optional.
Boolean force = true; // Boolean |
try {
Object result = apiInstance.workflowServiceDeleteWorkflow(namespace, name, deleteOptionsGracePeriodSeconds, deleteOptionsPreconditionsUid, deleteOptionsPreconditionsResourceVersion, deleteOptionsOrphanDependents, deleteOptionsPropagationPolicy, deleteOptionsDryRun);
Object result = apiInstance.workflowServiceDeleteWorkflow(namespace, name, deleteOptionsGracePeriodSeconds, deleteOptionsPreconditionsUid, deleteOptionsPreconditionsResourceVersion, deleteOptionsOrphanDependents, deleteOptionsPropagationPolicy, deleteOptionsDryRun, force);
System.out.println(result);
} catch (ApiException e) {
System.err.println("Exception when calling WorkflowServiceApi#workflowServiceDeleteWorkflow");
Expand All @@ -155,6 +156,7 @@ Name | Type | Description | Notes
**deleteOptionsOrphanDependents** | **Boolean**| Deprecated: please use the PropagationPolicy, this field will be deprecated in 1.7. Should the dependent objects be orphaned. If true/false, the \&quot;orphan\&quot; finalizer will be added to/removed from the object&#39;s finalizers list. Either this field or PropagationPolicy may be set, but not both. +optional. | [optional]
**deleteOptionsPropagationPolicy** | **String**| Whether and how garbage collection will be performed. Either this field or OrphanDependents may be set, but not both. The default policy is decided by the existing finalizer set in the metadata.finalizers and the resource-specific default policy. Acceptable values are: &#39;Orphan&#39; - orphan the dependents; &#39;Background&#39; - allow the garbage collector to delete the dependents in the background; &#39;Foreground&#39; - a cascading policy that deletes all dependents in the foreground. +optional. | [optional]
**deleteOptionsDryRun** | [**List&lt;String&gt;**](String.md)| When present, indicates that modifications should not be persisted. An invalid or unrecognized dryRun directive will result in an error response and no further processing of the request. Valid values are: - All: all dry run stages will be processed +optional. | [optional]
**force** | **Boolean**| | [optional]

### Return type

Expand Down
6 changes: 6 additions & 0 deletions sdks/python/client/argo_workflows/api/workflow_service_api.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion sdks/python/client/docs/WorkflowServiceApi.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions server/workflow/workflow_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
corev1 "k8s.io/api/core/v1"
apierr "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"

"github.com/argoproj/argo-workflows/v3/errors"
"github.com/argoproj/argo-workflows/v3/persist/sqldb"
Expand Down Expand Up @@ -298,6 +299,15 @@ func (s *workflowServer) DeleteWorkflow(ctx context.Context, req *workflowpkg.Wo
if err != nil {
return nil, err
}
if wf.Finalizers != nil && !req.Force {
return nil, fmt.Errorf("%s has finalizer. Use argo delete --force to delete this workflow", wf.Name)
}
if req.Force {
_, err := auth.GetWfClient(ctx).ArgoprojV1alpha1().Workflows(wf.Namespace).Patch(ctx, wf.Name, types.MergePatchType, []byte("{\"metadata\":{\"finalizers\":null}}"), metav1.PatchOptions{})
if err != nil {
return nil, err
}
}
err = auth.GetWfClient(ctx).ArgoprojV1alpha1().Workflows(wf.Namespace).Delete(ctx, wf.Name, metav1.DeleteOptions{PropagationPolicy: argoutil.GetDeletePropagation()})
if err != nil {
return nil, err
Expand Down

0 comments on commit 6d08098

Please sign in to comment.