Skip to content

Commit

Permalink
OSModifier: Add kernel cmdline in EMU API and update extraCommandLine…
Browse files Browse the repository at this point in the history
… to a list (#23)

<!-- Description: Please provide a summary of the changes and the
motivation behind them. -->

cherry-picked from
#19 with
commits signed and comments addressed.


What does the PR accomplish, why was it needed?

Now extraCommandLine format is consistent with trident API (see related
PR in trident:
https://dev.azure.com/mariner-org/ECF/_git/trident/pullrequest/20937).
It also avoids complexity with string parsing.

- update extraCommandLine to a list of strings
- Add kernel cmdline in EMU API

---

### **Checklist**
- [x] Tests added/updated
- [x] Documentation updated (if needed)
- [x] Code conforms to style guidelines
  • Loading branch information
elainezhao96 authored Dec 10, 2024
1 parent 7a69a84 commit 69fdc96
Show file tree
Hide file tree
Showing 20 changed files with 75 additions and 296 deletions.
2 changes: 1 addition & 1 deletion toolkit/tools/imagecustomizer/docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -780,7 +780,7 @@ Optional settings for where and how to mount the filesystem.

Options for configuring the kernel.

### extraCommandLine [string]
### extraCommandLine [string[]]

Additional Linux kernel command line options to add to the image.

Expand Down
6 changes: 4 additions & 2 deletions toolkit/tools/imagecustomizer/docs/iso.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ iso:
cloud-init-data/meta-data: /cloud-init-data/meta-data

kernelCommandLine:
extraCommandLine: "ds=nocloud"
extraCommandLine:
- "ds=nocloud"
```
Note: It is tempting to specify
Expand All @@ -106,7 +107,8 @@ If cloud-init data is to be placed within the LiveOS root file system:
```yaml
os:
kernelCommandLine:
extraCommandLine: "ds=nocloud"
extraCommandLine:
- "ds=nocloud"
additionalFiles:
cloud-init-data/user-data: /var/lib/cloud/seed/nocloud/user-data
Expand Down
5 changes: 4 additions & 1 deletion toolkit/tools/imagecustomizerapi/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -336,8 +336,11 @@ func TestConfigIsValidKernelCLI(t *testing.T) {
OS: &OS{
ResetBootLoaderType: "hard-reset",
Hostname: "test",

KernelCommandLine: KernelCommandLine{
ExtraCommandLine: "console=ttyS0",
ExtraCommandLine: []string{
"console=ttyS0",
},
},
},
}
Expand Down
2 changes: 1 addition & 1 deletion toolkit/tools/imagecustomizerapi/iso_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
func TestIsoIsValid(t *testing.T) {
iso := Iso{
KernelCommandLine: KernelCommandLine{
ExtraCommandLine: "'",
ExtraCommandLine: []string{""},
},
}

Expand Down
16 changes: 10 additions & 6 deletions toolkit/tools/imagecustomizerapi/kernelcommandline.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,20 @@

package imagecustomizerapi

import (
"fmt"
)

type KernelCommandLine struct {
// Extra kernel command line args.
ExtraCommandLine KernelExtraArguments `yaml:"extraCommandLine"`
ExtraCommandLine []string `yaml:"extraCommandLine"`
}

func (s *KernelCommandLine) IsValid() error {
err := s.ExtraCommandLine.IsValid()
if err != nil {
return err
func (k *KernelCommandLine) IsValid() error {
for i, arg := range k.ExtraCommandLine {
if arg == "" {
return fmt.Errorf("kernel argument cannot be empty at index %d", i)
}
}

return nil
}
148 changes: 0 additions & 148 deletions toolkit/tools/imagecustomizerapi/kernelextraarguments.go

This file was deleted.

102 changes: 0 additions & 102 deletions toolkit/tools/imagecustomizerapi/kernelextraarguments_test.go

This file was deleted.

2 changes: 1 addition & 1 deletion toolkit/tools/imagecustomizerapi/os_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ func TestOSIsValidOverlayDuplicateWorkDir(t *testing.T) {
func TestOSIsValidInvalidKernelCommandLine(t *testing.T) {
os := OS{
KernelCommandLine: KernelCommandLine{
ExtraCommandLine: "\"",
ExtraCommandLine: []string{""},
},
}

Expand Down
14 changes: 10 additions & 4 deletions toolkit/tools/osmodifierapi/os.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@ import (

// OS defines how each system present on the image is supposed to be configured.
type OS struct {
Hostname string `yaml:"hostname"`
SELinux imagecustomizerapi.SELinux `yaml:"selinux"`
Users []imagecustomizerapi.User `yaml:"users"`
Overlays *[]Overlay `yaml:"overlays"`
Hostname string `yaml:"hostname"`
SELinux imagecustomizerapi.SELinux `yaml:"selinux"`
Users []imagecustomizerapi.User `yaml:"users"`
Overlays *[]Overlay `yaml:"overlays"`
KernelCommandLine imagecustomizerapi.KernelCommandLine `yaml:"kernelCommandLine"`
}

func (s *OS) IsValid() error {
Expand Down Expand Up @@ -65,5 +66,10 @@ func (s *OS) IsValid() error {
}
}

err = s.KernelCommandLine.IsValid()
if err != nil {
return fmt.Errorf("invalid kernelCommandLine:\n%w", err)
}

return nil
}
Loading

0 comments on commit 69fdc96

Please sign in to comment.