Skip to content

Commit 533cd2b

Browse files
Merge pull request #5213 from stbenjam/revert-5148-1754043225154
TRT-2232: Revert #5148 "OCPBUGS-58023: Prevent unnecessary systemd unit disable"
2 parents d88a5c1 + ea59abe commit 533cd2b

File tree

3 files changed

+10
-40
lines changed

3 files changed

+10
-40
lines changed

pkg/controller/common/helpers.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -926,7 +926,7 @@ func CalculateConfigFileDiffs(oldIgnConfig, newIgnConfig *ign3types.Config) []st
926926
// that are different between them
927927
//
928928
//nolint:dupl
929-
func CalculateConfigUnitDiffs(oldIgnConfig, newIgnConfig *ign3types.Config) ([]string, []ign3types.Unit) {
929+
func CalculateConfigUnitDiffs(oldIgnConfig, newIgnConfig *ign3types.Config) []string {
930930
// Go through the units and see what is new or different
931931
oldUnitSet := make(map[string]ign3types.Unit)
932932
for _, u := range oldIgnConfig.Systemd.Units {
@@ -946,19 +946,16 @@ func CalculateConfigUnitDiffs(oldIgnConfig, newIgnConfig *ign3types.Config) ([]s
946946
}
947947
}
948948

949-
addedOrChangedUnits := []ign3types.Unit{}
950949
// Now check if any units were added/changed
951950
for name, newUnit := range newUnitSet {
952951
oldUnit, ok := oldUnitSet[name]
953952
if !ok {
954953
diffUnitSet = append(diffUnitSet, name)
955-
addedOrChangedUnits = append(addedOrChangedUnits, newUnit)
956954
} else if !reflect.DeepEqual(oldUnit, newUnit) {
957955
diffUnitSet = append(diffUnitSet, name)
958-
addedOrChangedUnits = append(addedOrChangedUnits, newUnit)
959956
}
960957
}
961-
return diffUnitSet, addedOrChangedUnits
958+
return diffUnitSet
962959
}
963960

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

pkg/daemon/on_disk_validation.go

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@ import (
44
"bytes"
55
"fmt"
66
"os"
7-
"os/exec"
87
"path/filepath"
9-
"strings"
108

119
ign2types "github.com/coreos/ignition/config/v2_2/types"
1210
ign3types "github.com/coreos/ignition/v2/config/v3_5/types"
@@ -103,12 +101,7 @@ func checkV3Unit(unit ign3types.Unit, systemdPath string) error {
103101
return nil
104102
}
105103

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

114107
// checkV3Units validates the contents of all the units in the
@@ -238,24 +231,6 @@ func checkV2Files(files []ign2types.File) error {
238231
return nil
239232
}
240233

241-
// checkUnitEnabled checks whether a systemd unit is enabled as expected.
242-
func checkUnitEnabled(name string, expectedEnabled *bool) error {
243-
if expectedEnabled == nil {
244-
return nil
245-
}
246-
cmd := exec.Command("systemctl", "is-enabled", name)
247-
outBytes, err := cmd.CombinedOutput()
248-
out := strings.TrimSpace(string(outBytes))
249-
250-
// units types considered not enabled (linked, linked-runtime, masked, masked-runtime, disabled, bad)
251-
isEnabled := err == nil
252-
if isEnabled != *expectedEnabled {
253-
return fmt.Errorf("unit %q expected enabled=%t, but systemd reports %q", name, *expectedEnabled, out)
254-
}
255-
256-
return nil
257-
}
258-
259234
// checkFileContentsAndMode reads the file from the filepath and compares its
260235
// contents and mode with the expectedContent and mode parameters. It logs an
261236
// error in case of an error or mismatch and returns the status of the

pkg/daemon/update.go

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1005,7 +1005,7 @@ func (dn *Daemon) update(oldConfig, newConfig *mcfgv1.MachineConfig, skipCertifi
10051005
logSystem("Starting update from %s to %s: %+v", oldConfigName, newConfigName, diff)
10061006

10071007
diffFileSet := ctrlcommon.CalculateConfigFileDiffs(&oldIgnConfig, &newIgnConfig)
1008-
diffUnitSet, addedOrChangedUnits := ctrlcommon.CalculateConfigUnitDiffs(&oldIgnConfig, &newIgnConfig)
1008+
diffUnitSet := ctrlcommon.CalculateConfigUnitDiffs(&oldIgnConfig, &newIgnConfig)
10091009

10101010
var nodeDisruptionActions []opv1.NodeDisruptionPolicyStatusAction
10111011
var actions []string
@@ -1117,13 +1117,13 @@ func (dn *Daemon) update(oldConfig, newConfig *mcfgv1.MachineConfig, skipCertifi
11171117
}
11181118

11191119
// update files on disk that need updating
1120-
if err := dn.updateFiles(oldIgnConfig, newIgnConfig, addedOrChangedUnits, skipCertificateWrite); err != nil {
1120+
if err := dn.updateFiles(oldIgnConfig, newIgnConfig, skipCertificateWrite); err != nil {
11211121
return err
11221122
}
11231123

11241124
defer func() {
11251125
if retErr != nil {
1126-
if err := dn.updateFiles(newIgnConfig, oldIgnConfig, addedOrChangedUnits, skipCertificateWrite); err != nil {
1126+
if err := dn.updateFiles(newIgnConfig, oldIgnConfig, skipCertificateWrite); err != nil {
11271127
errs := kubeErrs.NewAggregate([]error{err, retErr})
11281128
retErr = fmt.Errorf("error rolling back files writes: %w", errs)
11291129
return
@@ -1258,17 +1258,15 @@ func (dn *Daemon) updateHypershift(oldConfig, newConfig *mcfgv1.MachineConfig, d
12581258
return fmt.Errorf("parsing new Ignition config failed: %w", err)
12591259
}
12601260

1261-
_, addedOrChangedUnits := ctrlcommon.CalculateConfigUnitDiffs(&oldIgnConfig, &newIgnConfig)
1262-
12631261
// update files on disk that need updating
12641262
// We should't skip the certificate write in HyperShift since it does not run the extra daemon process
1265-
if err := dn.updateFiles(oldIgnConfig, newIgnConfig, addedOrChangedUnits, false); err != nil {
1263+
if err := dn.updateFiles(oldIgnConfig, newIgnConfig, false); err != nil {
12661264
return err
12671265
}
12681266

12691267
defer func() {
12701268
if retErr != nil {
1271-
if err := dn.updateFiles(newIgnConfig, oldIgnConfig, addedOrChangedUnits, false); err != nil {
1269+
if err := dn.updateFiles(newIgnConfig, oldIgnConfig, false); err != nil {
12721270
errs := kubeErrs.NewAggregate([]error{err, retErr})
12731271
retErr = fmt.Errorf("error rolling back files writes: %w", errs)
12741272
return
@@ -1773,12 +1771,12 @@ func (dn *CoreOSDaemon) switchKernel(oldConfig, newConfig *mcfgv1.MachineConfig)
17731771
// whatever has been written is picked up by the appropriate daemons, if
17741772
// required. in particular, a daemon-reload and restart for any unit files
17751773
// touched.
1776-
func (dn *Daemon) updateFiles(oldIgnConfig, newIgnConfig ign3types.Config, addedOrChangedUnits []ign3types.Unit, skipCertificateWrite bool) error {
1774+
func (dn *Daemon) updateFiles(oldIgnConfig, newIgnConfig ign3types.Config, skipCertificateWrite bool) error {
17771775
klog.Info("Updating files")
17781776
if err := dn.writeFiles(newIgnConfig.Storage.Files, skipCertificateWrite); err != nil {
17791777
return err
17801778
}
1781-
if err := dn.writeUnits(addedOrChangedUnits); err != nil {
1779+
if err := dn.writeUnits(newIgnConfig.Systemd.Units); err != nil {
17821780
return err
17831781
}
17841782
return dn.deleteStaleData(oldIgnConfig, newIgnConfig)

0 commit comments

Comments
 (0)