Skip to content

Commit a916055

Browse files
committed
fix: update charm dependent libs
1 parent 01010f1 commit a916055

2 files changed

Lines changed: 27 additions & 8 deletions

File tree

lib/charms/observability_libs/v0/kubernetes_compute_resources_patch.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ def setUp(self, *unused):
149149

150150
# Increment this PATCH version before using `charmcraft publish-lib` or reset
151151
# to 0 if you are raising the major API version
152-
LIBPATCH = 8
152+
LIBPATCH = 9
153153

154154

155155
_Decimal = Union[Decimal, float, str, int] # types that are potentially convertible to Decimal
@@ -584,6 +584,14 @@ def __init__(
584584
will be observed to re-apply the patch.
585585
"""
586586
super().__init__(charm, "{}_{}".format(self.__class__.__name__, container_name))
587+
588+
if container_name == "charm":
589+
raise ValueError(
590+
"Starting with juju 3.6.9, juju manages the charm container "
591+
"constraints and you'll get errors by doing this if the charm is deployed "
592+
"on higher juju versions."
593+
)
594+
587595
self._charm = charm
588596
self._container_name = container_name
589597
self.resource_reqs_func = resource_reqs_func
@@ -606,7 +614,7 @@ def __init__(
606614
def _on_config_changed(self, _):
607615
self._patch()
608616

609-
def _patch(self) -> None:
617+
def _patch(self) -> None: # noqa: C901
610618
"""Patch the Kubernetes resources created by Juju to limit cpu or mem.
611619
612620
This method will keep on retrying to patch the kubernetes resource for a default duration of 20 seconds
@@ -657,7 +665,9 @@ def _patch(self) -> None:
657665
except ApiError as e:
658666
if e.status.code == 403:
659667
msg = f"Kubernetes resources patch failed: `juju trust` this application. {e}"
660-
668+
elif e.status.code == 409:
669+
msg = (f"Kubernetes resources patch failed: someone else (likely juju) "
670+
f"owns the resources you're trying to patch {e}")
661671
else:
662672
msg = f"Kubernetes resources patch failed: {e}"
663673

lib/charms/traefik_k8s/v2/ingress.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ def _on_ingress_revoked(self, event: IngressPerAppRevokedEvent):
8484

8585
# Increment this PATCH version before using `charmcraft publish-lib` or reset
8686
# to 0 if you are raising the major API version
87-
LIBPATCH = 16
87+
LIBPATCH = 17
8888

8989
PYDEPS = ["pydantic"]
9090

@@ -456,11 +456,16 @@ class IngressPerAppDataRemovedEvent(RelationEvent):
456456
"""Event representing that ingress data has been removed for an app."""
457457

458458

459+
class IngressPerAppEndpointsUpdatedEvent(RelationEvent):
460+
"""Event representing that the proxied endpoints have been updated."""
461+
462+
459463
class IngressPerAppProviderEvents(ObjectEvents):
460464
"""Container for IPA Provider events."""
461465

462466
data_provided = EventSource(IngressPerAppDataProvidedEvent)
463467
data_removed = EventSource(IngressPerAppDataRemovedEvent)
468+
endpoints_updated = EventSource(IngressPerAppEndpointsUpdatedEvent)
464469

465470

466471
@dataclass
@@ -508,7 +513,7 @@ def _handle_relation(self, event):
508513
)
509514

510515
def _handle_relation_broken(self, event):
511-
self.on.data_removed.emit(event.relation) # type: ignore
516+
self.on.data_removed.emit(event.relation, event.relation.app) # type: ignore
512517

513518
def wipe_ingress_data(self, relation: Relation):
514519
"""Clear ingress data from relation."""
@@ -523,6 +528,7 @@ def wipe_ingress_data(self, relation: Relation):
523528
)
524529
return
525530
del relation.data[self.app]["ingress"]
531+
self.on.endpoints_updated.emit(relation=relation, app=relation.app)
526532

527533
def _get_requirer_units_data(self, relation: Relation) -> List["IngressRequirerUnitData"]:
528534
"""Fetch and validate the requirer's unit databag."""
@@ -556,7 +562,9 @@ def get_data(self, relation: Relation) -> IngressRequirerData:
556562
self._get_requirer_app_data(relation), self._get_requirer_units_data(relation)
557563
)
558564
except (pydantic.ValidationError, DataValidationError) as e:
559-
raise DataValidationError("failed to validate ingress requirer data") from e
565+
raise DataValidationError(
566+
"failed to validate ingress requirer data: %s" % str(e)
567+
) from e
560568

561569
def is_ready(self, relation: Optional[Relation] = None):
562570
"""The Provider is ready if the requirer has sent valid data."""
@@ -566,7 +574,7 @@ def is_ready(self, relation: Optional[Relation] = None):
566574
try:
567575
self.get_data(relation)
568576
except (DataValidationError, NotReadyError) as e:
569-
log.debug("Provider not ready; validation error encountered: %s" % str(e))
577+
log.info("Provider not ready; validation error encountered: %s" % str(e))
570578
return False
571579
return True
572580

@@ -591,6 +599,7 @@ def publish_url(self, relation: Relation, url: str):
591599
ingress_url = {"url": url}
592600
try:
593601
IngressProviderAppData(ingress=ingress_url).dump(relation.data[self.app]) # type: ignore
602+
self.on.endpoints_updated.emit(relation=relation, app=relation.app)
594603
except pydantic.ValidationError as e:
595604
# If we cannot validate the url as valid, publish an empty databag and log the error.
596605
log.error(f"Failed to validate ingress url '{url}' - got ValidationError {e}")
@@ -756,7 +765,7 @@ def _handle_relation(self, event):
756765

757766
def _handle_relation_broken(self, event):
758767
self._stored.current_url = None # type: ignore
759-
self.on.revoked.emit(event.relation) # type: ignore
768+
self.on.revoked.emit(relation=event.relation, app=event.relation.app) # type: ignore
760769

761770
def _handle_upgrade_or_leader(self, event):
762771
"""On upgrade/leadership change: ensure we publish the data we have."""

0 commit comments

Comments
 (0)