firecracker: Add support for default VM configuration

Kata support specifing the default VM configuration via
configuration.toml. This allows the system or cluster admin
to choose the default (i.e minimum) size of the VM.

Add support in kata to respect the VM configuration for firecracker.

Also refactor some code to make error handling uniform.

Fixes: #1594

Signed-off-by: Manohar Castelino <manohar.r.castelino@intel.com>
This commit is contained in:
Manohar Castelino 2019-05-02 01:19:24 +00:00
parent 437b3cb2f7
commit b496f3f71d

View File

@ -281,13 +281,9 @@ func (fc *firecracker) fcSetBootSource(path, params string) error {
bootSrcParams.SetBody(src)
_, err := fc.client().Operations.PutGuestBootSource(bootSrcParams)
if err != nil {
return err
}
return nil
}
func (fc *firecracker) fcSetVMRootfs(path string) error {
span, _ := fc.trace("fcSetVMRootfs")
defer span.Finish()
@ -308,11 +304,25 @@ func (fc *firecracker) fcSetVMRootfs(path string) error {
}
driveParams.SetBody(drive)
_, err := fc.client().Operations.PutGuestDriveByID(driveParams)
if err != nil {
return err
}
return nil
func (fc *firecracker) fcSetVMBaseConfig(mem int64, vcpus int64, htEnabled bool) error {
span, _ := fc.trace("fcSetVMBaseConfig")
defer span.Finish()
fc.Logger().WithFields(logrus.Fields{"mem": mem,
"vcpus": vcpus,
"htEnabled": htEnabled}).Debug("fcSetVMBaseConfig")
param := ops.NewPutMachineConfigurationParams()
cfg := &models.MachineConfiguration{
HtEnabled: htEnabled,
MemSizeMib: mem,
VcpuCount: vcpus,
}
param.SetBody(cfg)
_, err := fc.client().Operations.PutMachineConfiguration(param)
return err
}
func (fc *firecracker) fcStartVM() error {
@ -351,6 +361,12 @@ func (fc *firecracker) startSandbox(timeout int) error {
return err
}
if err := fc.fcSetVMBaseConfig(int64(fc.config.MemorySize),
int64(fc.config.NumVCPUs),
false); err != nil {
return err
}
kernelPath, err := fc.config.KernelAssetPath()
if err != nil {
return err
@ -528,13 +544,9 @@ func (fc *firecracker) fcAddNetDevice(endpoint Endpoint) error {
cfg.SetBody(ifaceCfg)
cfg.SetIfaceID(ifaceID)
_, err := fc.client().Operations.PutGuestNetworkInterfaceByID(cfg)
if err != nil {
return err
}
return nil
}
func (fc *firecracker) fcAddBlockDrive(drive config.BlockDrive) error {
span, _ := fc.trace("fcAddBlockDrive")
defer span.Finish()
@ -552,13 +564,9 @@ func (fc *firecracker) fcAddBlockDrive(drive config.BlockDrive) error {
}
driveParams.SetBody(driveFc)
_, err := fc.client().Operations.PutGuestDriveByID(driveParams)
if err != nil {
return err
}
return nil
}
// Firecracker supports replacing the host drive used once the VM has booted up
func (fc *firecracker) fcUpdateBlockDrive(drive config.BlockDrive) error {
span, _ := fc.trace("fcUpdateBlockDrive")