Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

Working on the postgresql charm a bit, and I'm wondering if there is a way to supply overrides for default values in a "juju-way".

In my charm that will be consuming the services provided by postgresql, I was thinking I could override things like the database name, or the name of the super_user created. If I stick something like this in the relation-joined:

relation-set user=my_superuser

I'm having an issue where the postgres/db-admin-relation-changed can actually run before the consumer joins runs (or finishes running at least).

Eventually, the postgresql/db-admin-relation-changed will run and get my data, but if it runs too quickly, I could wind up with 2 superusers.

TL;DR: Is there a way to guarantee that default configuration is overridden in a service on the provides side of the relationship?

share|improve this question

1 Answer 1

up vote 3 down vote accepted

There is no way to guarantee which hook runs first in the hook execution scheme, but you can predict which hook series will execute first. When a relation is added the *-relation-joined hooks are fired first (on both services, with no clear winner of who goes first), followed by the *-relation-changed hooks for each service. Since you can't guarantee which of the who hooks in a given relation state will fire first you can trump the relation-changed hook on the Postgres charm by placing your relation-set commands in relation-joined hook in your charm.

This won't work for every charm/relation as it depends on where the heavy lifting is done for each relation. For example, the MySQL charm does all the database creation instructions during the relation-joined hook, so the above wouldn't actually help you achieve anything as you'd still have the race condition.

Ideally unless there's a really good reason using what the postgres charm provides is probably the best way to go.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.