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 31, 2023
1 parent 2be5408 commit f1afab5
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
15 changes: 12 additions & 3 deletions pkg/daemon/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -583,13 +583,22 @@ 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 {
log.Log.Error(err, "nodeStateSyncHandler(): failed to write configuration file for systemd mode")
return err
}
reqDrain = reqDrain || r
reqReboot = reqReboot || r
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 {
log.Log.Error(err, "nodeStateSyncHandler(): failed to remove result file for systemd mode")
return err
}
}
reqDrain = reqDrain || systemdConfModified
reqReboot = reqReboot || systemdConfModified
log.Log.V(0).Info("nodeStateSyncHandler(): systemd mode WriteConfFile results",
"drain-required", reqDrain, "reboot-required", reqReboot, "disable-drain", dn.disableDrain)

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

func RemoveSriovResult() error {
err := os.Remove(SriovHostSystemdResultPath)
if err != nil {
if os.IsNotExist(err) {
log.Log.V(2).Info("RemoveSriovResult(): result file not found")
return nil
}
log.Log.Error(err, "RemoveSriovResult(): failed to remove sriov result file", "path", SriovHostSystemdResultPath)
return err
}
log.Log.V(2).Info("RemoveSriovResult(): result file removed")
return nil
}

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

0 comments on commit f1afab5

Please sign in to comment.