diff --git a/pkg/reloader/reloader.go b/pkg/reloader/reloader.go index 68c9d1709d..e666590451 100644 --- a/pkg/reloader/reloader.go +++ b/pkg/reloader/reloader.go @@ -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") + } } }