Skip to content

Commit

Permalink
exec/files: sort unit preset in alphabetical order
Browse files Browse the repository at this point in the history
The 20-ignition.preset file is used in CoreOS layering. The contents
of this file will be sorted in alphabetical order by unit name to ensure
the file is written in a consistent order across multiple runs.

Fixes coreos#1339
  • Loading branch information
marmijo committed Jun 2, 2022
1 parent cdb4632 commit f77b5d7
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion internal/exec/stages/files/units.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"context"
"fmt"
"path/filepath"
"sort"
"strings"

"github.com/coreos/ignition/v2/config/shared/errors"
Expand Down Expand Up @@ -151,7 +152,16 @@ func (s *stage) createSystemdPresetFile(presets map[string]*Preset) error {
return err
}
hasInstanceUnit := false
for _, value := range presets {

// sort the units before writing to the systemd presets file
unitNames := make([]string, 0, len(presets))
for unit := range presets {
unitNames = append(unitNames, unit)
}
sort.Strings(unitNames)

for i := range unitNames {
value := presets[unitNames[i]]
unitString := value.unit
if value.instantiatable {
hasInstanceUnit = true
Expand Down

0 comments on commit f77b5d7

Please sign in to comment.