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

[CI Run] diagd: atomically write the ADS config #5258

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions python/ambassador_diag/diagd.py
Original file line number Diff line number Diff line change
Expand Up @@ -1771,8 +1771,19 @@ def _load_ir(
with open(app.bootstrap_path, "w") as output:
output.write(dump_json(bootstrap_config, pretty=True))

with open(app.ads_path, "w") as output:
output.write(dump_json(ads_config, pretty=True))
# Write the ADS config to a temporary file first and then rename to
# ensure atomic update. Otherwise, ambex could be reading the config
# while we are still writing it.
#
# Rename are only atomic if in the same FS. To ensure that this work
# with any setup, we store the temporary file at the same path but with
# an extension that is ignored by ambex.
ads_tmp_path = app.ads_path + ".tmp"
with open(ads_tmp_path, "w") as output:
# Don't use pretty here, to reduce the config size, and improve the
# dump and load speed of the config.
output.write(dump_json(ads_config, pretty=False))
os.rename(ads_tmp_path, app.ads_path)

with open(app.clustermap_path, "w") as output:
output.write(dump_json(clustermap, pretty=True))
Expand Down
Loading