Skip to content

Commit

Permalink
split kargs so rpm-ostree can handle removing them
Browse files Browse the repository at this point in the history
  • Loading branch information
jkyros committed Jul 22, 2023
1 parent eadee47 commit 016227a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
25 changes: 19 additions & 6 deletions pkg/daemon/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -2042,20 +2042,20 @@ func (dn *Daemon) updateIgnitionKernelArguments(oldConfig, newConfig *mcfgv1.Mac
// See https://bugzilla.redhat.com/show_bug.cgi?id=1866546#c10.

// Remove the old ignition kargs if there are any
for _, arg := range oldIgnConfig.KernelArguments.ShouldExist {
cmdArgs = append(cmdArgs, "--delete-if-present", string(arg))
for _, arg := range stringifyKargs(oldIgnConfig.KernelArguments.ShouldExist) {
cmdArgs = append(cmdArgs, "--delete-if-present", arg)
}
// Remove the old machineconfig kargs if there are any
for _, arg := range oldConfig.Spec.KernelArguments {
cmdArgs = append(cmdArgs, "--delete-if-present", arg)
}
// And now that we support "should not exist", we need to remove those too
for _, arg := range oldIgnConfig.KernelArguments.ShouldNotExist {
cmdArgs = append(cmdArgs, "--delete-if-present", string(arg))
for _, arg := range stringifyKargs(oldIgnConfig.KernelArguments.ShouldNotExist) {
cmdArgs = append(cmdArgs, "--delete-if-present", arg)
}
// And then after we've removed them all, we insert the ones that should be there
for _, arg := range newIgnConfig.KernelArguments.ShouldExist {
cmdArgs = append(cmdArgs, "--append-if-missing", string(arg))
for _, arg := range stringifyKargs(newIgnConfig.KernelArguments.ShouldExist) {
cmdArgs = append(cmdArgs, "--append-if-missing", arg)
}

if len(cmdArgs) == 0 {
Expand All @@ -2067,3 +2067,16 @@ func (dn *Daemon) updateIgnitionKernelArguments(oldConfig, newConfig *mcfgv1.Mac
return runRpmOstree(args...)

}

// stringifyKargs converts typed ignition kargs to strings so we can use
// our existing parsing routines on them. This wouldn't be necessary if
// rpm-ostree could deal with combined kargs directly like ignition does,
// but it doesn't seem to be able to. So something like "foo=bar baz=ferzle"
// will be unable to removed unless we split it into "foo=bar" and "baz=ferzle"
func stringifyKargs(kargs []ign3types.KernelArgument) []string {
var convertedArgs []string
for _, karg := range kargs {
convertedArgs = append(convertedArgs, string(karg))
}
return parseKernelArguments(convertedArgs)
}
2 changes: 2 additions & 0 deletions test/e2e-single-node/sno_mcd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ func TestKernelArguments(t *testing.T) {
assert.Equal(t, node.Annotations[constants.MachineConfigDaemonStateAnnotationKey], constants.MachineConfigDaemonStateDone)
kargs := helpers.ExecCmdOnNode(t, cs, node, "cat", "/rootfs/proc/cmdline")
expectedKernelArgs := []string{"foo=bar", "foo=baz", "baz=test", "bar=hello world"}
t.Logf("Detected kargs: %s", kargs)
for _, v := range expectedKernelArgs {
if !strings.Contains(kargs, v) {
t.Fatalf("Missing %q in kargs: %q", v, kargs)
Expand All @@ -106,6 +107,7 @@ func TestKernelArguments(t *testing.T) {
assert.Equal(t, node.Annotations[constants.CurrentMachineConfigAnnotationKey], oldMasterRenderedConfig)
assert.Equal(t, node.Annotations[constants.MachineConfigDaemonStateAnnotationKey], constants.MachineConfigDaemonStateDone)
kargs = helpers.ExecCmdOnNode(t, cs, node, "cat", "/rootfs/proc/cmdline")
t.Logf("Detected kargs: %s", kargs)

for _, v := range expectedKernelArgs {
if strings.Contains(kargs, v) {
Expand Down

0 comments on commit 016227a

Please sign in to comment.