Skip to content

Commit

Permalink
Merge pull request #108 from saritasa-nest/feature/k8s-db-dump-specif…
Browse files Browse the repository at this point in the history
…y-folder

Add ability to set `dump_dir` for `K8SDBSettings`
  • Loading branch information
TheSuperiorStanislav authored Oct 14, 2024
2 parents e431b07 + c49ea06 commit 5f6c599
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions saritasa_invocations/_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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} "
Expand Down
7 changes: 4 additions & 3 deletions saritasa_invocations/db_k8s.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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,
)

Expand Down

0 comments on commit 5f6c599

Please sign in to comment.