Skip to content

Commit

Permalink
Fix charm going to infinite "Waiting for container" (#35)
Browse files Browse the repository at this point in the history
* Add defer event when container is not ready
  • Loading branch information
misohu authored Sep 12, 2023
1 parent 3848112 commit b956d3c
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 7 deletions.
2 changes: 1 addition & 1 deletion metadata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ resources:
oci-image:
type: oci-image
description: Backing OCI image
upstream-source: charmedkubeflow/resource-dispatcher:1.0_beta-22.04
upstream-source: charmedkubeflow/resource-dispatcher:1.0-22.04
requires:
secrets:
interface: secrets
Expand Down
2 changes: 1 addition & 1 deletion requirements-fmt.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# This file is autogenerated by pip-compile with Python 3.8
# by the following command:
#
# pip-compile --resolver=backtracking requirements-fmt.in
# pip-compile requirements-fmt.in
#
black==23.3.0
# via -r requirements-fmt.in
Expand Down
2 changes: 1 addition & 1 deletion requirements-lint.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# This file is autogenerated by pip-compile with Python 3.8
# by the following command:
#
# pip-compile --resolver=backtracking requirements-lint.in
# pip-compile requirements-lint.in
#
black==23.3.0
# via -r requirements-fmt.txt
Expand Down
3 changes: 2 additions & 1 deletion requirements.in
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
charmed-kubeflow-chisme>=0.0.10
charmed-kubeflow-chisme
lightkube-models
ops
oci-image
serialized-data-interface
pyyaml
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ pyrsistent==0.19.3
# via jsonschema
pyyaml==6.0.1
# via
# -r requirements.in
# lightkube
# ops
# serialized-data-interface
Expand Down
8 changes: 5 additions & 3 deletions src/charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from lightkube.generic_resource import load_in_cluster_generic_resources
from lightkube.models.core_v1 import ServicePort
from ops.charm import CharmBase, RelationBrokenEvent
from ops.framework import EventBase
from ops.main import main
from ops.model import ActiveStatus, BlockedStatus, MaintenanceStatus, WaitingStatus
from ops.pebble import APIError, ChangeError, Layer
Expand Down Expand Up @@ -117,9 +118,10 @@ def _check_leader(self):
self.logger.info("Not a leader, skipping setup")
raise ErrorWithStatus("Waiting for leadership", WaitingStatus)

def _check_container(self):
def _check_container(self, event: EventBase):
"""Check if we can connect the container."""
if not self.container.can_connect():
event.defer()
raise ErrorWithStatus("Container is not ready", WaitingStatus)

def _deploy_k8s_resources(self) -> None:
Expand Down Expand Up @@ -249,11 +251,11 @@ def _update_manifests(self, interfaces, dispatch_folder, relation, event):
self.logger.debug(f"received {relation} are {manifests}")
self._sync_manifests(manifests, dispatch_folder)

def _on_event(self, event) -> None:
def _on_event(self, event: EventBase) -> None:
"""Perform all required actions for the Charm."""
try:
self._check_leader()
self._check_container()
self._check_container(event)
interfaces = self._get_interfaces()
self._update_layer()
self._update_manifests(
Expand Down

0 comments on commit b956d3c

Please sign in to comment.