daemon: consider addition of an RT kernel package as update
Install additional RT kernel package if any shipped
as part of update in machine-os-content
Also some code cleanup to simplify RT kernel update logic
Fixes:
@@ -216,30 +216,27 @@ func canonicalizeEmptyMC(config *mcfgv1.MachineConfig) *mcfgv1.MachineConfig {
}
}
-// Returns true if updated packages are available
-func rtKernelUpdateAvailable(rpms []os.FileInfo, rtKernelPkg []string) (bool, error) {
- for _, pkg := range rtKernelPkg {
- var out []byte
- var err error
- found := false
-
- if out, err = exec.Command("rpm", "-q", pkg).Output(); err != nil {
- wrappedErr := fmt.Errorf("Failed to run rpm -q : %v", err)
- return false, wrappedErr
+// Returns true if updated packages or new RT kernel related packages are available
+func rtKernelUpdateAvailable(updateRpms []os.FileInfo, installedRTKernelRpms []string) bool {
+ // if list of RT kernel packages in update is more than installed list, then we have additional packages to install
+ if len(updateRpms) > len(installedRTKernelRpms) {
+ return true
}
- searchRpm := strings.TrimSpace(string(out)) + ".rpm"
- for _, rpm := range rpms {
+ for _, pkg := range installedRTKernelRpms {
+ found := false
+ searchRpm := pkg + ".rpm"
+ for _, rpm := range updateRpms {
if rpm.Name() == searchRpm {
found = true
break
}
}
if !found {
- return true, nil
+ return true
}
}
- return false, nil
+ return false
}
// return true if the MachineConfigDiff is not empty
@@ -780,12 +777,7 @@ func (dn *Daemon) switchKernel(oldConfig, newConfig *mcfgv1.MachineConfig) error
args = append(args, installedRTKernelRpm)
}
// Perform kernel-rt package update only if updated packages are available
- var updateAvailable bool
- if updateAvailable, err = rtKernelUpdateAvailable(rtKernelRpms, installedRTKernelRpms); err != nil {
- return err
- } else if !updateAvailable {
- return nil
- }
+ if rtKernelUpdateAvailable(rtKernelRpms, installedRTKernelRpms) {
for _, rpm := range rtKernelRpms {
args = append(args, "--install", fmt.Sprintf("%s/%s", mnt, rpm.Name()))
}
@@ -795,6 +787,7 @@ func (dn *Daemon) switchKernel(oldConfig, newConfig *mcfgv1.MachineConfig) error
}
}
}
+ }
return nil
}
