RelationDepartedEvent in ops has no private-address

I need to use the IP address of a departing unit in a relation.

However, if I try to access this value, its not available and throws a KeyError.

This is example code.

def _on_relation_departed(self, event: RelationDepartedEvent):
    raddr = event.relation.data[event.unit]['private-address']
    logging.debug("Removing trusted proxy: " + raddr)

Error is like this…

KeyError: <ops.model.Unit haproxy/1>
unit-nextcloud-0: 15:36:47 ERROR juju.worker.uniter.operation hook "website-relation-departed" (via hook dispatching script: dispatch) failed: exit status 1

If this is expected when a unit departs, do I need to maintain my own data-bucket with these IP:s in order to be able to use that?

Hi Erik,

I’ve experienced this as well and thought the same thing about maintaining my own metadata hash of remote unit relation data for scale-back operations.

I believe the typical method of handling this is to iterate the remaining list of related units rather than targetting the removed unit. This method does have the benefit of catching any related units that may not have been caught during joins or departed hooks in the past. I.E. consider idempotent configuration generation with current state vs targeted configuration reaction based on assumed prior state.

1 Like

This is exactly what I had to resort to and I guess it works. I do however think that this information is monumental to have clearly stipulated since it will for sure end up in an exception when called in the ops framework for this event. (Like it did for me).

If this is now a known situation, developers like myself will wonder if there is a bug or an expected behavior.

I do think however, that the consistency of the framework itself would perhaps benefit from actually maintaining this information - but I’m not sure.

@tmihoc - this above information is really something that would need to be very clearly expressed in the Relations docs both

here: Welcome to The Operator Framework’s documentation! — The Operator Framework documentation

and here

1 Like