Skip to content

Commit

Permalink
Gracefully handle charm initialization when storage not attached (#108)
Browse files Browse the repository at this point in the history
  • Loading branch information
theoctober19th committed Sep 11, 2024
1 parent 235ad09 commit 0e4a4cd
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from charms.tempo_k8s.v2.tracing import TracingEndpointRequirer
from ops.charm import ActionEvent, CharmBase
from ops.main import main
from ops.model import ActiveStatus, BlockedStatus, MaintenanceStatus
from ops.model import ActiveStatus, BlockedStatus, MaintenanceStatus, ModelError
from ops.pebble import APIError, ChangeError, ExecError

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -90,10 +90,18 @@ def __init__(self, *args):
# Storage isn't available yet. Since storage becomes available early enough, no need
# to observe storage-attached and complicate things; simply abort until it is ready.
return
self._git_sync_mount_point = self.model.storages["content-from-git"][0].location
self._repo_path = os.path.join(self._git_sync_mount_point, self.SUBDIR)

self._tracing = TracingEndpointRequirer(self, protocols=["otlp_http"])

try:
self._git_sync_mount_point = self.model.storages["content-from-git"][0].location
except ModelError:
# Storage isn't available yet. This may happen during the startup sequence.
# ops.model.ModelError: ERROR invalid value "content-from-git/1" for option -s: getting filesystem attachment info: filesystem attachment "1" on "unit cos-configuration/0" not provisioned
return

self._repo_path = os.path.join(self._git_sync_mount_point, self.SUBDIR)

self.container = self.unit.get_container(self._container_name)
self.unit.set_ports(self._git_sync_port)

Expand Down

0 comments on commit 0e4a4cd

Please sign in to comment.