From a1a5adebe7519ba94058ca98abbb76d4e5b243f7 Mon Sep 17 00:00:00 2001 From: Yury Kulazhenkov Date: Thu, 26 Oct 2023 12:28:08 +0300 Subject: [PATCH] Remove systemd service result file after configuration update 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 --- pkg/daemon/daemon.go | 17 +++++++++++++---- pkg/systemd/systemd.go | 14 ++++++++++++++ 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/pkg/daemon/daemon.go b/pkg/daemon/daemon.go index c35f72fccb..51dd35a136 100644 --- a/pkg/daemon/daemon.go +++ b/pkg/daemon/daemon.go @@ -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 { diff --git a/pkg/systemd/systemd.go b/pkg/systemd/systemd.go index 504fcf3890..a38e83191b 100644 --- a/pkg/systemd/systemd.go +++ b/pkg/systemd/systemd.go @@ -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 {