Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

libvirt: Add podvm instance cpu and mem size support for libvirt #2116

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions src/cloud-providers/libvirt/libvirt.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ const (
GetDomainIPsRetries = 20
// The sleep time between retries to get the domain IP addresses
GetDomainIPsSleep = time.Second * 3
// Default Memory size
LIBVIRT_DEF_MEM_SIZE = uint(8)
// Default CPU size
LIBVIRT_DEF_CPU_SIZE = uint(2)
// Convert Memory size from MegaBytes to GigaBytes
LIBVIRT_CONV_MEM = 1000
)

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

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

v.cpu = uint(2)
v.mem = uint(8)
// Assign the default CPU size and memory when no default memory and
// CPU are provided through annotations
if v.cpu == 0 {
v.cpu = LIBVIRT_DEF_CPU_SIZE
}
if v.mem == 0 {
v.mem = LIBVIRT_DEF_MEM_SIZE
}
v.rootDiskSize = uint64(10)

exists, err := checkDomainExistsByName(v.name, libvirtClient)
Expand Down
7 changes: 5 additions & 2 deletions src/cloud-providers/libvirt/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,12 @@ func (p *libvirtProvider) CreateInstance(ctx context.Context, podName, sandboxID
return nil, err
}

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

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