Skip to content

Commit

Permalink
neonvm: Add ability to append to kernel command line (#625)
Browse files Browse the repository at this point in the history
  • Loading branch information
problame authored Nov 16, 2023
1 parent 9c06125 commit f149f2b
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 3 deletions.
3 changes: 3 additions & 0 deletions neonvm/apis/neonvm/v1/virtualmachine_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,9 @@ type Guest struct {
// +optional
KernelImage *string `json:"kernelImage,omitempty"`

// +optional
AppendKernelCmdline *string `json:"appendKernelCmdline,omitempty"`

// +optional
CPUs CPUs `json:"cpus"`
// +optional
Expand Down
5 changes: 5 additions & 0 deletions neonvm/apis/neonvm/v1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions neonvm/controllers/virtualmachine_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -1165,6 +1165,10 @@ func podSpec(virtualmachine *vmv1.VirtualMachine) (*corev1.Pod, error) {
})
}

if virtualmachine.Spec.Guest.AppendKernelCmdline != nil {
pod.Spec.Containers[0].Args = append(pod.Spec.Containers[0].Args, fmt.Sprintf("-appendKernelCmdline=%s", *virtualmachine.Spec.Guest.AppendKernelCmdline))
}

// Add any InitContainers that were specified by the spec
pod.Spec.InitContainers = append(pod.Spec.InitContainers, virtualmachine.Spec.ExtraInitContainers...)

Expand Down
13 changes: 10 additions & 3 deletions neonvm/runner/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ const (
QEMU_BIN = "qemu-system-x86_64"
QEMU_IMG_BIN = "qemu-img"
defaultKernelPath = "/vm/kernel/vmlinuz"
kernelCmdline = "panic=-1 init=/neonvm/bin/init memhp_default_state=online_movable console=ttyS1 loglevel=7 root=/dev/vda rw"
baseKernelCmdline = "panic=-1 init=/neonvm/bin/init memhp_default_state=online_movable console=ttyS1 loglevel=7 root=/dev/vda rw"

rootDiskPath = "/vm/images/rootdisk.qcow2"
runtimeDiskPath = "/vm/images/runtime.iso"
Expand Down Expand Up @@ -469,9 +469,11 @@ func main() {
var vmSpecDump string
var vmStatusDump string
var kernelPath string
var appendKernelCmdline string
flag.StringVar(&vmSpecDump, "vmspec", vmSpecDump, "Base64 encoded VirtualMachine json specification")
flag.StringVar(&vmStatusDump, "vmstatus", vmStatusDump, "Base64 encoded VirtualMachine json status")
flag.StringVar(&kernelPath, "kernelpath", defaultKernelPath, "Override path for kernel to use")
flag.StringVar(&appendKernelCmdline, "appendKernelCmdline", "", "Additional kernel command line arguments")
flag.Parse()

selfPodName, ok := os.LookupEnv("K8S_POD_NAME")
Expand Down Expand Up @@ -625,11 +627,16 @@ func main() {

// kernel details
qemuCmd = append(qemuCmd, "-kernel", kernelPath)
var effectiveKernelCmdline string
if vmSpec.ExtraNetwork != nil && vmSpec.ExtraNetwork.Enable {
qemuCmd = append(qemuCmd, "-append", fmt.Sprintf("ip=%s:::%s:%s:eth1:off %s", vmStatus.ExtraNetIP, vmStatus.ExtraNetMask, vmStatus.PodName, kernelCmdline))
effectiveKernelCmdline = fmt.Sprintf("ip=%s:::%s:%s:eth1:off %s", vmStatus.ExtraNetIP, vmStatus.ExtraNetMask, vmStatus.PodName, baseKernelCmdline)
} else {
qemuCmd = append(qemuCmd, "-append", kernelCmdline)
effectiveKernelCmdline = baseKernelCmdline
}
if appendKernelCmdline != "" {
effectiveKernelCmdline = fmt.Sprintf("%s %s", effectiveKernelCmdline, appendKernelCmdline)
}
qemuCmd = append(qemuCmd, "-append", effectiveKernelCmdline)

// should runner receive migration ?
if os.Getenv("RECEIVE_MIGRATION") == "true" {
Expand Down

0 comments on commit f149f2b

Please sign in to comment.