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"
52 changes: 50 additions & 2 deletions single_kernel_postgresql/charms/abstract_charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"""Skeleton for the abstract charm."""

from abc import ABC, abstractmethod
from typing import TYPE_CHECKING
from typing import TYPE_CHECKING, cast

from data_platform_helpers.advanced_statuses import StatusHandler
from ops import StatusBase
Expand Down Expand Up @@ -31,19 +31,28 @@
from single_kernel_postgresql.managers.async_replication import (
AsyncReplicationManager,
)
from single_kernel_postgresql.managers.backup import BackupManager
from single_kernel_postgresql.managers.cluster import ClusterManager
from single_kernel_postgresql.managers.cluster_membership import ClusterMembershipManager
from single_kernel_postgresql.managers.config import ConfigManager
from single_kernel_postgresql.managers.database import DatabaseManager
from single_kernel_postgresql.managers.logical_replication import LogicalReplicationManager
from single_kernel_postgresql.managers.observer import ObserverManager
from single_kernel_postgresql.managers.patroni import PatroniManager
from single_kernel_postgresql.managers.raft import RaftManager
from single_kernel_postgresql.managers.refresh import RefreshManager
from single_kernel_postgresql.managers.restore import RestoreManager
from single_kernel_postgresql.managers.tls import TLSManager
from single_kernel_postgresql.utils.s3 import S3Client
from single_kernel_postgresql.workload.base import BaseWorkload, ResourceProvider

from ..config.enums import Substrates
from ..config.literals import DATABASE, S3_RELATION_NAME
from ..config.literals import (
DATABASE,
REPLICATION_CONSUMER_RELATION,
REPLICATION_OFFER_RELATION,
S3_RELATION_NAME,
)
from ..utils.postgresql import PostgreSQL


Expand Down Expand Up @@ -203,6 +212,30 @@ def __init__(self, *args):
set_primary_status_message=self.set_primary_status_message,
)

# The backup subsystem (port of the VM charm's composition wiring): the
# charm-side duplicates are retired when the thin charm lands.
self.s3_client = S3Client(self.workload)
self.backup_manager = BackupManager(
state=self.state,
workload=self.workload,
s3_client=self.s3_client,
patroni_manager=self.patroni_manager,
update_config=self.update_config,
resource_provider=cast("ResourceProvider", self.workload),
is_standby_cluster=self._is_standby_cluster,
set_unit_status=self.set_unit_status,
refresh_primary_status=self.set_primary_status_message,
)
self.restore_manager = RestoreManager(
state=self.state,
workload=self.workload,
patroni_manager=self.patroni_manager,
update_config=self.update_config,
backup_manager=self.backup_manager,
is_standby_cluster=self._is_standby_cluster,
)
self.observer_manager = ObserverManager(self.state, self.workload)

# Events Handler
self.postgresql_events_handler = PostgreSQLEventsHandler(
self,
Expand All @@ -214,6 +247,12 @@ def __init__(self, *args):
self.patroni_manager,
self.refresh_manager,
membership_manager=self.membership_manager,
backup_manager=self.backup_manager,
restore_manager=self.restore_manager,
observer_manager=self.observer_manager,
async_replication_manager=self.async_replication_manager,
database_manager=self.database_manager,
postgresql=lambda: self.postgresql,
)

# Resume or prepare the refresh (the charms' post-construction resume block).
Expand All @@ -230,6 +269,15 @@ def __init__(self, *args):
self.logical_replication_manager,
)

def _is_standby_cluster(self) -> bool:
"""Whether this unit belongs to a standby (read-only) cluster (port)."""
if (
self.state.model.get_relation(REPLICATION_CONSUMER_RELATION) is None
and self.state.model.get_relation(REPLICATION_OFFER_RELATION) is None
):
return False
return not self.async_replication_manager.is_primary_cluster()

# Postgresql Client
@property
@abstractmethod
Expand Down
4 changes: 4 additions & 0 deletions single_kernel_postgresql/config/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ class UpdateSyncNodeCountError(PostgreSQLBaseError):
"""Raised when updating synchronous_node_count failed for some reason."""


class CannotConnectError(Exception):
"""Cannot run the connectivity check against the database."""


class DeployedWithoutTrustError(PostgreSQLBaseError):
"""Raised when the K8s API denies access because the app wasn't deployed with --trust."""

Expand Down
Loading
Loading