Continuing the discussion from Juju 2.7.0: creating a new usability standard for infrastructure automation:
Wanted to make sure I have this right.
So if I understand correctly, normally, relations are with other units. So if I have a charm “WebApp” with 2 units and another charm “PostgreSQL” with 2 units and they are related to each-other you will have the relations:
-
webapp:db/1
<->postresql:db/1
-
webapp:db/1
<->postresql:db/2
-
webapp:db/2
<->postresql:db/1
-
webapp:db/2
<->postresql:db/2
So if I’m in the db-relation-changed
hook on webapp/1
and I do a relation-get
it will get the value from the specific postresql unit on which the relation changed. On the other hand if I do a relation-get --app
it will get a value that is unspecific to the unit and general to the whole PostgreSQL charm that I am related to.
That means that, if I were the author of the PostgreSQL charm, and I wanted clients to the db
relation to get the same values regardless of which unit they are connected to, I should be setting values using relation-set --app
.
Furthermore, on the same relation, the values set with relation-set
and the values set with relation-set --app
don’t conflict with each-other and are completely separate.
On another note, if I wanted to create a charm key-value store that all of my charm units could share to coordinate with each-other, I could create a peer relation and then use relation-set --app
and relation-get --app
to make that key-value store available to any unit in the charm.