-
Notifications
You must be signed in to change notification settings - Fork 459
pkg/daemon: do not delete host files when deleting an MC #797
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -485,6 +485,13 @@ func (dn *Daemon) deleteStaleData(oldConfig, newConfig *mcfgv1.MachineConfig) er | |
|
|
||
| for _, f := range oldConfig.Spec.Config.Storage.Files { | ||
| if _, ok := newFileSet[f.Path]; !ok { | ||
| if _, err := os.Stat(origFileName(f.Path)); err == nil { | ||
| if err := os.Rename(origFileName(f.Path), f.Path); err != nil { | ||
| return err | ||
| } | ||
| glog.V(2).Infof("Restored file %q", f.Path) | ||
| continue | ||
| } | ||
| glog.V(2).Infof("Deleting stale config file: %s", f.Path) | ||
| if err := os.Remove(f.Path); err != nil { | ||
| newErr := fmt.Errorf("unable to delete %s: %s", f.Path, err) | ||
|
|
@@ -680,13 +687,36 @@ func (dn *Daemon) writeFiles(files []igntypes.File) error { | |
| return fmt.Errorf("failed to retrieve file ownership for file %q: %v", file.Path, err) | ||
| } | ||
| } | ||
| if err := createOrigFile(file.Path); err != nil { | ||
| return err | ||
| } | ||
| if err := writeFileAtomically(file.Path, contents.Data, defaultDirectoryPermissions, mode, uid, gid); err != nil { | ||
| return err | ||
| } | ||
| } | ||
| return nil | ||
| } | ||
|
|
||
| func origFileName(fpath string) string { | ||
| return fpath + ".mcdorig" | ||
| } | ||
|
|
||
| func createOrigFile(fpath string) error { | ||
| if _, err := os.Stat(fpath); err != nil { | ||
| // the file isn't there, no need to back it up | ||
| // we could check ENOENT only maybe? | ||
| return nil | ||
| } | ||
| if _, err := os.Stat(origFileName(fpath)); err == nil { | ||
| // the orig file is already there and we avoid creating a new one to preserve the real default | ||
| return nil | ||
| } | ||
| if out, err := exec.Command("cp", "-a", "--reflink=auto", fpath, origFileName(fpath)).CombinedOutput(); err != nil { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Of course if this is interrupted in the middle we'll end up with an incomplete backup but...let's just get this in!
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The libglnx code I wrote for this properly clones to an If only calling C from golang wasn't unspeakably awful... Anyways we can circle back to polishing this bit later. |
||
| return errors.Wrapf(err, "creating orig file for %q: %s", fpath, string(out)) | ||
| } | ||
| return nil | ||
| } | ||
|
|
||
| // This is essentially ResolveNodeUidAndGid() from Ignition; XXX should dedupe | ||
| func getFileOwnership(file igntypes.File) (int, int, error) { | ||
| uid, gid := 0, 0 // default to root | ||
|
|
@@ -781,12 +811,12 @@ func (dn *Daemon) updateOS(config *mcfgv1.MachineConfig) error { | |
|
|
||
| // RHEL 7.6 logger (util-linux) doesn't have the --journald flag | ||
| func (dn *Daemon) isLoggingToJournalSupported() bool { | ||
| if dn.OperatingSystem == machineConfigDaemonOSRHEL { | ||
| return true | ||
| } | ||
| loggerOutput, err := exec.Command("logger", "--help").CombinedOutput() | ||
| if err != nil { | ||
| dn.logSystem("error running logger --help: %v", err) | ||
| if dn.OperatingSystem == machineConfigDaemonOSRHCOS { | ||
| return true | ||
| } | ||
| return false | ||
| } | ||
| return strings.Contains(string(loggerOutput), "--journald") | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.