Skip to content
This repository was archived by the owner on May 12, 2021. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
132 changes: 122 additions & 10 deletions pkg/katautils/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ var (
// The currently supported types are listed below:
const (
// supported hypervisor component types
qemuHypervisorTableType = "qemu"
firecrackerHypervisorTableType = "firecracker"
qemuHypervisorTableType = "qemu"

// supported proxy component types
ccProxyTableType = "cc"
Expand Down Expand Up @@ -322,6 +323,26 @@ func (h hypervisor) guestHookPath() string {
return h.GuestHookPath
}

func (h hypervisor) getInitrdAndImage() (initrd string, image string, err error) {
if initrd, err = h.initrd(); err != nil {
return
}

if image, err = h.image(); err != nil {
return
}

if image != "" && initrd != "" {
return "", "", errors.New("having both an image and an initrd defined in the configuration file is not supported")
}

if image == "" && initrd == "" {
return "", "", errors.New("either image or initrd must be defined in the configuration file")
}

return
}

func (p proxy) path() string {
if p.Path == "" {
return defaultProxyPath
Expand Down Expand Up @@ -368,7 +389,7 @@ func (n netmon) debug() bool {
return n.Debug
}

func newQemuHypervisorConfig(h hypervisor) (vc.HypervisorConfig, error) {
func newFirecrackerHypervisorConfig(h hypervisor) (vc.HypervisorConfig, error) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Adding the firecracker function above the existing one make reviewing this change harder ;(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I did it alphabetical order. noted.

hypervisor, err := h.path()
if err != nil {
return vc.HypervisorConfig{}, err
Expand All @@ -379,12 +400,64 @@ func newQemuHypervisorConfig(h hypervisor) (vc.HypervisorConfig, error) {
return vc.HypervisorConfig{}, err
}

initrd, err := h.initrd()
initrd, image, err := h.getInitrdAndImage()
if err != nil {
return vc.HypervisorConfig{}, err
}

image, err := h.image()
firmware, err := h.firmware()
if err != nil {
return vc.HypervisorConfig{}, err
}

kernelParams := h.kernelParams()

blockDriver, err := h.blockDeviceDriver()
if err != nil {
return vc.HypervisorConfig{}, err
}

if !utils.SupportsVsocks() {
return vc.HypervisorConfig{}, errors.New("No vsock support, firecracker cannot be used")
}

return vc.HypervisorConfig{
HypervisorPath: hypervisor,
KernelPath: kernel,
InitrdPath: initrd,
ImagePath: image,
FirmwarePath: firmware,
KernelParams: vc.DeserializeParams(strings.Fields(kernelParams)),
NumVCPUs: h.defaultVCPUs(),
DefaultMaxVCPUs: h.defaultMaxVCPUs(),
MemorySize: h.defaultMemSz(),
MemSlots: h.defaultMemSlots(),
EntropySource: h.GetEntropySource(),
DefaultBridges: h.defaultBridges(),
DisableBlockDeviceUse: h.DisableBlockDeviceUse,
HugePages: h.HugePages,
Mlock: !h.Swap,
Debug: h.Debug,
DisableNestingChecks: h.DisableNestingChecks,
BlockDeviceDriver: blockDriver,
EnableIOThreads: h.EnableIOThreads,
UseVSock: true,
GuestHookPath: h.guestHookPath(),
}, nil
}

func newQemuHypervisorConfig(h hypervisor) (vc.HypervisorConfig, error) {
hypervisor, err := h.path()
if err != nil {
return vc.HypervisorConfig{}, err
}

kernel, err := h.kernel()
if err != nil {
return vc.HypervisorConfig{}, err
}

initrd, image, err := h.getInitrdAndImage()
if err != nil {
return vc.HypervisorConfig{}, err
}
Expand Down Expand Up @@ -474,19 +547,30 @@ func newShimConfig(s shim) (vc.ShimConfig, error) {
}, nil
}

func updateRuntimeConfig(configPath string, tomlConf tomlConfig, config *oci.RuntimeConfig) error {
func updateRuntimeConfigHypervisor(configPath string, tomlConf tomlConfig, config *oci.RuntimeConfig) error {
for k, hypervisor := range tomlConf.Hypervisor {
var err error
var hConfig vc.HypervisorConfig

switch k {
case firecrackerHypervisorTableType:
config.HypervisorType = vc.FirecrackerHypervisor
hConfig, err = newFirecrackerHypervisorConfig(hypervisor)
case qemuHypervisorTableType:
hConfig, err := newQemuHypervisorConfig(hypervisor)
if err != nil {
return fmt.Errorf("%v: %v", configPath, err)
}
config.HypervisorType = vc.QemuHypervisor
hConfig, err = newQemuHypervisorConfig(hypervisor)
}

config.HypervisorConfig = hConfig
if err != nil {
return fmt.Errorf("%v: %v", configPath, err)
}
config.HypervisorConfig = hConfig
}

return nil
}

func updateRuntimeConfigProxy(configPath string, tomlConf tomlConfig, config *oci.RuntimeConfig) error {
for k, proxy := range tomlConf.Proxy {
switch k {
case ccProxyTableType:
Expand All @@ -501,6 +585,10 @@ func updateRuntimeConfig(configPath string, tomlConf tomlConfig, config *oci.Run
}
}

return nil
}

func updateRuntimeConfigAgent(configPath string, tomlConf tomlConfig, config *oci.RuntimeConfig) error {
for k := range tomlConf.Agent {
switch k {
case hyperstartAgentTableType:
Expand All @@ -515,6 +603,10 @@ func updateRuntimeConfig(configPath string, tomlConf tomlConfig, config *oci.Run
}
}

return nil
}

func updateRuntimeConfigShim(configPath string, tomlConf tomlConfig, config *oci.RuntimeConfig) error {
for k, shim := range tomlConf.Shim {
switch k {
case ccShimTableType:
Expand All @@ -531,6 +623,26 @@ func updateRuntimeConfig(configPath string, tomlConf tomlConfig, config *oci.Run
config.ShimConfig = shConfig
}

return nil
}

func updateRuntimeConfig(configPath string, tomlConf tomlConfig, config *oci.RuntimeConfig) error {
if err := updateRuntimeConfigHypervisor(configPath, tomlConf, config); err != nil {
return err
}

if err := updateRuntimeConfigProxy(configPath, tomlConf, config); err != nil {
return err
}

if err := updateRuntimeConfigAgent(configPath, tomlConf, config); err != nil {
return err
}

if err := updateRuntimeConfigShim(configPath, tomlConf, config); err != nil {
return err
}

fConfig, err := newFactoryConfig(tomlConf.Factory)
if err != nil {
return fmt.Errorf("%v: %v", configPath, err)
Expand Down