From 3d0949d60df0ad6e4fb24a5e21ae73cc89aa358b Mon Sep 17 00:00:00 2001 From: Julio Montes Date: Fri, 20 Sep 2019 13:43:24 +0000 Subject: [PATCH] virtcontainers: check minimum supported version of firecracker Check minimum supported version of firecracker to make sure it's compatible with kata containers Signed-off-by: Julio Montes --- virtcontainers/fc.go | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/virtcontainers/fc.go b/virtcontainers/fc.go index 83c100c468..332c038cc6 100644 --- a/virtcontainers/fc.go +++ b/virtcontainers/fc.go @@ -30,7 +30,9 @@ import ( "github.com/pkg/errors" "github.com/sirupsen/logrus" + "github.com/blang/semver" "github.com/kata-containers/runtime/virtcontainers/device/config" + fcmodels "github.com/kata-containers/runtime/virtcontainers/pkg/firecracker/client/models" "github.com/kata-containers/runtime/virtcontainers/store" "github.com/kata-containers/runtime/virtcontainers/types" "github.com/kata-containers/runtime/virtcontainers/utils" @@ -66,6 +68,9 @@ const ( defaultGuestVSockCID = int64(0x3) ) +// Specify the minimum version of firecracker supported +var fcMinSupportedVersion = semver.MustParse("0.18.0") + var fcKernelParams = append(commonVirtioblkKernelRootParams, []Param{ // The boot source is the first partition of the first block device added {"pci", "off"}, @@ -296,6 +301,23 @@ func (fc *firecracker) vmRunning() bool { } } +func (fc *firecracker) checkVersion(vmmInfo *fcmodels.InstanceInfo) error { + if vmmInfo == nil || vmmInfo.VmmVersion == nil { + return fmt.Errorf("Unknown firecracker version") + } + + v, err := semver.Make(*vmmInfo.VmmVersion) + if err != nil { + return fmt.Errorf("Malformed firecracker version: %v", err) + } + + if v.LT(fcMinSupportedVersion) { + return fmt.Errorf("version %v is not supported. Minimum supported version of firecracker is %v", v.String(), fcMinSupportedVersion.String()) + } + + return nil +} + // waitVMM will wait for timeout seconds for the VMM to be up and running. // This does not mean that the VM is up and running. It only indicates that the VMM is up and // running and able to handle commands to setup and launch a VM @@ -309,8 +331,11 @@ func (fc *firecracker) waitVMM(timeout int) error { timeStart := time.Now() for { - _, err := fc.client().Operations.DescribeInstance(nil) + vmmInfo, err := fc.client().Operations.DescribeInstance(nil) if err == nil { + if err := fc.checkVersion(vmmInfo.Payload); err != nil { + return err + } return nil }