Skip to content

Commit

Permalink
fix: defer pebble ready event if container is not ready
Browse files Browse the repository at this point in the history
Deferring the pebble ready event will ensure that the required operations
that need to happen before starting the service are in place. In this case,
certificate files need to be present in the container, but sometimes the container
is not reachable, causing the action of pushing these files to the container impossible.
In the past we returned if the container was not reachable, but never tried to reach out
to it and push the files, this commit ensures the retry via defer.
Fixes 110
  • Loading branch information
DnPlas committed Oct 3, 2023
1 parent cbc7cc2 commit 1feb12b
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,12 +227,13 @@ def _gen_certs(self):
for k, v in certs.items():
setattr(self._stored, k, v)

def _upload_certs_to_container(self):
def _upload_certs_to_container(self, event):
"""Upload generated certs to container."""
try:
self._check_container_connection(self.container)
except ErrorWithStatus as error:
self.model.unit.status = error.status
event.defer()
return

self.container.push(CONTAINER_CERTS_DEST / "key.pem", self._cert_key, make_dirs=True)
Expand Down Expand Up @@ -303,7 +304,7 @@ def _on_remove(self, _):
def _on_pebble_ready(self, event):
"""Configure started container."""
# upload certs to container
self._upload_certs_to_container()
self._upload_certs_to_container(event)

# proceed with other actions
self._on_event(event)
Expand Down

0 comments on commit 1feb12b

Please sign in to comment.