Skip to content

Commit

Permalink
Also add fix to on start hook
Browse files Browse the repository at this point in the history
  • Loading branch information
marceloneppel committed Aug 18, 2023
1 parent b2bd3a7 commit cb92791
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ def __init__(self, *args):

self.framework.observe(self.on.config_changed, self._on_config_changed)
self.framework.observe(self.on.pgbouncer_pebble_ready, self._on_pgbouncer_pebble_ready)
self.framework.observe(self.on.start, self._on_start)
self.framework.observe(self.on.update_status, self._on_update_status)
self.framework.observe(self.on.upgrade_charm, self._on_upgrade_charm)

Expand Down Expand Up @@ -281,6 +282,15 @@ def _pgbouncer_layer(self) -> Layer:
}
)

def _on_start(self, _) -> None:
"""Re-render the auth file, which is lost if the host machine is restarted."""
self.render_auth_file_if_available()

def render_auth_file_if_available(self):
"""Render the auth file if it's available in the secret store."""
if auth_file := self.get_secret("app", AUTH_FILE_DATABAG_KEY):
self.render_auth_file(auth_file)

def _on_update_status(self, _) -> None:
"""Update Status hook.
Expand Down Expand Up @@ -319,8 +329,7 @@ def update_status(self):

def _on_upgrade_charm(self, _) -> None:
"""Re-render the auth file, which is lost in a pod reschedule."""
if auth_file := self.get_secret("app", AUTH_FILE_DATABAG_KEY):
self.render_auth_file(auth_file)
self.render_auth_file_if_available()

def reload_pgbouncer(self) -> None:
"""Reloads pgbouncer application.
Expand Down

0 comments on commit cb92791

Please sign in to comment.