canonical / traefik-k8s-operator

https://charmhub.io/traefik-k8s
Apache License 2.0
11 stars 27 forks source link

`IngressPerUnitRequirer.url` should return a None on relation broken #230

Closed sed-i closed 2 weeks ago

sed-i commented 1 year ago

Bug Description

When I removed the relation between prometheus and traefik, I noticed that web.external-url still has the ingress path. This is because in prometheus we use self.ingress.url (IngressPerUnitRequirer.url), which in turn uses _urls_from_relation_data.

However, on relation broken, relation data can be misleading. https://github.com/canonical/traefik-k8s-operator/blob/f6b150f1da2aa83da74c7eae28b35b4048fb8270/lib/charms/traefik_k8s/v1/ingress_per_unit.py#L726-L728

Luckily, in _handle_relation, the requirer already has up to date information:

def _handle_relation(self, event: RelationEvent):
    # ...
    self._stored.current_urls = current_urls
    # ...
    self.on.revoked.emit(self.relation, unit_name)

All we need to do™ is also look at self._stored.current_urls inside IngressPerUnitRequirer.url.

To Reproduce

  1. Relate prom - trfk.
  2. Remove the relation.

Environment

Juju 3.2.0. Latest charms.

Relevant log output

NTA.

Additional context

No response

sed-i commented 4 months ago

With recent ops, relation data should be hidden on relation broken.

dstathis commented 2 weeks ago

We certainly have a recent enough version of ops by now.