mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-09-19 15:58:25 +00:00
Merge pull request #9657 from ajaypvictor/remote-hyp-annotations
runtime: Disable number of cpu comparison on remote hypervisor scenario
This commit is contained in:
@@ -608,7 +608,7 @@ func addHypervisorHotColdPlugVfioOverrides(ocispec specs.Spec, sbConfig *vc.Sand
|
|||||||
func addHypervisorMemoryOverrides(ocispec specs.Spec, sbConfig *vc.SandboxConfig, runtime RuntimeConfig) error {
|
func addHypervisorMemoryOverrides(ocispec specs.Spec, sbConfig *vc.SandboxConfig, runtime RuntimeConfig) error {
|
||||||
|
|
||||||
if err := newAnnotationConfiguration(ocispec, vcAnnotations.DefaultMemory).setUintWithCheck(func(memorySz uint64) error {
|
if err := newAnnotationConfiguration(ocispec, vcAnnotations.DefaultMemory).setUintWithCheck(func(memorySz uint64) error {
|
||||||
if memorySz < vc.MinHypervisorMemory {
|
if memorySz < vc.MinHypervisorMemory && sbConfig.HypervisorType != vc.RemoteHypervisor {
|
||||||
return fmt.Errorf("Memory specified in annotation %s is less than minimum required %d, please specify a larger value", vcAnnotations.DefaultMemory, vc.MinHypervisorMemory)
|
return fmt.Errorf("Memory specified in annotation %s is less than minimum required %d, please specify a larger value", vcAnnotations.DefaultMemory, vc.MinHypervisorMemory)
|
||||||
}
|
}
|
||||||
sbConfig.HypervisorConfig.MemorySize = uint32(memorySz)
|
sbConfig.HypervisorConfig.MemorySize = uint32(memorySz)
|
||||||
@@ -689,7 +689,7 @@ func addHypervisorCPUOverrides(ocispec specs.Spec, sbConfig *vc.SandboxConfig) e
|
|||||||
numCPUs := goruntime.NumCPU()
|
numCPUs := goruntime.NumCPU()
|
||||||
|
|
||||||
if err := newAnnotationConfiguration(ocispec, vcAnnotations.DefaultVCPUs).setFloat32WithCheck(func(vcpus float32) error {
|
if err := newAnnotationConfiguration(ocispec, vcAnnotations.DefaultVCPUs).setFloat32WithCheck(func(vcpus float32) error {
|
||||||
if vcpus > float32(numCPUs) {
|
if vcpus > float32(numCPUs) && sbConfig.HypervisorType != vc.RemoteHypervisor {
|
||||||
return fmt.Errorf("Number of cpus %f specified in annotation default_vcpus is greater than the number of CPUs %d on the system", vcpus, numCPUs)
|
return fmt.Errorf("Number of cpus %f specified in annotation default_vcpus is greater than the number of CPUs %d on the system", vcpus, numCPUs)
|
||||||
}
|
}
|
||||||
sbConfig.HypervisorConfig.NumVCPUsF = float32(vcpus)
|
sbConfig.HypervisorConfig.NumVCPUsF = float32(vcpus)
|
||||||
@@ -701,11 +701,11 @@ func addHypervisorCPUOverrides(ocispec specs.Spec, sbConfig *vc.SandboxConfig) e
|
|||||||
return newAnnotationConfiguration(ocispec, vcAnnotations.DefaultMaxVCPUs).setUintWithCheck(func(maxVCPUs uint64) error {
|
return newAnnotationConfiguration(ocispec, vcAnnotations.DefaultMaxVCPUs).setUintWithCheck(func(maxVCPUs uint64) error {
|
||||||
max := uint32(maxVCPUs)
|
max := uint32(maxVCPUs)
|
||||||
|
|
||||||
if max > uint32(numCPUs) {
|
if max > uint32(numCPUs) && sbConfig.HypervisorType != vc.RemoteHypervisor {
|
||||||
return fmt.Errorf("Number of cpus %d in annotation default_maxvcpus is greater than the number of CPUs %d on the system", max, numCPUs)
|
return fmt.Errorf("Number of cpus %d in annotation default_maxvcpus is greater than the number of CPUs %d on the system", max, numCPUs)
|
||||||
}
|
}
|
||||||
|
|
||||||
if sbConfig.HypervisorType == vc.QemuHypervisor && max > govmm.MaxVCPUs() {
|
if sbConfig.HypervisorType == vc.QemuHypervisor && max > govmm.MaxVCPUs() && sbConfig.HypervisorType != vc.RemoteHypervisor {
|
||||||
return fmt.Errorf("Number of cpus %d in annotation default_maxvcpus is greater than max no of CPUs %d supported for qemu", max, govmm.MaxVCPUs())
|
return fmt.Errorf("Number of cpus %d in annotation default_maxvcpus is greater than max no of CPUs %d supported for qemu", max, govmm.MaxVCPUs())
|
||||||
}
|
}
|
||||||
sbConfig.HypervisorConfig.DefaultMaxVCPUs = max
|
sbConfig.HypervisorConfig.DefaultMaxVCPUs = max
|
||||||
|
@@ -726,6 +726,51 @@ func TestAddHypervisorAnnotations(t *testing.T) {
|
|||||||
assert.Error(err)
|
assert.Error(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestAddRemoteHypervisorAnnotations(t *testing.T) {
|
||||||
|
// Remote hypervisor uses DefaultVCPUs, DefaultMemory etc as annotations to pick the size of the separate VM to create,
|
||||||
|
// so doesn't need to be bound by the host's capacity limits.
|
||||||
|
assert := assert.New(t)
|
||||||
|
|
||||||
|
config := vc.SandboxConfig{
|
||||||
|
Annotations: make(map[string]string),
|
||||||
|
}
|
||||||
|
|
||||||
|
sbConfig := vc.SandboxConfig{
|
||||||
|
Annotations: make(map[string]string),
|
||||||
|
HypervisorType: vc.RemoteHypervisor,
|
||||||
|
}
|
||||||
|
|
||||||
|
ocispec := specs.Spec{
|
||||||
|
Annotations: make(map[string]string),
|
||||||
|
}
|
||||||
|
|
||||||
|
runtimeConfig := RuntimeConfig{
|
||||||
|
HypervisorType: vc.RemoteHypervisor,
|
||||||
|
}
|
||||||
|
|
||||||
|
err := addAnnotations(ocispec, &config, runtimeConfig)
|
||||||
|
assert.NoError(err)
|
||||||
|
assert.Exactly(vc.HypervisorConfig{}, config.HypervisorConfig)
|
||||||
|
|
||||||
|
// Enable annotations
|
||||||
|
runtimeConfig.HypervisorConfig.EnableAnnotations = []string{".*"}
|
||||||
|
|
||||||
|
// When DefaultVCPUs is more than the number of cpus on the host, remote hypervisor annotations don't throw an error
|
||||||
|
ocispec.Annotations[vcAnnotations.DefaultVCPUs] = "2000"
|
||||||
|
err = addAnnotations(ocispec, &sbConfig, runtimeConfig)
|
||||||
|
assert.NoError(err)
|
||||||
|
|
||||||
|
// When DefaultMaxVCPUs is more than the number of cpus on the host, remote hypervisor annotations don't throw an error
|
||||||
|
ocispec.Annotations[vcAnnotations.DefaultMaxVCPUs] = "2000"
|
||||||
|
err = addAnnotations(ocispec, &sbConfig, runtimeConfig)
|
||||||
|
assert.NoError(err)
|
||||||
|
|
||||||
|
// When memory is smaller than the minimum Hypervisor memory, remote hypervisor annotations don't throw an error
|
||||||
|
ocispec.Annotations[vcAnnotations.DefaultMemory] = "1"
|
||||||
|
err = addAnnotations(ocispec, &sbConfig, runtimeConfig)
|
||||||
|
assert.NoError(err)
|
||||||
|
}
|
||||||
|
|
||||||
func TestAddProtectedHypervisorAnnotations(t *testing.T) {
|
func TestAddProtectedHypervisorAnnotations(t *testing.T) {
|
||||||
assert := assert.New(t)
|
assert := assert.New(t)
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user