operator: Add Relation.broken to allow querying if a relation is broken (breaking)
It’s sometimes good to be able to query for relations and then determine if the relation you’re looking at is broken (due to the current event being a relation-broken event for the relation in question, or while handling deferred events before that event). So it would be good to add a Relation.broken boolean attribute (or perhaps its inverse, Relation.active?) that ops sets based on the relation data and incoming event.
This is to solve the issue I’ve been discussing with @carlcsaposs-canonical with the mysql-router-k8s charm using a “stateless status setting” approach, but having to pass the current event down to all their get-status functions. It’d be conceptually simpler (and perhaps better in the case of deferred events?) to just be able to query relation.broken.
So this should probably be done as part of or shortly after the multi-status work (spec OP033).
About this issue
- Original URL
- State: closed
- Created a year ago
- Comments: 21 (15 by maintainers)
That’s a reasonable idea, @sed-i, thanks. I intend to discuss this with John M a couple of others next week, to see if we can finalize which approach we take.
I discussed this with @jameinel today, and we lean towards excluding the broken relation from
model.relations["foo"]duringrelation-broken(but not from priorrelation-departedevents). This makes more sense, and is what charmers expect.In terms of backwards-compatibility and whether this would be a safe change to make, I’ve done a cursory look through a bunch of charms I have downloaded, and where they iterate over
model.relationsit looks like it’s in contexts where the broken relation shouldn’t be included anyway. So I think it probably would be safe to do this.One tricky thing is what
model.get_relation()would return, and what the.relationattribute of theRelationBrokenEventshould be in therelation-brokenhook. If we just made the change tomodel.relationsto exclude the broken relation,get_relation()would also return None and theRelationBrokenEvent.relationwould be None. (This would happen as it’s no longer inmodel.relations["foo"], andget_relationuses that viaRelationMapping._get_unique.) I’m not sure that’s a good idea.Ideally we’d make the change to Juju’s
relation-listhook tool. However, ops would still have to exclude it manually for older versions of Juju.As next steps, @wallyworld said he’d bring this up at the next charm guild meeting next week to try to discuss the Juju aspects of this then.