Skip to content

Commit de8ed45

Browse files
Merge pull request #5576 from neisw/revert-5527-ocpbugs-58023
Revert "OCPBUGS-58023: Prevent unnecessary systemd unit disable"
2 parents 96310d2 + 5ddfe9b commit de8ed45

3 files changed

Lines changed: 21 additions & 73 deletions

File tree

pkg/controller/common/helpers.go

Lines changed: 12 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -945,25 +945,12 @@ func CalculateConfigFileDiffs(oldIgnConfig, newIgnConfig *ign3types.Config) []st
945945
return diffFileSet
946946
}
947947

948-
type UnitDiff struct {
949-
Added []ign3types.Unit
950-
Removed []ign3types.Unit
951-
Updated []ign3types.Unit
952-
}
953-
954-
// GetChangedConfigUnitsByType compares the units present in two ignition configurations, one
955-
// old config and the other new, a struct with units mapped to the type of change:
956-
// - New unit added: "Added"
957-
// - Unit previously existing removed: "Removed"
958-
// - Existing unit changed in some way: "Updated"
959-
func GetChangedConfigUnitsByType(oldIgnConfig, newIgnConfig *ign3types.Config) (unitDiffs UnitDiff) {
960-
diffUnit := UnitDiff{
961-
Added: []ign3types.Unit{},
962-
Removed: []ign3types.Unit{},
963-
Updated: []ign3types.Unit{},
964-
}
965-
966-
// Get the sets of the old and new units from the ignition configurations
948+
// CalculateConfigUnitDiffs compares the units present in two ignition configurations and returns the list of units
949+
// that are different between them
950+
//
951+
//nolint:dupl
952+
func CalculateConfigUnitDiffs(oldIgnConfig, newIgnConfig *ign3types.Config) []string {
953+
// Go through the units and see what is new or different
967954
oldUnitSet := make(map[string]ign3types.Unit)
968955
for _, u := range oldIgnConfig.Systemd.Units {
969956
oldUnitSet[u.Name] = u
@@ -972,25 +959,26 @@ func GetChangedConfigUnitsByType(oldIgnConfig, newIgnConfig *ign3types.Config) (
972959
for _, u := range newIgnConfig.Systemd.Units {
973960
newUnitSet[u.Name] = u
974961
}
962+
diffUnitSet := []string{}
975963

976964
// First check if any units were removed
977965
for unit := range oldUnitSet {
978966
_, ok := newUnitSet[unit]
979967
if !ok {
980-
diffUnit.Removed = append(diffUnit.Removed, oldUnitSet[unit])
968+
diffUnitSet = append(diffUnitSet, unit)
981969
}
982970
}
983971

984-
// Now check if any units were added or updated
972+
// Now check if any units were added/changed
985973
for name, newUnit := range newUnitSet {
986974
oldUnit, ok := oldUnitSet[name]
987975
if !ok {
988-
diffUnit.Added = append(diffUnit.Added, newUnitSet[name])
976+
diffUnitSet = append(diffUnitSet, name)
989977
} else if !reflect.DeepEqual(oldUnit, newUnit) {
990-
diffUnit.Updated = append(diffUnit.Updated, newUnitSet[name])
978+
diffUnitSet = append(diffUnitSet, name)
991979
}
992980
}
993-
return diffUnit
981+
return diffUnitSet
994982
}
995983

996984
// NewIgnFile returns a simple ignition3 file from just path and file contents.

pkg/daemon/on_disk_validation.go

Lines changed: 1 addition & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"fmt"
66
"os"
77
"path/filepath"
8-
"strings"
98

109
ign2types "github.com/coreos/ignition/config/v2_2/types"
1110
ign3types "github.com/coreos/ignition/v2/config/v3_5/types"
@@ -102,12 +101,7 @@ func checkV3Unit(unit ign3types.Unit, systemdPath string) error {
102101
return nil
103102
}
104103

105-
err := checkFileContentsAndMode(path, []byte(*unit.Contents), defaultFilePermissions)
106-
if err != nil {
107-
return err
108-
}
109-
110-
return checkUnitEnabled(unit.Name, unit.Enabled)
104+
return checkFileContentsAndMode(path, []byte(*unit.Contents), defaultFilePermissions)
111105
}
112106

113107
// checkV3Units validates the contents of all the units in the
@@ -237,29 +231,6 @@ func checkV2Files(files []ign2types.File) error {
237231
return nil
238232
}
239233

240-
// checkUnitEnabled checks whether a systemd unit is enabled as expected.
241-
func checkUnitEnabled(name string, expectedEnabled *bool) error {
242-
if expectedEnabled == nil {
243-
return nil
244-
}
245-
outBytes, _ := runGetOut("systemctl", "is-enabled", name)
246-
out := strings.TrimSpace(string(outBytes))
247-
248-
switch {
249-
case *expectedEnabled:
250-
// If expected to be enabled, reject known "not enabled" states
251-
if out == "disabled" || out == "masked" || out == "masked-runtime" || out == "not-found" {
252-
return fmt.Errorf("unit %q expected enabled=true, but systemd reports %q", name, out)
253-
}
254-
case !*expectedEnabled:
255-
// If expected to be disabled, reject any of the enabled-like states
256-
if out == "enabled" || out == "enabled-runtime" {
257-
return fmt.Errorf("unit %q expected enabled=false, but systemd reports %q", name, out)
258-
}
259-
}
260-
return nil
261-
}
262-
263234
// checkFileContentsAndMode reads the file from the filepath and compares its
264235
// contents and mode with the expectedContent and mode parameters. It logs an
265236
// error in case of an error or mismatch and returns the status of the

pkg/daemon/update.go

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import (
1212
"path/filepath"
1313
"reflect"
1414
goruntime "runtime"
15-
"slices"
1615
"strconv"
1716
"strings"
1817
"sync"
@@ -1014,20 +1013,13 @@ func (dn *Daemon) update(oldConfig, newConfig *mcfgv1.MachineConfig, skipCertifi
10141013
logSystem("Starting update from %s to %s: %+v", oldConfigName, newConfigName, diff)
10151014

10161015
diffFileSet := ctrlcommon.CalculateConfigFileDiffs(&oldIgnConfig, &newIgnConfig)
1017-
// Get the added and updated units
1018-
unitDiff := ctrlcommon.GetChangedConfigUnitsByType(&oldIgnConfig, &newIgnConfig)
1019-
addedOrChangedUnits := slices.Concat(unitDiff.Added, unitDiff.Updated)
1020-
// Get the names of all units changed in some way (added, removed, or updated)
1021-
var allChangedUnitNames []string
1022-
for _, unit := range append(addedOrChangedUnits, unitDiff.Removed...) {
1023-
allChangedUnitNames = append(allChangedUnitNames, unit.Name)
1024-
}
1016+
diffUnitSet := ctrlcommon.CalculateConfigUnitDiffs(&oldIgnConfig, &newIgnConfig)
10251017

10261018
var nodeDisruptionActions []opv1.NodeDisruptionPolicyStatusAction
10271019
var actions []string
10281020
// Node Disruption Policies cannot be used during firstboot as API is not accessible.
10291021
if !firstBoot {
1030-
nodeDisruptionActions, err = dn.calculatePostConfigChangeNodeDisruptionAction(diff, diffFileSet, allChangedUnitNames)
1022+
nodeDisruptionActions, err = dn.calculatePostConfigChangeNodeDisruptionAction(diff, diffFileSet, diffUnitSet)
10311023
} else {
10321024
actions, err = calculatePostConfigChangeAction(diff, diffFileSet)
10331025
klog.Infof("Skipping node disruption polciies as node is executing first boot.")
@@ -1133,13 +1125,13 @@ func (dn *Daemon) update(oldConfig, newConfig *mcfgv1.MachineConfig, skipCertifi
11331125
}
11341126

11351127
// update files on disk that need updating
1136-
if err := dn.updateFiles(oldIgnConfig, newIgnConfig, addedOrChangedUnits, skipCertificateWrite); err != nil {
1128+
if err := dn.updateFiles(oldIgnConfig, newIgnConfig, skipCertificateWrite); err != nil {
11371129
return err
11381130
}
11391131

11401132
defer func() {
11411133
if retErr != nil {
1142-
if err := dn.updateFiles(newIgnConfig, oldIgnConfig, addedOrChangedUnits, skipCertificateWrite); err != nil {
1134+
if err := dn.updateFiles(newIgnConfig, oldIgnConfig, skipCertificateWrite); err != nil {
11431135
errs := kubeErrs.NewAggregate([]error{err, retErr})
11441136
retErr = fmt.Errorf("error rolling back files writes: %w", errs)
11451137
return
@@ -1274,18 +1266,15 @@ func (dn *Daemon) updateHypershift(oldConfig, newConfig *mcfgv1.MachineConfig, d
12741266
return fmt.Errorf("parsing new Ignition config failed: %w", err)
12751267
}
12761268

1277-
unitDiff := ctrlcommon.GetChangedConfigUnitsByType(&oldIgnConfig, &newIgnConfig)
1278-
addedOrChangedUnits := slices.Concat(unitDiff.Added, unitDiff.Updated)
1279-
12801269
// update files on disk that need updating
12811270
// We should't skip the certificate write in HyperShift since it does not run the extra daemon process
1282-
if err := dn.updateFiles(oldIgnConfig, newIgnConfig, addedOrChangedUnits, false); err != nil {
1271+
if err := dn.updateFiles(oldIgnConfig, newIgnConfig, false); err != nil {
12831272
return err
12841273
}
12851274

12861275
defer func() {
12871276
if retErr != nil {
1288-
if err := dn.updateFiles(newIgnConfig, oldIgnConfig, addedOrChangedUnits, false); err != nil {
1277+
if err := dn.updateFiles(newIgnConfig, oldIgnConfig, false); err != nil {
12891278
errs := kubeErrs.NewAggregate([]error{err, retErr})
12901279
retErr = fmt.Errorf("error rolling back files writes: %w", errs)
12911280
return
@@ -1810,12 +1799,12 @@ func (dn *CoreOSDaemon) getKernelPackagesForTargetRelease() (releaseKernelPackag
18101799
// whatever has been written is picked up by the appropriate daemons, if
18111800
// required. in particular, a daemon-reload and restart for any unit files
18121801
// touched.
1813-
func (dn *Daemon) updateFiles(oldIgnConfig, newIgnConfig ign3types.Config, addedOrChangedUnits []ign3types.Unit, skipCertificateWrite bool) error {
1802+
func (dn *Daemon) updateFiles(oldIgnConfig, newIgnConfig ign3types.Config, skipCertificateWrite bool) error {
18141803
klog.Info("Updating files")
18151804
if err := dn.writeFiles(newIgnConfig.Storage.Files, skipCertificateWrite); err != nil {
18161805
return err
18171806
}
1818-
if err := dn.writeUnits(addedOrChangedUnits); err != nil {
1807+
if err := dn.writeUnits(newIgnConfig.Systemd.Units); err != nil {
18191808
return err
18201809
}
18211810
return dn.deleteStaleData(oldIgnConfig, newIgnConfig)

0 commit comments

Comments
 (0)