Skip to content
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

Merged
merged 61 commits into from
Feb 14, 2024
Merged

[DPE-3049] templated config #186

merged 61 commits into from
Feb 14, 2024

Conversation

dragomirp
Copy link
Contributor

@dragomirp dragomirp commented Jan 23, 2024

Remove sync between on file configuration and peer data and just rerender a jinja template.

@dragomirp dragomirp force-pushed the dpe-3049-templated-config branch 7 times, most recently from 9e69f30 to b248aa9 Compare January 25, 2024 01:14
Comment on lines +651 to +670
# 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")
Copy link
Contributor Author

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,
Copy link
Contributor Author

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?

Copy link
Contributor

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 ?

Copy link
Member

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.

Comment on lines +2 to +4
{% for name, database in databases.items() %}
{{ name }} = host={{ database.host }} dbname={{ database.dbname }} port={{ database.port }} auth_user={{ database.auth_user }}
{% endfor %}
Copy link
Contributor Author

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.

Comment on lines +117 to +131
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
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copied from the lib.

Comment on lines +162 to +163
self.charm.render_pgb_config(reload_pgbouncer=True)
self.charm.toggle_monitoring_layer(self.charm.backend.ready)
Copy link
Contributor Author

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.

@@ -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)
Copy link
Contributor Author

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

@dragomirp dragomirp marked this pull request as ready for review February 12, 2024 20:59
Copy link
Contributor

@taurus-forever taurus-forever left a 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,
Copy link
Contributor

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 ?

src/charm.py Outdated Show resolved Hide resolved
@dragomirp dragomirp merged commit 4952d4e into main Feb 14, 2024
29 checks passed
@dragomirp dragomirp deleted the dpe-3049-templated-config branch February 14, 2024 17:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants