-
Notifications
You must be signed in to change notification settings - Fork 54
OCPBUGS-43501: coreos-installer iso kargs show broken when using minimal ISO #463
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
…RUB and ISOLINUX config edits Replaced repetitive editFile logic with reusable helper functions: - `replacePatternInFile`: performs regex replacement and returns the updated file content. - `saveFile`: writes content to file with secure permissions (0600). Updated `fixGrubConfig` and `fixIsolinuxConfig` to use these helpers for: - Adding coreos.live.rootfs_url - Removing coreos.liveiso - Modifying initrd lines with optional nmstate ramdisk This improves readability, testability, and maintainability of config mutation logic during ISO generation.
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: pawanpinjarkar The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
…port - Refactored fixIsolinuxConfig to return modified content for reuse. - Added fixKargsConfig to generate and update kargs.jso with correct kernel args and offset. - Introduced utility functions for extracting boot args and rebuilding kargs.jso. - Enhanced test coverage for both isolinux and kargs config logic. - Updated test data to reflect new kernel argument structure
def12db
to
83daebe
Compare
@pawanpinjarkar: This pull request references Jira Issue OCPBUGS-43501, which is invalid:
Comment The bug has been updated to refer to the pull request using the external bug tracker. In response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the openshift-eng/jira-lifecycle-plugin repository. |
/jira refresh |
@pawanpinjarkar: This pull request references Jira Issue OCPBUGS-43501, which is valid. The bug has been moved to the POST state. 3 validation(s) were run on this bug
Requesting review from QA contact: In response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the openshift-eng/jira-lifecycle-plugin repository. |
/cherrypick release-4.19, release-4.18, release-4.17, release-4.16 |
@pawanpinjarkar: once the present PR merges, I will cherry-pick it on top of In response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
@pawanpinjarkar: The following test failed, say
Full PR test history. Your PR dashboard. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a bit strange. Generally I'm not sure why this is happening for only one of the boot configs, I don't know where the original offset numbers are coming from and it seems like there's a lot of unnecessary refactoring going on.
@@ -18,6 +20,16 @@ const ( | |||
MinimalVersionForNmstatectl = "4.18.0-ec.0" | |||
) | |||
|
|||
type FileEntry struct { | |||
Offset int `json:"offset"` | |||
Path string `json:"path"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are "end" and "pad" just not needed? Maybe add them anyway just for completeness?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had them added initially, its fair, I will add it back again
Path string `json:"path"` | ||
} | ||
|
||
type Config struct { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we name this more specifically? This is kargs-specific, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
right, will do
@@ -72,6 +93,7 @@ func createTestFiles(volumeID string) (string, string) { | |||
Expect(os.WriteFile(filepath.Join(filesDir, "images/pxeboot/rootfs.img"), []byte("this is rootfs"), 0600)).To(Succeed()) | |||
Expect(os.WriteFile(filepath.Join(filesDir, "EFI/redhat/grub.cfg"), []byte(testGrubConfig), 0600)).To(Succeed()) | |||
Expect(os.WriteFile(filepath.Join(filesDir, "isolinux/isolinux.cfg"), []byte(testISOLinuxConfig), 0600)).To(Succeed()) | |||
Expect(os.WriteFile(filepath.Join(filesDir, "coreos/kargs.jso"), []byte(testKargsConfig), 0600)).To(Succeed()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Expect(os.WriteFile(filepath.Join(filesDir, "coreos/kargs.jso"), []byte(testKargsConfig), 0600)).To(Succeed()) | |
Expect(os.WriteFile(filepath.Join(filesDir, "coreos/kargs.json"), []byte(testKargsConfig), 0600)).To(Succeed()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The filename extension in reality is limited just to 3 chars hence .jso
if err != nil { | ||
return err | ||
} | ||
offset := 1903 | ||
if includeNmstateRamDisk { | ||
offset = 1923 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where is this number coming from?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The offset was manually calculated during the dev work with the command such as dd if-isolinux.cfg bs=1 skip 1903
when the includeNmstateRamDisk was not included and it was coming to be 1923
when the includeNmstateRamDisk was included.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this the same for every ISO version? I would expect this to vary.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we knew what the grub config file looked like in advance, we could just write the whole file out. We're doing all the replace stuff because we need to be robust against changes in coreos.
I think we need to count the number of characters we're adding/removing and where, then update the offsets/size as appropriate.
log.WithError(err).Warnf("Failed to edit isolinux config") | ||
return err | ||
} | ||
if err := fixKargsConfig(extractDir, contentWithRamDiskPath, includeNmstateRamDisk); err != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why does this only apply for isolinux and not grub?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In isolinux.cfg the offset moves (due to adding the ramdisk images at the beginning of the same line.
In grub.cfg the offset stays the same because the line specifying the initrd images currently appears after the one that specifies the kargs.
if err != nil { | ||
return err | ||
} | ||
if err = saveFile(foundGrubPath, grubFileContent); err != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why save then edit and save again? Couldn't this just be removed?
} | ||
|
||
// saveFile writes the given content to the specified file with 0600 permissions. | ||
func saveFile(fileName, content string) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function doesn't offer any benefit over just calling os.WriteFile
directly. Just deduplicating the permissions hardly seems worth it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've noticed that AIs love to do this kind of stuff.
} | ||
|
||
return nil | ||
} | ||
|
||
func fixIsolinuxConfig(rootFSURL, extractDir string, includeNmstateRamDisk bool) error { | ||
func fixIsolinuxConfig(rootFSURL, extractDir string, includeNmstateRamDisk bool) (string, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of returning the content as a side-effect, could we leave this unchanged then read the file we need after we call the original function?
// Extract the line content after "append " | ||
kernelArgs := strings.TrimPrefix(trimmed, "append ") | ||
// Find " rw " (with spaces to avoid partial matches) | ||
index := strings.Index(kernelArgs, " rw ") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No reason to think that rw will always be the first arg either.
Description
This PR enhances the way kernel arguments (kargs) are handled in RHCOS ISOs by updating both
isolinux.cfg
andcoreos/kargs.jso
files during minimal ISO generation.Key changes:
fixIsolinuxConfig
now returns the modified config content for reuse instead of writing blindly to disk.Added
fixKargsConfig
, which extracts the kernel args starting with rw fromisolinux.cfg
and updates the embeddedcoreos/kargs.jso
JSON file with correct kernel arguments and offset values.Introduced helper functions
extractBootArgs
andbuildKargsContent
to support safe, consistent parsing and rewriting of kernel args.Updated test data to include sample
kargs.jso
.Extended test coverage to validate both
isolinux.cfg
andkargs.jso
updates in cases with and without the nmstate disk image.This improves consistency across bootloaders (isolinux and grub), avoids stale
coreos.liveiso
entries, and ensures correct injection of dynamic rootfs URLs and initrds, especially when including nmstate or other additional initrd images.How was this code tested?
Unit Tests: Added new tests in rhcos_test.go to validate that:
fixIsolinuxConfig
correctly removescoreos.liveiso
, addsrw
, and appends appropriate initrd paths.fixKargsConfig
correctly parses the kernel args fromisolinux.cfg
, modifies thekargs.jso
file with correct offsets, and embeds updated args.Assignees
/cc @
/cc @
Links
Checklist
docs
, README, etc)