Skip to content

Commit 5fc2dcd

Browse files
mxsrcboddumanohar
authored andcommitted
Fix handling of existing passwords on branch clones
1 parent 7178519 commit 5fc2dcd

2 files changed

Lines changed: 21 additions & 2 deletions

File tree

src/api/organization/project/branch/__init__.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -687,6 +687,7 @@ async def _deploy_branch_environment_task(
687687
pgbouncer_admin_password: str,
688688
pgbouncer_config: PgbouncerConfigSnapshot,
689689
pitr_enabled: bool,
690+
initial_password: str,
690691
) -> None:
691692
await _persist_branch_status(branch_id, BranchServiceStatus.CREATING)
692693
try:
@@ -702,6 +703,7 @@ async def _deploy_branch_environment_task(
702703
pgbouncer_admin_password=pgbouncer_admin_password,
703704
pgbouncer_config=pgbouncer_snapshot_to_mapping(pgbouncer_config),
704705
pitr_enabled=pitr_enabled,
706+
initial_password=initial_password,
705707
)
706708
except VelaError:
707709
await _persist_branch_status(branch_id, BranchServiceStatus.ERROR)
@@ -731,6 +733,7 @@ async def _clone_branch_environment_task(
731733
copy_data: bool,
732734
pgbouncer_config: PgbouncerConfigSnapshot,
733735
pitr_enabled: bool,
736+
initial_password: str | None,
734737
) -> None:
735738
await _persist_branch_status(branch_id, BranchServiceStatus.CREATING)
736739
storage_class_name: str | None = None
@@ -773,6 +776,7 @@ async def _clone_branch_environment_task(
773776
use_existing_pvc=copy_data,
774777
pgbouncer_config=pgbouncer_snapshot_to_mapping(pgbouncer_config),
775778
pitr_enabled=pitr_enabled,
779+
initial_password=initial_password,
776780
)
777781
except VelaError:
778782
await _persist_branch_status(branch_id, BranchServiceStatus.ERROR)
@@ -805,6 +809,7 @@ async def _restore_branch_environment_task(
805809
restore_database_size: int,
806810
pgbouncer_config: PgbouncerConfigSnapshot,
807811
pitr_enabled: bool,
812+
initial_password: str | None,
808813
) -> None:
809814
await _persist_branch_status(branch_id, BranchServiceStatus.CREATING)
810815
storage_class_name: str | None = None
@@ -851,6 +856,7 @@ async def _restore_branch_environment_task(
851856
use_existing_pvc=True,
852857
pgbouncer_config=pgbouncer_snapshot_to_mapping(pgbouncer_config),
853858
pitr_enabled=pitr_enabled,
859+
initial_password=initial_password,
854860
)
855861
except VelaError:
856862
await _persist_branch_status(branch_id, BranchServiceStatus.ERROR)
@@ -1259,6 +1265,7 @@ def _schedule_branch_environment_tasks(
12591265
pgbouncer_config: PgbouncerConfigSnapshot,
12601266
restore_snapshot: RestoreSnapshotContext | None,
12611267
restore_database_size: int | None,
1268+
initial_password: str | None = None,
12621269
) -> None:
12631270
if deployment_parameters is not None:
12641271
asyncio.create_task(
@@ -1274,6 +1281,7 @@ def _schedule_branch_environment_tasks(
12741281
pgbouncer_admin_password=pgbouncer_admin_password,
12751282
pgbouncer_config=pgbouncer_config,
12761283
pitr_enabled=branch.pitr_enabled,
1284+
initial_password=deployment_parameters.database_password,
12771285
)
12781286
)
12791287
return
@@ -1298,6 +1306,7 @@ def _schedule_branch_environment_tasks(
12981306
restore_database_size=restore_database_size,
12991307
pgbouncer_config=pgbouncer_config,
13001308
pitr_enabled=branch.pitr_enabled,
1309+
initial_password=initial_password,
13011310
)
13021311
)
13031312
return
@@ -1317,6 +1326,7 @@ def _schedule_branch_environment_tasks(
13171326
copy_data=copy_data,
13181327
pgbouncer_config=pgbouncer_config,
13191328
pitr_enabled=branch.pitr_enabled,
1329+
initial_password=initial_password,
13201330
)
13211331
)
13221332

@@ -1363,11 +1373,11 @@ async def create( # noqa: C901
13631373
source_id: Identifier | None = getattr(source, "id", None)
13641374
clone_parameters: DeploymentParameters | None = None
13651375
restore_database_size: int | None = None
1376+
source_overrides: BranchSourceDeploymentParameters | None = None
13661377
restore_params = parameters.restore
13671378
is_restore = restore_params is not None
13681379
is_data_clone = bool(parameters.source and parameters.source.data_copy)
13691380
if source is not None:
1370-
source_overrides: BranchSourceDeploymentParameters | None = None
13711381
if parameters.source is not None:
13721382
source_overrides = parameters.source.deployment_parameters
13731383
elif restore_params is not None:
@@ -1480,6 +1490,10 @@ async def create( # noqa: C901
14801490
)
14811491
restore_snapshot: RestoreSnapshotContext | None = restore_snapshot_context
14821492

1493+
clone_initial_password: str | None = None
1494+
if source_overrides is not None and source_overrides.database_password is not None:
1495+
clone_initial_password = source_overrides.database_password
1496+
14831497
_schedule_branch_environment_tasks(
14841498
deployment_parameters=parameters.deployment,
14851499
organization_id=organization.id,
@@ -1494,6 +1508,7 @@ async def create( # noqa: C901
14941508
pgbouncer_config=pgbouncer_config_snapshot,
14951509
restore_snapshot=restore_snapshot,
14961510
restore_database_size=restore_database_size,
1511+
initial_password=clone_initial_password,
14971512
)
14981513

14991514
payload = (await _public(entity)).model_dump(mode="json") if response == "full" else None

src/deployment/__init__.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -503,6 +503,7 @@ async def create_vela_config(
503503
ensure_namespace: bool = True,
504504
pgbouncer_config: Mapping[str, int] | None = None,
505505
pitr_enabled: bool = False,
506+
initial_password: str | None = None,
506507
):
507508
namespace = deployment_namespace(branch_id)
508509
logging.info(
@@ -568,7 +569,8 @@ async def create_vela_config(
568569
text=True,
569570
)
570571
await _initialize_autoscaler_overlay_endpoints(namespace)
571-
await set_initial_password(branch_id, parameters.database_password, database_admin_password, timeout=240)
572+
if initial_password is not None:
573+
await set_initial_password(branch_id, initial_password, database_admin_password, timeout=240)
572574
except subprocess.CalledProcessError as e:
573575
logger.exception(f"Failed to create deployment: {e.stderr}")
574576
release_name = _release_name()
@@ -1259,6 +1261,7 @@ async def deploy_branch_environment(
12591261
pgbouncer_config: Mapping[str, int],
12601262
use_existing_pvc: bool = False,
12611263
pitr_enabled: bool = False,
1264+
initial_password: str | None = None,
12621265
) -> None:
12631266
"""Background task: provision infra for a branch and persist the resulting endpoint."""
12641267
await kube_service.ensure_namespace(deployment_namespace(branch_id), labels=_POD_SECURITY_LABELS)
@@ -1276,6 +1279,7 @@ async def deploy_branch_environment(
12761279
ensure_namespace=False,
12771280
pgbouncer_config=pgbouncer_config,
12781281
pitr_enabled=pitr_enabled,
1282+
initial_password=initial_password,
12791283
),
12801284
provision_branch_endpoints(
12811285
spec=BranchEndpointProvisionSpec(

0 commit comments

Comments
 (0)