Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions refresh_versions.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
charm = "16/0.0.0"
workload = "16.0"
32 changes: 31 additions & 1 deletion single_kernel_postgresql/charms/abstract_charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,9 @@ def __init__(self, *args):
self.patroni_manager,
)

# Resume or prepare the refresh (the charms' post-construction resume block).
self.refresh_manager.on_init()

# Status Handler
self.status_handler = StatusHandler(
self,
Expand Down Expand Up @@ -177,10 +180,37 @@ def set_app_status(self) -> None:
pass

@abstractmethod
def update_config(self) -> bool:
def update_config(self, *, refresh: "charm_refresh.Machines | None" = None) -> bool:
"""Re-render the Patroni configuration and apply it."""
pass

@abstractmethod
def post_refresh_side_effects(self) -> None:
"""Run the post-snap-refresh side effects owned by not-yet-migrated modules.

The VM charm sets up the exporter and pgBackRest exporter, starts/stops the
pgBackRest service and updates the watcher unit address here.
"""
pass

@abstractmethod
def has_async_replication_relation(self) -> bool:
"""Whether this unit is related to an async replication partner.

Owned by the async-replication module until that phase migrates; the temp
tablespace migration skips units inside an async cluster.
"""
pass

@abstractmethod
def update_relation_endpoints(self) -> None:
"""Refresh the client and async relation endpoints after a switchover.

Owned by the client-relation and async-replication modules until those
phases migrate; the VM pre-refresh checks call it after switching primary.
"""
pass

@property
@abstractmethod
def primary_endpoint(self) -> str | None:
Expand Down
16 changes: 14 additions & 2 deletions single_kernel_postgresql/charms/k8s_charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def set_unit_status(
status: StatusBase,
/,
*,
refresh: "charm_refresh.Kubernetes | None" = None,
refresh: "charm_refresh.Machines | charm_refresh.Kubernetes | None" = None,
) -> None:
"""Set the unit status without overriding a higher-priority refresh status."""
self.refresh_manager.set_unit_status(status, refresh=refresh)
Expand All @@ -101,7 +101,16 @@ def set_default_unit_status(self) -> None:
def set_app_status(self) -> None:
"""Set the application status from the async-replication state."""

def update_config(self, *, refresh: "charm_refresh.Kubernetes | None" = None) -> bool:
def post_refresh_side_effects(self) -> None:
"""Run the post-snap-refresh side effects owned by not-yet-migrated modules."""

def has_async_replication_relation(self) -> bool:
"""Whether this unit is related to an async replication partner."""
return False

def update_config(
self, *, refresh: "charm_refresh.Machines | charm_refresh.Kubernetes | None" = None
) -> bool:
"""Re-render the Patroni configuration and apply it."""
return self.config_manager.update_config(self.postgresql)

Expand All @@ -113,3 +122,6 @@ def primary_endpoint(self) -> str | None:
def get_async_primary_cluster_endpoint(self) -> str | None:
"""Endpoint of the primary cluster of the async replication partner, if any."""
return None

def update_relation_endpoints(self) -> None:
"""Refresh the client and async relation endpoints after a switchover."""
16 changes: 14 additions & 2 deletions single_kernel_postgresql/charms/vm_charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def set_unit_status(
status: StatusBase,
/,
*,
refresh: "charm_refresh.Machines | None" = None,
refresh: "charm_refresh.Machines | charm_refresh.Kubernetes | None" = None,
) -> None:
"""Set the unit status without overriding a higher-priority refresh status."""
self.refresh_manager.set_unit_status(status, refresh=refresh)
Expand All @@ -92,7 +92,16 @@ def set_default_unit_status(self) -> None:
def set_app_status(self) -> None:
"""Set the application status from the async-replication state."""

def update_config(self, *, refresh: "charm_refresh.Machines | None" = None) -> bool:
def post_refresh_side_effects(self) -> None:
"""Set up the exporters, pgBackRest service, and watcher unit address."""

def has_async_replication_relation(self) -> bool:
"""Whether this unit is related to an async replication partner."""
return False

def update_config(
self, *, refresh: "charm_refresh.Machines | charm_refresh.Kubernetes | None" = None
) -> bool:
"""Re-render the Patroni configuration and apply it."""
if refresh is None:
refresh = self.refresh_manager.refresh
Expand All @@ -107,3 +116,6 @@ def primary_endpoint(self) -> str | None:
def get_async_primary_cluster_endpoint(self) -> str | None:
"""Endpoint of the primary cluster of the async replication partner, if any."""
return None

def update_relation_endpoints(self) -> None:
"""Refresh the client and async relation endpoints after a switchover."""
4 changes: 2 additions & 2 deletions single_kernel_postgresql/managers/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@ def update_config(
watcher_raft_address: str | None = None,
no_peers: bool = False,
*,
refresh: charm_refresh.Machines | None = None,
refresh: charm_refresh.Machines | charm_refresh.Kubernetes | None = None,
) -> bool:
"""Updates Patroni config file based on the existence of the TLS files.

Expand Down Expand Up @@ -578,7 +578,7 @@ def update_config(
self.state.substrate == Substrates.VM
and refresh is not None
and cast("VMWorkload", self.workload).get_snap_revision()
!= refresh.pinned_snap_revision
!= cast("charm_refresh.Machines", refresh).pinned_snap_revision
):
logger.debug("Early exit: snap was not refreshed to the right version yet")
return True
Expand Down
Loading