Skip to content

Commit ba16f22

Browse files
committed
remove redunant storageclass name parameter
1 parent 5c1349e commit ba16f22

File tree

2 files changed

+24
-20
lines changed

2 files changed

+24
-20
lines changed

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

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
from ....._util.crypto import encrypt_with_passphrase, generate_keys
2626
from .....database import AsyncSessionLocal, SessionDep
2727
from .....deployment import (
28-
SIMPLYBLOCK_CSI_STORAGE_CLASS,
2928
DeploymentParameters,
3029
ResizeParameters,
3130
branch_api_domain,
@@ -760,7 +759,6 @@ async def _clone_branch_environment_task(
760759
source_branch_id=source_branch_id,
761760
target_branch_id=branch_id,
762761
snapshot_class=_VOLUME_SNAPSHOT_CLASS,
763-
storage_class_name=SIMPLYBLOCK_CSI_STORAGE_CLASS,
764762
snapshot_timeout_seconds=_SNAPSHOT_TIMEOUT_SECONDS,
765763
snapshot_poll_interval_seconds=_SNAPSHOT_POLL_INTERVAL_SECONDS,
766764
pvc_timeout_seconds=_PVC_CLONE_TIMEOUT_SECONDS,
@@ -839,7 +837,6 @@ async def _restore_branch_environment_task(
839837
snapshot_name=snapshot_name,
840838
snapshot_content_name=snapshot_content_name,
841839
snapshot_class=_VOLUME_SNAPSHOT_CLASS,
842-
storage_class_name=SIMPLYBLOCK_CSI_STORAGE_CLASS,
843840
snapshot_timeout_seconds=_SNAPSHOT_TIMEOUT_SECONDS,
844841
snapshot_poll_interval_seconds=_SNAPSHOT_POLL_INTERVAL_SECONDS,
845842
pvc_timeout_seconds=_PVC_TIMEOUT_SECONDS,
@@ -853,7 +850,6 @@ async def _restore_branch_environment_task(
853850
snapshot_namespace=snapshot_namespace,
854851
snapshot_name=wal_snapshot_name,
855852
snapshot_class=_VOLUME_SNAPSHOT_CLASS,
856-
storage_class_name=SIMPLYBLOCK_CSI_STORAGE_CLASS,
857853
snapshot_timeout_seconds=_SNAPSHOT_TIMEOUT_SECONDS,
858854
snapshot_poll_interval_seconds=_SNAPSHOT_POLL_INTERVAL_SECONDS,
859855
pvc_timeout_seconds=_PVC_TIMEOUT_SECONDS,
@@ -933,7 +929,6 @@ async def _restore_branch_environment_in_place_task(
933929
snapshot_name=snapshot_name,
934930
snapshot_content_name=snapshot_content_name,
935931
snapshot_class=_VOLUME_SNAPSHOT_CLASS,
936-
storage_class_name=SIMPLYBLOCK_CSI_STORAGE_CLASS,
937932
snapshot_timeout_seconds=_SNAPSHOT_TIMEOUT_SECONDS,
938933
snapshot_poll_interval_seconds=_SNAPSHOT_POLL_INTERVAL_SECONDS,
939934
pvc_timeout_seconds=_PVC_TIMEOUT_SECONDS,

src/deployment/kubernetes/volume_clone.py

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
AUTOSCALER_PVC_SUFFIX,
1515
AUTOSCALER_WAL_PVC_SUFFIX,
1616
PITR_WAL_PVC_SIZE,
17+
SIMPLYBLOCK_CSI_STORAGE_CLASS,
1718
get_autoscaler_vm_identity,
1819
kube_service,
1920
)
@@ -42,6 +43,13 @@
4243
_PITR_WAL_PVC_SIZE_BYTES: int = int(parse_quantity(PITR_WAL_PVC_SIZE))
4344

4445

46+
def _resolve_snapshot_restore_size_bytes(snapshot: dict[str, Any]) -> int | None:
47+
restore_size = (snapshot.get("status") or {}).get("restoreSize")
48+
if restore_size is None:
49+
return None
50+
return int(parse_quantity(str(restore_size)))
51+
52+
4553
@dataclass(frozen=True)
4654
class CloneTimeouts:
4755
snapshot_ready: float
@@ -114,7 +122,6 @@ class _VolumeCloneOperation:
114122
source_branch_id: Identifier
115123
target_branch_id: Identifier
116124
snapshot_class: str
117-
storage_class_name: str
118125
target_database_size: int
119126
timeouts: CloneTimeouts
120127
volume_label: str = "data"
@@ -123,6 +130,7 @@ class _VolumeCloneOperation:
123130
created_source_snapshot: bool = field(default=False, init=False)
124131
created_target_snapshot: bool = field(default=False, init=False)
125132
created_content: bool = field(default=False, init=False)
133+
snapshot_restore_size_bytes: int | None = field(default=None, init=False)
126134

127135
def __post_init__(self) -> None:
128136
source_ns, source_vm_name = get_autoscaler_vm_identity(self.source_branch_id)
@@ -227,6 +235,7 @@ async def _capture_source_snapshot(self) -> SnapshotMaterial:
227235
timeout=self.timeouts.snapshot_ready,
228236
poll_interval=self.timeouts.snapshot_poll,
229237
)
238+
self.snapshot_restore_size_bytes = _resolve_snapshot_restore_size_bytes(snapshot)
230239

231240
material, _ = await _extract_snapshot_material(
232241
namespace=self.ids.source_namespace,
@@ -274,10 +283,13 @@ async def _create_target_pvc(self) -> None:
274283
source_pvc,
275284
volume_snapshot_name=snapshot_name,
276285
)
277-
new_manifest.spec.resources.requests["storage"] = str(self.target_database_size)
278-
new_manifest.spec.storage_class_name = self.storage_class_name
286+
requested_size = self.target_database_size
287+
if self.snapshot_restore_size_bytes is not None:
288+
requested_size = max(requested_size, self.snapshot_restore_size_bytes)
289+
new_manifest.spec.resources.requests["storage"] = str(requested_size)
290+
new_manifest.spec.storage_class_name = SIMPLYBLOCK_CSI_STORAGE_CLASS
279291
if hasattr(new_manifest.spec, "storageClassName"):
280-
new_manifest.spec.storageClassName = self.storage_class_name
292+
new_manifest.spec.storageClassName = SIMPLYBLOCK_CSI_STORAGE_CLASS
281293
annotations = dict(getattr(new_manifest.metadata, "annotations", {}) or {})
282294
annotations["meta.helm.sh/release-name"] = get_settings().deployment_release_name
283295
annotations["meta.helm.sh/release-namespace"] = namespace
@@ -320,13 +332,13 @@ class _SnapshotRestoreOperation:
320332
snapshot_name: str
321333
snapshot_content_name: str | None
322334
snapshot_class: str
323-
storage_class_name: str
324335
target_database_size: int
325336
timeouts: CloneTimeouts
326337
pvc_suffix: str = AUTOSCALER_PVC_SUFFIX
327338
ids: CloneIdentifiers = field(init=False)
328339
created_target_snapshot: bool = field(default=False, init=False)
329340
created_content: bool = field(default=False, init=False)
341+
snapshot_restore_size_bytes: int | None = field(default=None, init=False)
330342

331343
def __post_init__(self) -> None:
332344
source_ns = self.snapshot_namespace
@@ -403,6 +415,7 @@ async def _load_snapshot_material(self) -> SnapshotMaterial:
403415
timeout=self.timeouts.snapshot_ready,
404416
poll_interval=self.timeouts.snapshot_poll,
405417
)
418+
self.snapshot_restore_size_bytes = _resolve_snapshot_restore_size_bytes(snapshot)
406419
material, _ = await _extract_snapshot_material(
407420
namespace=self.snapshot_namespace,
408421
snapshot=snapshot,
@@ -443,10 +456,13 @@ async def _create_target_pvc(self) -> None:
443456
source_pvc,
444457
volume_snapshot_name=self.ids.target_snapshot,
445458
)
446-
new_manifest.spec.resources.requests["storage"] = str(self.target_database_size)
447-
new_manifest.spec.storage_class_name = self.storage_class_name
459+
requested_size = self.target_database_size
460+
if self.snapshot_restore_size_bytes is not None:
461+
requested_size = max(requested_size, self.snapshot_restore_size_bytes)
462+
new_manifest.spec.resources.requests["storage"] = str(requested_size)
463+
new_manifest.spec.storage_class_name = SIMPLYBLOCK_CSI_STORAGE_CLASS
448464
if hasattr(new_manifest.spec, "storageClassName"):
449-
new_manifest.spec.storageClassName = self.storage_class_name
465+
new_manifest.spec.storageClassName = SIMPLYBLOCK_CSI_STORAGE_CLASS
450466
annotations = dict(getattr(new_manifest.metadata, "annotations", {}) or {})
451467
annotations["meta.helm.sh/release-name"] = get_settings().deployment_release_name
452468
annotations["meta.helm.sh/release-namespace"] = self.ids.target_namespace
@@ -487,7 +503,6 @@ async def clone_branch_database_volume(
487503
source_branch_id: Identifier,
488504
target_branch_id: Identifier,
489505
snapshot_class: str,
490-
storage_class_name: str,
491506
snapshot_timeout_seconds: float,
492507
snapshot_poll_interval_seconds: float,
493508
pvc_timeout_seconds: float,
@@ -510,7 +525,6 @@ async def clone_branch_database_volume(
510525
source_branch_id=source_branch_id,
511526
target_branch_id=target_branch_id,
512527
snapshot_class=snapshot_class,
513-
storage_class_name=storage_class_name,
514528
target_database_size=database_size,
515529
timeouts=timeouts,
516530
volume_label="pgdata",
@@ -523,7 +537,6 @@ async def clone_branch_database_volume(
523537
source_branch_id=source_branch_id,
524538
target_branch_id=target_branch_id,
525539
snapshot_class=snapshot_class,
526-
storage_class_name=storage_class_name,
527540
target_database_size=_PITR_WAL_PVC_SIZE_BYTES,
528541
timeouts=timeouts,
529542
volume_label="wal",
@@ -540,7 +553,6 @@ async def restore_branch_database_volume_from_snapshot(
540553
snapshot_name: str,
541554
snapshot_content_name: str | None,
542555
snapshot_class: str,
543-
storage_class_name: str,
544556
database_size: int,
545557
snapshot_timeout_seconds: float,
546558
snapshot_poll_interval_seconds: float,
@@ -557,7 +569,6 @@ async def restore_branch_database_volume_from_snapshot(
557569
snapshot_name=snapshot_name,
558570
snapshot_content_name=snapshot_content_name,
559571
snapshot_class=snapshot_class,
560-
storage_class_name=storage_class_name,
561572
target_database_size=database_size,
562573
timeouts=CloneTimeouts(
563574
snapshot_ready=snapshot_timeout_seconds,
@@ -576,7 +587,6 @@ async def restore_branch_wal_volume_from_snapshot(
576587
snapshot_namespace: str,
577588
snapshot_name: str,
578589
snapshot_class: str,
579-
storage_class_name: str,
580590
snapshot_timeout_seconds: float,
581591
snapshot_poll_interval_seconds: float,
582592
pvc_timeout_seconds: float,
@@ -593,7 +603,6 @@ async def restore_branch_wal_volume_from_snapshot(
593603
snapshot_name=snapshot_name,
594604
snapshot_content_name=None,
595605
snapshot_class=snapshot_class,
596-
storage_class_name=storage_class_name,
597606
target_database_size=_PITR_WAL_PVC_SIZE_BYTES,
598607
pvc_suffix=AUTOSCALER_WAL_PVC_SUFFIX,
599608
timeouts=CloneTimeouts(

0 commit comments

Comments
 (0)