-
Notifications
You must be signed in to change notification settings - Fork 594
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
Configuration writes should be atomic #1252
Configuration writes should be atomic #1252
Conversation
This change introduces a method `atomicFileWrite(...)` which writes to a temporary file and then renames it to avoid partial reads, e.g. ``` Mar 29 04:13:05 labkubedualhost-node-1 crio[33593]: time="2024-03-29 04:13:05.977398607+09:00" level=info msg="CNI monitoring event CREATE \"/etc/cni/net.d/00-multus.conf\"" Mar 29 04:13:05 labkubedualhost-node-1 crio[33593]: time="2024-03-29 04:13:05.977767189+09:00" level=error msg="Error loading CNI config file /etc/cni/net.d/00-multus.conf: error parsing configuration: unexpected end of JSON input" ```
ad5970c
to
5d0ff07
Compare
@@ -64,6 +65,32 @@ func NewManager(config MultusConf) (*Manager, error) { | |||
return newManager(config, defaultPluginName) | |||
} | |||
|
|||
// atomicFileWrite writes our configs atomically to avoid partial reads | |||
func atomicFileWrite(filename string, data []byte, perm os.FileMode) error { |
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.
As warning mentiond, perm is not used in the function hence, none changed the files permission to 0644. Could you please change the file permission?
func atomicFileWrite(filename string, data []byte, perm os.FileMode) error { | ||
// Create a temporary file in the same directory as the destination file | ||
dir := filepath.Dir(filename) | ||
tmpFile, err := ioutil.TempFile(dir, ".multus.tmp") |
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.
ioutil.TempFile() is deprecated as https://pkg.go.dev/io/ioutil#TempFile so please change that.
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.
This pull request is stale because it has been open 90 days with no activity. Remove stale label or comment or this will be closed in 7 days. |
This change introduces a method
atomicFileWrite(...)
which writes to a temporary file and then renames it to avoid partial reads, e.g.