-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[DPE-3049] templated config #186
Conversation
fb7d8aa
to
ca23974
Compare
3fe6142
to
10b6f86
Compare
10b6f86
to
496363b
Compare
9e69f30
to
b248aa9
Compare
b248aa9
to
8f0a651
Compare
# Nothing set in the config peer data trying to regenerate based on old data in case of update. | ||
elif not self.unit.is_leader(): | ||
if cfg := self.get_secret(APP_SCOPE, CFG_FILE_DATABAG_KEY): | ||
try: | ||
parser = ConfigParser() | ||
parser.optionxform = str | ||
parser.read_string(cfg) | ||
old_cfg = dict(parser) | ||
if databases := old_cfg.get("databases"): | ||
databases.pop("DEFAULT", None) | ||
result = {} | ||
i = 1 | ||
for database in dict(databases): | ||
if database.endswith("_standby") or database.endswith("_readonly"): | ||
continue | ||
result[str(i)] = {"name": database, "legacy": False} | ||
i += 1 | ||
return result | ||
except Exception: | ||
logger.exception("Unable to parse legacy config format") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Try to regen the old cfg, so that we can upgrade without downtime.
database = self.legacy_db_relation.get_databags(relation)[0].get("database") | ||
if database: | ||
databases[relation.id] = { | ||
"name": database, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the db names sensitive info? Should this go in a secret instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMHO, it is not a sensitive info (normally) but can go through secrets as well.
@delgod ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would not normally put the database name into secret.
{% for name, database in databases.items() %} | ||
{{ name }} = host={{ database.host }} dbname={{ database.dbname }} port={{ database.port }} auth_user={{ database.auth_user }} | ||
{% endfor %} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should be able to split out most (all?) of the moving parts and use %include
instead to reduce the amount of rerenders. Created DPE-3549 to track.
parser = ConfigParser() | ||
parser.optionxform = str | ||
parser.read_string( | ||
await cat_file_from_unit(ops_test, f"{PGB_DIR}/instance_0/pgbouncer.ini", unit_name) | ||
) | ||
|
||
cfg = dict(parser) | ||
# Convert Section objects to dictionaries, so they can hold dictionaries themselves. | ||
for section, data in cfg.items(): | ||
cfg[section] = dict(data) | ||
|
||
# ConfigParser object creates a DEFAULT section of an .ini file, which we don't need. | ||
del cfg["DEFAULT"] | ||
|
||
return cfg |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copied from the lib.
self.charm.render_pgb_config(reload_pgbouncer=True) | ||
self.charm.toggle_monitoring_layer(self.charm.backend.ready) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Most of the cfg updates and restarts will happen here, when pgb_dbs_config
gets updated.
1ae3f8c
to
19b13e1
Compare
@@ -316,7 +304,7 @@ def _on_relation_changed(self, change_event: RelationChangedEvent): | |||
change_event.defer() | |||
return | |||
|
|||
self.update_postgres_endpoints(change_event.relation, reload_pgbouncer=True) | |||
self.charm.render_pgb_config(reload_pgbouncer=True) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Relation errors out without this reload
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very interesting approach. Happy to test it in edge!
Do you mind to expand unit test they are a bit shrinked here. Keep the final wording to Marcelo.
database = self.legacy_db_relation.get_databags(relation)[0].get("database") | ||
if database: | ||
databases[relation.id] = { | ||
"name": database, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMHO, it is not a sensitive info (normally) but can go through secrets as well.
@delgod ?
da87381
to
2f3443f
Compare
2f3443f
to
3620aa4
Compare
Remove sync between on file configuration and peer data and just rerender a jinja template.