Skip to content

Commit

Permalink
Remove systemd service result file after configuration update
Browse files Browse the repository at this point in the history
This is required to ensure that we will not read outdated result in
edge case scenarios, e.g. when systemd service exist but for some
reason was disabled by the user.

Signed-off-by: Yury Kulazhenkov <[email protected]>
  • Loading branch information
ykulazhenkov committed Oct 27, 2023
1 parent 188236a commit a1a5ade
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
17 changes: 13 additions & 4 deletions pkg/daemon/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -572,14 +572,23 @@ func (dn *Daemon) nodeStateSyncHandler() error {
// or there is a new config we need to apply
// When using systemd configuration we write the file
if dn.useSystemdService {
r, err := systemd.WriteConfFile(latestState, dn.devMode, dn.platform)
systemdConfModified, err := systemd.WriteConfFile(latestState, dn.devMode, dn.platform)
if err != nil {
glog.Errorf("nodeStateSyncHandler(): failed to write configuration file for systemd mode: %v", err)
return err
}
reqDrain = reqDrain || r
reqReboot = reqReboot || r
glog.V(0).Infof("nodeStateSyncHandler(): systemd mode reqDrain %v, reqReboot %v disableDrain %v", r, r, dn.disableDrain)
if systemdConfModified {
// remove existing result file to make sure that we will not use outdated result, e.g. in case if
// systemd service was not triggered for some reason
err = systemd.RemoveSriovResult()
if err != nil {
glog.Errorf("nodeStateSyncHandler(): failed to remove result file for systemd mode: %v", err)
return err
}
}
reqDrain = reqDrain || systemdConfModified
reqReboot = reqReboot || systemdConfModified
glog.V(0).Infof("nodeStateSyncHandler(): systemd mode reqDrain %v, reqReboot %v disableDrain %v", systemdConfModified, systemdConfModified, dn.disableDrain)

err = systemd.WriteSriovSupportedNics()
if err != nil {
Expand Down
14 changes: 14 additions & 0 deletions pkg/systemd/systemd.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,20 @@ func ReadSriovResult() (*SriovResult, error) {
return result, err
}

func RemoveSriovResult() error {
err := os.Remove(SriovHostSystemdResultPath)
if err != nil {
if os.IsNotExist(err) {
glog.V(2).Infof("RemoveSriovResult(): result file not found")
return nil
}
glog.Errorf("RemoveSriovResult(): failed to remove sriov result file on path %s: %v", SriovHostSystemdResultPath, err)
return err
}
glog.V(2).Infof("RemoveSriovResult(): result file removed")
return nil
}

func WriteSriovSupportedNics() error {
_, err := os.Stat(sriovHostSystemdSupportedNicPath)
if err != nil {
Expand Down

0 comments on commit a1a5ade

Please sign in to comment.