mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-08-18 07:58:36 +00:00
runtime: Remove the version check for cloud hypervisor
It looks like the version check for cloud hypervisor (clh) was added initially when clh was actively evolving its API. We no longer need the version check as clh API has been fairly stable for its recent releases. Fixes: #1991 Signed-off-by: Bo Chen <chen.bo@intel.com>
This commit is contained in:
parent
7d3cf04f29
commit
d08603bebb
@ -63,8 +63,6 @@ const (
|
|||||||
clhSocket = "clh.sock"
|
clhSocket = "clh.sock"
|
||||||
clhAPISocket = "clh-api.sock"
|
clhAPISocket = "clh-api.sock"
|
||||||
virtioFsSocket = "virtiofsd.sock"
|
virtioFsSocket = "virtiofsd.sock"
|
||||||
supportedMajorVersion = 0
|
|
||||||
supportedMinorVersion = 5
|
|
||||||
defaultClhPath = "/usr/local/bin/cloud-hypervisor"
|
defaultClhPath = "/usr/local/bin/cloud-hypervisor"
|
||||||
virtioFsCacheAlways = "always"
|
virtioFsCacheAlways = "always"
|
||||||
)
|
)
|
||||||
@ -95,12 +93,6 @@ type clhClient interface {
|
|||||||
VmRemoveDevicePut(ctx context.Context, vmRemoveDevice chclient.VmRemoveDevice) (*http.Response, error)
|
VmRemoveDevicePut(ctx context.Context, vmRemoveDevice chclient.VmRemoveDevice) (*http.Response, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
type CloudHypervisorVersion struct {
|
|
||||||
Major int
|
|
||||||
Minor int
|
|
||||||
Revision int
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// Cloud hypervisor state
|
// Cloud hypervisor state
|
||||||
//
|
//
|
||||||
@ -123,7 +115,6 @@ type cloudHypervisor struct {
|
|||||||
config HypervisorConfig
|
config HypervisorConfig
|
||||||
ctx context.Context
|
ctx context.Context
|
||||||
APIClient clhClient
|
APIClient clhClient
|
||||||
version CloudHypervisorVersion
|
|
||||||
vmconfig chclient.VmConfig
|
vmconfig chclient.VmConfig
|
||||||
virtiofsd Virtiofsd
|
virtiofsd Virtiofsd
|
||||||
store persistapi.PersistDriver
|
store persistapi.PersistDriver
|
||||||
@ -150,18 +141,6 @@ var clhDebugKernelParams = []Param{
|
|||||||
//
|
//
|
||||||
//###########################################################
|
//###########################################################
|
||||||
|
|
||||||
func (clh *cloudHypervisor) checkVersion() error {
|
|
||||||
if clh.version.Major < supportedMajorVersion || (clh.version.Major == supportedMajorVersion && clh.version.Minor < supportedMinorVersion) {
|
|
||||||
errorMessage := fmt.Sprintf("Unsupported version: cloud-hypervisor %d.%d not supported by this driver version (%d.%d)",
|
|
||||||
clh.version.Major,
|
|
||||||
clh.version.Minor,
|
|
||||||
supportedMajorVersion,
|
|
||||||
supportedMinorVersion)
|
|
||||||
return errors.New(errorMessage)
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// For cloudHypervisor this call only sets the internal structure up.
|
// For cloudHypervisor this call only sets the internal structure up.
|
||||||
// The VM will be created and started through startSandbox().
|
// The VM will be created and started through startSandbox().
|
||||||
func (clh *cloudHypervisor) createSandbox(ctx context.Context, id string, networkNS NetworkNamespace, hypervisorConfig *HypervisorConfig) error {
|
func (clh *cloudHypervisor) createSandbox(ctx context.Context, id string, networkNS NetworkNamespace, hypervisorConfig *HypervisorConfig) error {
|
||||||
@ -180,23 +159,6 @@ func (clh *cloudHypervisor) createSandbox(ctx context.Context, id string, networ
|
|||||||
clh.config = *hypervisorConfig
|
clh.config = *hypervisorConfig
|
||||||
clh.state.state = clhNotReady
|
clh.state.state = clhNotReady
|
||||||
|
|
||||||
// version check only applicable to 'cloud-hypervisor' executable
|
|
||||||
clhPath, perr := clh.clhPath()
|
|
||||||
if perr != nil {
|
|
||||||
return perr
|
|
||||||
|
|
||||||
}
|
|
||||||
if strings.HasSuffix(clhPath, "cloud-hypervisor") {
|
|
||||||
err = clh.getAvailableVersion()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := clh.checkVersion(); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
clh.Logger().WithField("function", "createSandbox").Info("creating Sandbox")
|
clh.Logger().WithField("function", "createSandbox").Info("creating Sandbox")
|
||||||
|
|
||||||
virtiofsdSocketPath, err := clh.virtioFsSocketPath(clh.id)
|
virtiofsdSocketPath, err := clh.virtioFsSocketPath(clh.id)
|
||||||
@ -880,59 +842,6 @@ func (clh *cloudHypervisor) clhPath() (string, error) {
|
|||||||
return p, nil
|
return p, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (clh *cloudHypervisor) getAvailableVersion() error {
|
|
||||||
|
|
||||||
clhPath, err := clh.clhPath()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
cmd := exec.Command(clhPath, "--version")
|
|
||||||
out, err := cmd.CombinedOutput()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
words := strings.Fields(string(out))
|
|
||||||
if len(words) != 2 {
|
|
||||||
return errors.New("Failed to parse cloud-hypervisor version response. Illegal length")
|
|
||||||
}
|
|
||||||
versionSplit := strings.SplitN(words[1], ".", -1)
|
|
||||||
if len(versionSplit) != 3 {
|
|
||||||
return errors.New("Failed to parse cloud-hypervisor version field. Illegal length")
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// Remove 'v' prefix if has one
|
|
||||||
versionSplit[0] = strings.TrimLeft(versionSplit[0], "v")
|
|
||||||
major, err := strconv.ParseUint(versionSplit[0], 10, 64)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
minor, err := strconv.ParseUint(versionSplit[1], 10, 64)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
// revision could have aditional commit information separated by '-'
|
|
||||||
revisionSplit := strings.SplitN(versionSplit[2], "-", -1)
|
|
||||||
if len(revisionSplit) < 1 {
|
|
||||||
return errors.Errorf("Failed parse cloud-hypervisor revision %s", versionSplit[2])
|
|
||||||
}
|
|
||||||
revision, err := strconv.ParseUint(revisionSplit[0], 10, 64)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
clh.version = CloudHypervisorVersion{
|
|
||||||
Major: int(major),
|
|
||||||
Minor: int(minor),
|
|
||||||
Revision: int(revision),
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
func (clh *cloudHypervisor) launchClh() (int, error) {
|
func (clh *cloudHypervisor) launchClh() (int, error) {
|
||||||
|
|
||||||
clhPath, err := clh.clhPath()
|
clhPath, err := clh.clhPath()
|
||||||
|
@ -7,7 +7,6 @@ package virtcontainers
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
@ -324,50 +323,6 @@ func TestCloudHypervisorResizeMemory(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestCheckVersion(t *testing.T) {
|
|
||||||
clh := &cloudHypervisor{}
|
|
||||||
assert := assert.New(t)
|
|
||||||
testcases := []struct {
|
|
||||||
name string
|
|
||||||
major int
|
|
||||||
minor int
|
|
||||||
pass bool
|
|
||||||
}{
|
|
||||||
{
|
|
||||||
name: "minor lower than supported version",
|
|
||||||
major: supportedMajorVersion,
|
|
||||||
minor: 2,
|
|
||||||
pass: false,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "minor equal to supported version",
|
|
||||||
major: supportedMajorVersion,
|
|
||||||
minor: supportedMinorVersion,
|
|
||||||
pass: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "major exceeding supported version",
|
|
||||||
major: 1,
|
|
||||||
minor: supportedMinorVersion,
|
|
||||||
pass: true,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
for _, tc := range testcases {
|
|
||||||
clh.version = CloudHypervisorVersion{
|
|
||||||
Major: tc.major,
|
|
||||||
Minor: tc.minor,
|
|
||||||
Revision: 0,
|
|
||||||
}
|
|
||||||
err := clh.checkVersion()
|
|
||||||
msg := fmt.Sprintf("test: %+v, clh.version: %v, result: %v", tc, clh.version, err)
|
|
||||||
if tc.pass {
|
|
||||||
assert.NoError(err, msg)
|
|
||||||
} else {
|
|
||||||
assert.Error(err, msg)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestCloudHypervisorHotplugAddBlockDevice(t *testing.T) {
|
func TestCloudHypervisorHotplugAddBlockDevice(t *testing.T) {
|
||||||
assert := assert.New(t)
|
assert := assert.New(t)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user