Merge ~mthaddon/charm-k8s-discourse/+git/charm-k8s-discourse:app-name into charm-k8s-discourse:master

Proposed by Tom Haddon
Status: Merged
Approved by: Jay Kuri
Approved revision: 04e7a6ea4c0f3dfcf6da5594c36691bf8786a116
Merged at revision: fc9fdfd2a84a21bd9e1b14badef7c6ac9205728a
Proposed branch: ~mthaddon/charm-k8s-discourse/+git/charm-k8s-discourse:app-name
Merge into: charm-k8s-discourse:master
Diff against target: 23 lines (+6/-2)
1 file modified
src/charm.py (+6/-2)
Reviewer Review Type Date Requested Status
Jay Kuri (community) Approve
Canonical IS Reviewers Pending
Review via email: mp+395134@code.launchpad.net

Commit message

Ensure we always set event.database to a non-empty string - PG isn't able to infer this in a CMR situation

Description of the change

Ensure we always set event.database to a non-empty string - PG isn't able to infer this in a CMR situation

To post a comment you must log in.
Revision history for this message
Tom Haddon (mthaddon) wrote :

I've tested this locally both with an in-model PostgreSQL db, and using CMR with a db in an IaaS model.

Revision history for this message
🤖 Canonical IS Merge Bot (canonical-is-mergebot) wrote :

This merge proposal is being monitored by mergebot. Change the status to Approved to merge.

Revision history for this message
Jay Kuri (jk0ne) wrote :

Confirmed that this works. ready for merge.

review: Approve
Revision history for this message
🤖 Canonical IS Merge Bot (canonical-is-mergebot) wrote :

Change successfully merged at revision fc9fdfd2a84a21bd9e1b14badef7c6ac9205728a

Revision history for this message
Stuart Bishop (stub) wrote :

This is working around a bug in the postgresql-k8s charm, which should now be fixed. No harm being explicit though.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/src/charm.py b/src/charm.py
2index d0239e4..bb5c4f6 100755
3--- a/src/charm.py
4+++ b/src/charm.py
5@@ -234,12 +234,16 @@ class DiscourseCharm(CharmBase):
6 from inside the event handler per https://github.com/canonical/ops-lib-pgsql/issues/2
7 """
8 self.stored.has_db_relation = True
9+ # Ensure event.database is always set to a non-empty string. PostgreSQL
10+ # can infer this if it's in the same model as Discourse, but not if
11+ # we're using cross-model relations.
12+ db_name = self.model.config["db_name"] or self.framework.model.app.name
13 # Per https://github.com/canonical/ops-lib-pgsql/issues/2,
14 # changing the setting in the config will not take effect,
15 # unless the relation is dropped and recreated.
16 if self.model.unit.is_leader():
17- event.database = self.model.config["db_name"]
18- elif event.database != self.model.config["db_name"]:
19+ event.database = db_name
20+ elif event.database != db_name:
21 # Leader has not yet set requirements. Defer, in case this unit
22 # becomes leader and needs to perform that operation.
23 event.defer()

Subscribers

People subscribed via source and target branches