Skip to content
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
54 changes: 54 additions & 0 deletions pkg/daemon/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -840,6 +840,32 @@ func restorePath(path string) error {
return nil
}

// parse path to find out if its a systemd dropin
// Returns is dropin (true/false), service name, dropin name
func isSystemdDropin(path string) (bool, string, string) {
glog.V(2).Infof("DEBUG isSystemdDropin path=%v", path)
if !strings.HasPrefix(path, "/etc/systemd/system") {
return false, "", ""
}
pathSegments := strings.Split(path, "/")
glog.V(2).Infof("DEBUG isSystemdDropin pathSegments=%v", pathSegments)
if len(pathSegments) != 5 {
return false, "", ""
}
dropinName := pathSegments[len(pathSegments)-1]
glog.V(2).Infof("DEBUG isSystemdDropin dropinName=%v", dropinName)
servicePart := pathSegments[len(pathSegments)-2]
glog.V(2).Infof("DEBUG isSystemdDropin servicePart=%v", servicePart)
allServiceSegments := strings.Split(servicePart, ".")
glog.V(2).Infof("DEBUG isSystemdDropin allServiceSegments=%v", allServiceSegments)
if allServiceSegments[len(allServiceSegments)-1] != "d" {
return false, "", ""
}
serviceName := strings.Join(allServiceSegments[:len(allServiceSegments)-1], ".")
glog.V(2).Infof("DEBUG isSystemdDropin serviceName=%v", serviceName)
return true, serviceName, dropinName
}

// deleteStaleData performs a diff of the new and the old Ignition config. It then deletes
// all the files, units that are present in the old config but not in the new one.
// this function will error out if it fails to delete a file (with the exception
Expand Down Expand Up @@ -892,6 +918,34 @@ func (dn *Daemon) deleteStaleData(oldIgnConfig, newIgnConfig *igntypes.Config) e
continue
}

// Check Systemd.Units.Dropins - don't remove the file if configuration has been converted into a dropin
fileReplacedWithDropin := false
if ok, service, dropin := isSystemdDropin(f.Path); ok {
glog.V(2).Infof("DEBUG isSystemdDropin ok=%v service=%v dropin=%v", ok, service, dropin)
for _, u := range newIgnConfig.Systemd.Units {
glog.V(2).Infof("DEBUG isSystemdDropin service=%v", u.Name)
if u.Name == service {
glog.V(2).Infof("DEBUG isSystemdDropin found matching service")
for _, j := range u.Dropins {
glog.V(2).Infof("DEBUG isSystemdDropin dropin=%v", j.Name)
if j.Name == dropin {
glog.V(2).Infof("DEBUG isSystemdDropin found matching dropin")
fileReplacedWithDropin = true
break
}
}
if fileReplacedWithDropin {
break
}
}
}
}

if fileReplacedWithDropin {
glog.V(2).Infof("Not removing file %q: replaced with systemd dropin", f.Path)
continue
}

if err := os.Remove(origFileName(f.Path)); err != nil {
return errors.Wrapf(err, "deleting orig file %q: %v", origFileName(f.Path), err)
}
Expand Down