generated from canonical/template-operator
-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[DPE-4066] HA interface #317
Merged
Merged
Changes from 21 commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
8eb8edf
Initial hacluster implementation
dragomirp 134a321
Merge branch 'main' into dpe-4066-ha-interface
dragomirp aefb45f
Fix clustered check
dragomirp 72ef2da
Check for relation in set_vip
dragomirp d847fd8
Hacluster test
dragomirp 799f983
Fix test
dragomirp 521f8c8
Add remove test
dragomirp fcabb83
Merge branch 'main' into dpe-4066-ha-interface
dragomirp e9bfbda
Merge branch 'main' into dpe-4066-ha-interface
dragomirp 9e71a30
Update libs
dragomirp 9ba5893
Update client info on config change
dragomirp b4dcd2f
Cache vip in peer data
dragomirp 6c8542f
Block on edge cases
dragomirp a670cbb
Bump coverage
dragomirp fa85efa
Blocking check
dragomirp 13f0033
Fix integration test
dragomirp 2a3d907
App status with VIP
dragomirp 22ff7e3
Move vip to leader status
dragomirp fa284b1
Merge branch 'main' into dpe-4066-ha-interface
dragomirp 6243066
Clear up vip caching
dragomirp 674d07e
Forgotten None
dragomirp ec9ef66
Bump libs
dragomirp fe09777
Merge branch 'main' into dpe-4066-ha-interface
dragomirp File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -71,3 +71,8 @@ requires: | |
interface: tracing | ||
limit: 1 | ||
optional: true | ||
|
||
ha: | ||
interface: hacluster | ||
limit: 1 | ||
optional: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,17 +24,18 @@ | |
from charms.tempo_k8s.v1.charm_tracing import trace_charm | ||
from charms.tempo_k8s.v2.tracing import TracingEndpointRequirer | ||
from jinja2 import Template | ||
from ops import JujuVersion | ||
from ops.charm import CharmBase, StartEvent | ||
from ops.main import main | ||
from ops.model import ( | ||
from ops import ( | ||
ActiveStatus, | ||
BlockedStatus, | ||
CharmBase, | ||
JujuVersion, | ||
MaintenanceStatus, | ||
ModelError, | ||
Relation, | ||
StartEvent, | ||
WaitingStatus, | ||
) | ||
from ops.main import main | ||
|
||
from constants import ( | ||
APP_SCOPE, | ||
|
@@ -65,6 +66,7 @@ | |
) | ||
from relations.backend_database import BackendDatabaseRequires | ||
from relations.db import DbProvides | ||
from relations.hacluster import HaCluster | ||
from relations.peers import Peers | ||
from relations.pgbouncer_provider import PgBouncerProvider | ||
from upgrade import PgbouncerUpgrade, get_pgbouncer_dependencies_model | ||
|
@@ -120,6 +122,7 @@ def __init__(self, *args): | |
self.legacy_db_relation = DbProvides(self, admin=False) | ||
self.legacy_db_admin_relation = DbProvides(self, admin=True) | ||
self.tls = PostgreSQLTLS(self, PEER_RELATION_NAME) | ||
self.hacluster = HaCluster(self) | ||
|
||
self.service_ids = list(range(self.instances_count)) | ||
self.pgb_services = [ | ||
|
@@ -507,8 +510,24 @@ def update_status(self): | |
self.unit.status = BlockedStatus("backend database relation not ready") | ||
return | ||
|
||
if self.hacluster.relation and not self._is_exposed: | ||
self.unit.status = BlockedStatus("ha integration used without data-intgrator") | ||
return | ||
|
||
vip = self.config.get("vip") | ||
if self.hacluster.relation and not vip: | ||
self.unit.status = BlockedStatus("ha integration used without vip configuration") | ||
return | ||
|
||
if vip and not self._is_exposed: | ||
self.unit.status = BlockedStatus("vip configuration without data-intgrator") | ||
return | ||
|
||
if self.check_pgb_running(): | ||
self.unit.status = ActiveStatus() | ||
if self.unit.is_leader() and vip: | ||
self.unit.status = ActiveStatus(f"VIP: {vip}") | ||
else: | ||
self.unit.status = ActiveStatus() | ||
|
||
def _on_config_changed(self, event) -> None: | ||
"""Config changed handler. | ||
|
@@ -521,19 +540,28 @@ def _on_config_changed(self, event) -> None: | |
event.defer() | ||
return | ||
|
||
old_vip = self.peers.app_databag.get("current_vip", "") | ||
vip = self.config.get("vip", "") | ||
vip_changed = old_vip != vip | ||
if vip_changed and self._is_exposed: | ||
self.hacluster.set_vip(self.config.get("vip")) | ||
|
||
old_port = self.peers.app_databag.get("current_port") | ||
port_changed = old_port != str(self.config["listen_port"]) | ||
if port_changed and self._is_exposed: | ||
if self.unit.is_leader(): | ||
self.peers.app_databag["current_port"] = str(self.config["listen_port"]) | ||
# Open port | ||
try: | ||
if old_port: | ||
self.unit.close_port("tcp", old_port) | ||
self.unit.open_port("tcp", self.config["listen_port"]) | ||
self.unit.set_ports(self.config["listen_port"]) | ||
except ModelError: | ||
logger.exception("failed to open port") | ||
|
||
if self.unit.is_leader(): | ||
self.peers.app_databag["current_port"] = str(self.config["listen_port"]) | ||
if vip: | ||
self.peers.app_databag["current_vip"] = str(vip) | ||
else: | ||
self.peers.app_databag.pop("current_vip", None) | ||
|
||
# TODO hitting upgrade errors here due to secrets labels failing to set on non-leaders. | ||
# deferring until the leader manages to set the label | ||
try: | ||
|
@@ -546,6 +574,9 @@ def _on_config_changed(self, event) -> None: | |
if self.backend.postgres: | ||
self.render_prometheus_service() | ||
|
||
if port_changed or vip_changed: | ||
self.update_client_connection_info() | ||
|
||
def check_pgb_running(self): | ||
"""Checks that pgbouncer service is running, and updates status accordingly.""" | ||
prom_service = f"{PGB}-{self.app.name}-prometheus" | ||
|
@@ -910,14 +941,13 @@ def unit_ip(self) -> str: | |
# Relation Utilities | ||
# ===================== | ||
|
||
def update_client_connection_info(self, port: Optional[str] = None): | ||
def update_client_connection_info(self): | ||
Comment on lines
-913
to
+944
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not really passed anywhere |
||
"""Update ports in backend relations to match updated pgbouncer port.""" | ||
# Skip updates if backend.postgres doesn't exist yet. | ||
if not self.backend.postgres or not self.unit.is_leader(): | ||
return | ||
|
||
if port is None: | ||
port = self.config["listen_port"] | ||
port = self.config["listen_port"] | ||
|
||
for relation in self.model.relations.get("db", []): | ||
self.legacy_db_relation.update_connection_info(relation, port) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Setting just the app status message here didn't show when testing locally, while setting a proper app status didn't clear up when blocking.