-
Notifications
You must be signed in to change notification settings - Fork 147
feat: add delete command, make cancel abort for k8s (#1156) #1158
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| #!/usr/bin/env python3 | ||
| # Copyright (c) Meta Platforms, Inc. and affiliates. | ||
| # All rights reserved. | ||
| # | ||
| # This source code is licensed under the BSD-style license found in the | ||
| # LICENSE file in the root directory of this source tree. | ||
|
|
||
| # pyre-strict | ||
|
|
||
| import argparse | ||
| import logging | ||
|
|
||
| from torchx.cli.cmd_base import SubCommand | ||
| from torchx.runner import get_runner | ||
|
|
||
| logger: logging.Logger = logging.getLogger(__name__) | ||
|
|
||
|
|
||
| class CmdDelete(SubCommand): | ||
| def add_arguments(self, subparser: argparse.ArgumentParser) -> None: | ||
| subparser.add_argument( | ||
| "app_handle", | ||
| type=str, | ||
| help="torchx app handle (e.g. local://session-name/app-id)", | ||
| ) | ||
|
|
||
| def run(self, args: argparse.Namespace) -> None: | ||
| app_handle = args.app_handle | ||
| runner = get_runner() | ||
| runner.delete(app_handle) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| #!/usr/bin/env python3 | ||
| # Copyright (c) Meta Platforms, Inc. and affiliates. | ||
| # All rights reserved. | ||
| # | ||
| # This source code is licensed under the BSD-style license found in the | ||
| # LICENSE file in the root directory of this source tree. | ||
|
|
||
| # pyre-strict | ||
|
|
||
| import argparse | ||
| import unittest | ||
| from unittest.mock import MagicMock, patch | ||
|
|
||
| from torchx.cli.cmd_delete import CmdDelete | ||
|
|
||
|
|
||
| class CmdDeleteTest(unittest.TestCase): | ||
| @patch("torchx.runner.api.Runner.delete") | ||
| def test_run(self, delete: MagicMock) -> None: | ||
| parser = argparse.ArgumentParser() | ||
| cmd_delete = CmdDelete() | ||
| cmd_delete.add_arguments(parser) | ||
|
|
||
| args = parser.parse_args(["foo://session/id"]) | ||
| cmd_delete.run(args) | ||
|
|
||
| self.assertEqual(delete.call_count, 1) | ||
| delete.assert_called_with("foo://session/id") |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -622,6 +622,16 @@ class KubernetesScheduler( | |
| $ torchx status kubernetes://torchx_user/1234 | ||
| ... | ||
|
|
||
| **Cancellation** | ||
|
|
||
| Canceling a job aborts it while preserving the job spec for inspection | ||
| and cloning via kubectl apply. Use the delete command to remove the job entirely: | ||
|
|
||
| .. code-block:: bash | ||
|
|
||
| $ torchx cancel kubernetes://namespace/jobname # abort, preserves spec | ||
| $ torchx delete kubernetes://namespace/jobname # delete completely | ||
|
|
||
| **Config Options** | ||
|
|
||
| .. runopts:: | ||
|
|
@@ -818,6 +828,33 @@ def _validate(self, app: AppDef, scheduler: str, cfg: KubernetesOpts) -> None: | |
| pass | ||
|
|
||
| def _cancel_existing(self, app_id: str) -> None: | ||
| """ | ||
| Abort a Volcano job while preserving the spec for inspection. | ||
| """ | ||
| namespace, name = app_id.split(":") | ||
| vcjob = self._custom_objects_api().get_namespaced_custom_object( | ||
| group="batch.volcano.sh", | ||
| version="v1alpha1", | ||
| namespace=namespace, | ||
| plural="jobs", | ||
| name=name, | ||
| ) | ||
| vcjob["status"]["state"]["phase"] = "Aborted" | ||
| self._custom_objects_api().replace_namespaced_custom_object_status( | ||
| group="batch.volcano.sh", | ||
| version="v1alpha1", | ||
| namespace=namespace, | ||
| plural="jobs", | ||
| name=name, | ||
| body=vcjob, | ||
| ) | ||
|
|
||
| def delete(self, app_id: str) -> None: | ||
| """ | ||
| Delete a Volcano job completely from the cluster. | ||
| """ | ||
| if not self.exists(app_id): | ||
| return | ||
|
Comment on lines
+856
to
+857
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we're going to have to templetize this behavior also needs to be documented at the parent level (e.g. that calling delete on an |
||
| namespace, name = app_id.split(":") | ||
| self._custom_objects_api().delete_namespaced_custom_object( | ||
| group="batch.volcano.sh", | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.