Skip to content

Commit 628f293

Browse files
committed
libvirt: Add podvm instance cpu and mem size support for libvirt
Use io.katacontainers.config.hypervisor.default_vcpus and io.katacontainers.config.hypervisor.default_memory annotations to set the libvirt podvm instance. Use the default values if no annotations are provided. Fixes: confidential-containers#1650 Signed-off-by : savitrilh <[email protected]>
1 parent d3ad603 commit 628f293

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

src/cloud-providers/libvirt/libvirt.go

+14-2
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,12 @@ const (
2727
GetDomainIPsRetries = 20
2828
// The sleep time between retries to get the domain IP addresses
2929
GetDomainIPsSleep = time.Second * 3
30+
// Default Memory size
31+
LIBVIRT_DEF_MEM_SIZE = uint(8)
32+
// Default CPU size
33+
LIBVIRT_DEF_CPU_SIZE = uint(2)
34+
// Convert Memory size from MegaBytes to GigaBytes
35+
LIBVIRT_CONV_MEM = 1000
3036
)
3137

3238
type domainConfig struct {
@@ -529,8 +535,14 @@ func getDomainIPs(dom *libvirt.Domain) ([]netip.Addr, error) {
529535

530536
func CreateDomain(ctx context.Context, libvirtClient *libvirtClient, v *vmConfig) (result *createDomainOutput, err error) {
531537

532-
v.cpu = uint(2)
533-
v.mem = uint(8)
538+
// Assign the default CPU size and memory when no default memory and
539+
// CPU are provided through annotations
540+
if v.cpu == 0 {
541+
v.cpu = LIBVIRT_DEF_CPU_SIZE
542+
}
543+
if v.mem == 0 {
544+
v.mem = LIBVIRT_DEF_MEM_SIZE
545+
}
534546
v.rootDiskSize = uint64(10)
535547

536548
exists, err := checkDomainExistsByName(v.name, libvirtClient)

src/cloud-providers/libvirt/provider.go

+5-2
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,12 @@ func (p *libvirtProvider) CreateInstance(ctx context.Context, podName, sandboxID
5656
return nil, err
5757
}
5858

59-
// TODO: Specify the maximum instance name length in Libvirt
60-
vm := &vmConfig{name: instanceName, userData: userData, firmware: p.serviceConfig.Firmware}
59+
// Convert the memory units in gigabytes
60+
instanceMemory := uint(spec.Memory / LIBVIRT_CONV_MEM)
61+
instanceVCPUs := uint(spec.VCPUs)
6162

63+
// TODO: Specify the maximum instance name length in Libvirt
64+
vm := &vmConfig{name: instanceName, cpu: instanceVCPUs, mem: instanceMemory, userData: userData, firmware: p.serviceConfig.Firmware}
6265
if p.serviceConfig.DisableCVM {
6366
vm.launchSecurityType = NoLaunchSecurity
6467
} else if p.serviceConfig.LaunchSecurity != "" {

0 commit comments

Comments
 (0)