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
diff --git a/src/charm.py b/src/charm.py
index d0239e4..bb5c4f6 100755
--- a/src/charm.py
+++ b/src/charm.py
@@ -234,12 +234,16 @@ class DiscourseCharm(CharmBase):
234 from inside the event handler per https://github.com/canonical/ops-lib-pgsql/issues/2234 from inside the event handler per https://github.com/canonical/ops-lib-pgsql/issues/2
235 """235 """
236 self.stored.has_db_relation = True236 self.stored.has_db_relation = True
237 # Ensure event.database is always set to a non-empty string. PostgreSQL
238 # can infer this if it's in the same model as Discourse, but not if
239 # we're using cross-model relations.
240 db_name = self.model.config["db_name"] or self.framework.model.app.name
237 # Per https://github.com/canonical/ops-lib-pgsql/issues/2,241 # Per https://github.com/canonical/ops-lib-pgsql/issues/2,
238 # changing the setting in the config will not take effect,242 # changing the setting in the config will not take effect,
239 # unless the relation is dropped and recreated.243 # unless the relation is dropped and recreated.
240 if self.model.unit.is_leader():244 if self.model.unit.is_leader():
241 event.database = self.model.config["db_name"]245 event.database = db_name
242 elif event.database != self.model.config["db_name"]:246 elif event.database != db_name:
243 # Leader has not yet set requirements. Defer, in case this unit247 # Leader has not yet set requirements. Defer, in case this unit
244 # becomes leader and needs to perform that operation.248 # becomes leader and needs to perform that operation.
245 event.defer()249 event.defer()

Subscribers

People subscribed via source and target branches