Skip to content

Commit

Permalink
Merge pull request #3053 from mkenigs/refactor-updateKernelArguments
Browse files Browse the repository at this point in the history
updateKernelArgs: pass kargs instead of MCs
  • Loading branch information
openshift-merge-robot authored Mar 31, 2022
2 parents 0ab40fc + c113a34 commit 9b886c7
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 15 deletions.
12 changes: 6 additions & 6 deletions pkg/daemon/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ func (dn *CoreOSDaemon) applyOSChanges(mcDiff machineConfigDiff, oldConfig, newC

// Apply kargs
if mcDiff.kargs {
if err := dn.updateKernelArguments(oldConfig, newConfig); err != nil {
if err := dn.updateKernelArguments(oldConfig.Spec.KernelArguments, newConfig.Spec.KernelArguments); err != nil {
return err
}
}
Expand Down Expand Up @@ -933,9 +933,9 @@ func parseKernelArguments(kargs []string) []string {
// Note what we really should be doing though is also looking at the *current*
// kernel arguments in case there was drift. But doing that requires us knowing
// what the "base" arguments are. See https://github.com/ostreedev/ostree/issues/479
func generateKargs(oldConfig, newConfig *mcfgv1.MachineConfig) []string {
oldKargs := parseKernelArguments(oldConfig.Spec.KernelArguments)
newKargs := parseKernelArguments(newConfig.Spec.KernelArguments)
func generateKargs(oldKernelArguments, newKernelArguments []string) []string {
oldKargs := parseKernelArguments(oldKernelArguments)
newKargs := parseKernelArguments(newKernelArguments)
cmdArgs := []string{}

// To keep kernel argument processing simpler and bug free, we first delete all
Expand All @@ -952,8 +952,8 @@ func generateKargs(oldConfig, newConfig *mcfgv1.MachineConfig) []string {
}

// updateKernelArguments adjusts the kernel args
func (dn *CoreOSDaemon) updateKernelArguments(oldConfig, newConfig *mcfgv1.MachineConfig) error {
kargs := generateKargs(oldConfig, newConfig)
func (dn *CoreOSDaemon) updateKernelArguments(oldKernelArguments, newKernelArguments []string) error {
kargs := generateKargs(oldKernelArguments, newKernelArguments)
if len(kargs) == 0 {
return nil
}
Expand Down
10 changes: 1 addition & 9 deletions pkg/daemon/update_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -313,15 +313,7 @@ func TestKernelAguments(t *testing.T) {
rand.Seed(time.Now().UnixNano())
for idx, test := range tests {
t.Run(fmt.Sprintf("case#%d", idx), func(t *testing.T) {
oldIgnCfg := ctrlcommon.NewIgnConfig()
oldMcfg := helpers.CreateMachineConfigFromIgnition(oldIgnCfg)
oldMcfg.Spec.KernelArguments = test.oldKargs

newIgnCfg := ctrlcommon.NewIgnConfig()
newMcfg := helpers.CreateMachineConfigFromIgnition(newIgnCfg)
newMcfg.Spec.KernelArguments = test.newKargs

res := generateKargs(oldMcfg, newMcfg)
res := generateKargs(test.oldKargs, test.newKargs)

if !reflect.DeepEqual(test.out, res) {
t.Errorf("Failed kernel arguments processing: expected: %v but result is: %v", test.out, res)
Expand Down

0 comments on commit 9b886c7

Please sign in to comment.