From c49ea0673166b82136c22cb0a43ba23430d0f3a1 Mon Sep 17 00:00:00 2001 From: Stanislav Khlud Date: Wed, 9 Oct 2024 15:03:57 +0700 Subject: [PATCH] Add ability to set `dump_dir` for `K8SDBSettings` --- CHANGELOG.md | 1 + README.md | 1 + saritasa_invocations/_config.py | 1 + saritasa_invocations/db_k8s.py | 7 ++++--- 4 files changed, 7 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ccf9a06..b29ab71 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ We follow [Semantic Versions](https://semver.org/). ## unreleased - Add params for `system.chown`(`owner` and `path`) +- Add ability to set `dump_dir` for `K8SDBSettings` ## 1.2.3 diff --git a/README.md b/README.md index 5fa047c..d31ad55 100644 --- a/README.md +++ b/README.md @@ -885,6 +885,7 @@ Settings: * `get_pod_name_command` template for fetching db pod (Default located in `_config.pp > K8SdbSettings`) * `dump_filename` default dump filename (Default: Name of project from `project_name` plus `_db_dump`) * `dump_command` dump command template (Default located in `_config.pp > K8SDBSettings`) +* `dump_dir` folder where to put dump file (Default: `tmp`) * `dump_additional_params` additional dump commands (Default: `--no-owner`) #### db-k8s.get-dump diff --git a/saritasa_invocations/_config.py b/saritasa_invocations/_config.py index 75492c3..f73a033 100644 --- a/saritasa_invocations/_config.py +++ b/saritasa_invocations/_config.py @@ -245,6 +245,7 @@ class K8SDBSettings: exec_command: str = ( "kubectl exec -ti --namespace {db_pod_namespace} $({db_pod})" ) + dump_dir: str = "tmp" dump_command: str = ( "pg_dump " "{additional_params} " diff --git a/saritasa_invocations/db_k8s.py b/saritasa_invocations/db_k8s.py index 0ff9431..f2054be 100644 --- a/saritasa_invocations/db_k8s.py +++ b/saritasa_invocations/db_k8s.py @@ -50,15 +50,16 @@ def get_dump( file = _get_db_k8s_dump_filename(context, file) k8s.success(context, f"Downloading dump ({file}) from pod") + dump_path = f"{config.dump_dir}/{file}" k8s.download_file_from_pod( context, pod_namespace=config.namespace, get_pod_name_command=_generate_get_pod_name_command(context), - path_to_file_in_pod=f"tmp/{file}", + path_to_file_in_pod=dump_path, path_to_where_save_file=f"{pathlib.Path.cwd()}/{file}", ) k8s.success(context, f"Downloaded dump ({file}) from pod. Clean up") - context.run(f"{_generate_exec_command(context)} -- rm tmp/{file}") + context.run(f"{_generate_exec_command(context)} -- rm {dump_path}") return file @@ -96,7 +97,7 @@ def _generate_dump_command( host=host, port=port, username=username, - file=f"tmp/{_get_db_k8s_dump_filename(context, file)}", + file=f"{config.dump_dir}/{_get_db_k8s_dump_filename(context, file)}", additional_params=additional_params or config.dump_additional_params, )