mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-06-27 15:57:09 +00:00
qemu: refector createPod()
To fix CI complains:
virtcontainers/qemu.go:248:⚠️ cyclomatic complexity 18 of
function (*qemu).createPod() is high (> 15) (gocyclo)
Signed-off-by: Peng Tao <bergwolf@gmail.com>
This commit is contained in:
parent
8c5fb45f99
commit
423e86405e
@ -244,13 +244,10 @@ func (q *qemu) qmpSocketPath(socketName string) (string, error) {
|
|||||||
return path, nil
|
return path, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// createPod is the Hypervisor pod creation implementation for govmmQemu.
|
func (q *qemu) getQemuMachine(podConfig PodConfig) (govmmQemu.Machine, error) {
|
||||||
func (q *qemu) createPod(podConfig PodConfig) error {
|
|
||||||
var devices []govmmQemu.Device
|
|
||||||
|
|
||||||
machine, err := q.arch.machine()
|
machine, err := q.arch.machine()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return govmmQemu.Machine{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
accelerators := podConfig.HypervisorConfig.MachineAccelerators
|
accelerators := podConfig.HypervisorConfig.MachineAccelerators
|
||||||
@ -261,6 +258,34 @@ func (q *qemu) createPod(podConfig PodConfig) error {
|
|||||||
machine.Options += accelerators
|
machine.Options += accelerators
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return machine, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (q *qemu) appendImage(devices []govmmQemu.Device) ([]govmmQemu.Device, error) {
|
||||||
|
imagePath, err := q.config.ImageAssetPath()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if imagePath != "" {
|
||||||
|
devices, err = q.arch.appendImage(devices, imagePath)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return devices, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// createPod is the Hypervisor pod creation implementation for govmmQemu.
|
||||||
|
func (q *qemu) createPod(podConfig PodConfig) error {
|
||||||
|
var devices []govmmQemu.Device
|
||||||
|
|
||||||
|
machine, err := q.getQemuMachine(podConfig)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
smp := q.cpuTopology()
|
smp := q.cpuTopology()
|
||||||
|
|
||||||
memory, err := q.memoryTopology(podConfig)
|
memory, err := q.memoryTopology(podConfig)
|
||||||
@ -343,17 +368,10 @@ func (q *qemu) createPod(podConfig PodConfig) error {
|
|||||||
devices = q.arch.appendConsole(devices, q.getPodConsole(podConfig.ID))
|
devices = q.arch.appendConsole(devices, q.getPodConsole(podConfig.ID))
|
||||||
|
|
||||||
if initrdPath == "" {
|
if initrdPath == "" {
|
||||||
imagePath, err := q.config.ImageAssetPath()
|
devices, err = q.appendImage(devices)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if imagePath != "" {
|
|
||||||
devices, err = q.arch.appendImage(devices, imagePath)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if q.config.BlockDeviceDriver == VirtioBlock {
|
if q.config.BlockDeviceDriver == VirtioBlock {
|
||||||
|
Loading…
Reference in New Issue
Block a user