generated from canonical/template-operator
-
Notifications
You must be signed in to change notification settings - Fork 5
backend_database relation
Andreia Velasco edited this page Sep 27, 2024
·
1 revision
This reference documentation details the implementation of the backend-database
relation. The file implementing these relations can be found here: src/relations/backend_database.py.
These are the expected contents of the databags in this relation (all values are examples, generated in a running test instance):
category | keys | pgbouncer-k8s-o… | postgresql-k8s/0 |
---|---|---|---|
metadata | endpoint |
'backend-databa… | 'database' |
leader |
True | True | |
application data | data |
{"endpoints":"postgresql-k8s", "password":"18cqKCp19xOPBh", "read-only-endpoints":"postgresql-k8s","username":"relation_18", "version":"12.9"} | {"database":"postgresql", "extra-user-roles","SUPERUSER" |
database |
pgbouncer | ||
endpoints |
postgresql-k8s-… | ||
extra-user-roles |
SUPERUSER | ||
password |
18cqKCp19xOPBh | ||
read-only-endpoints |
postgresql-k8s-… | ||
username |
relation_18 | ||
version |
12.9 |
These flowcharts detail the control flow of the hooks in this program. Unless otherwise stated, a hook deferral is always followed by a return.
flowchart TD
hook_fired([backend-database-requested Hook]) --> is_leader{Is current unit leader?}
is_leader -- no --> rtn([return])
is_leader -- yes --> is_running{Is pgbouncer running?}
is_running -- no --> defer2>defer]
is_running -- yes --> is_backend_ready{is backend database charm ready, and has pgbouncer been provided with the necessary relation data?}
is_backend_ready -- no --> defer>defer]
is_backend_ready -- yes --> generate_user[Generate username & password]
generate_user --> create_auth_func[create auth function on postgres]
create_auth_func --> save_auth_data[update pgbouncer config, and save auth data to container and peer databag]
save_auth_data --> update_relations[update postgres endpoints in client relations]
update_relations --> update_status[update charm status]
update_status --> rtn2([return])
flowchart TD
hook_fired([backend-database-relation-departed Hook]) --> update_info[update relation connection information]
update_info --> is_this_unit_departing{Is this unit the departing unit?}
is_this_unit_departing -- yes --> tell_peers[update unit databag to tell peers this unit is departing]
tell_peers --> rtn([return])
is_this_unit_departing -- no --> is_leader{is this unit the leader, and is it departing}
is_leader -- no --> rtn2([return])
is_leader -- yes --> scale_down{Is this application scaling down, but not to 0?}
scale_down -- yes --> rtn3([return])
scale_down -- no --> remove_auth[Remove auth function, and delete auth user]
remove_auth --> rtn4([return])
flowchart TD
hook_fired([backend-database-relation-broken Hook]) --> check_depart{Is this unit not the leader, or is the relation_departing flag in the unit databag?}
check_depart -- yes --> rtn([return])
check_depart -- no --> is_cfg{Is pgbouncer config available?}
is_cfg -- no --> defer>defer]
is_cfg -- yes --> remove_auth[Remove authentication information from pgbouncer config]
remove_auth --> rtn2([return])