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

Make config reloader file writes atomic #962

Merged
merged 2 commits into from Mar 22, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 8 additions & 1 deletion pkg/reloader/reloader.go
Expand Up @@ -199,9 +199,16 @@ func (r *Reloader) apply(ctx context.Context) error {
return errors.Wrap(err, "expand environment variables")
}

if err := ioutil.WriteFile(r.cfgOutputFile, b, 0666); err != nil {
tmpFile := r.cfgOutputFile + ".tmp"
defer func() {
_ = os.Remove(tmpFile)
}()
if err := ioutil.WriteFile(tmpFile, b, 0666); err != nil {
return errors.Wrap(err, "write file")
}
if err := os.Rename(tmpFile, r.cfgOutputFile); err != nil {
return errors.Wrap(err, "rename file")
}
}
}

Expand Down