Skip to content
This repository has been archived by the owner on Dec 14, 2023. It is now read-only.

Add hugepages support #20

Merged
merged 1 commit into from
Oct 1, 2020
Merged
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
7 changes: 7 additions & 0 deletions pkg/kubevirt/apis/provider_spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package api

import (
corev1 "k8s.io/api/core/v1"
kubevirtv1 "kubevirt.io/client-go/api/v1"
)

// KubeVirtProviderSpec is the spec to be used while parsing the calls.
Expand Down Expand Up @@ -54,6 +55,12 @@ type KubeVirtProviderSpec struct {
// Tags is an optional map of tags that is added to the VM as labels.
// +optional
Tags map[string]string `json:"tags,omitempty"`
// MemoryFeatures allows specifying the VirtualMachineInstance memory features like huge pages and guest memory settings.
// Each feature might require appropriate FeatureGate enabled.
// For hugepages take a look at:
// k8s - https://kubernetes.io/docs/tasks/manage-hugepages/scheduling-hugepages/
// okd - https://docs.okd.io/3.9/scaling_performance/managing_hugepages.html#huge-pages-prerequisites
MemoryFeatures *kubevirtv1.Memory
}

// NetworkSpec contains information about a network.
Expand Down
6 changes: 6 additions & 0 deletions pkg/kubevirt/core/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,12 @@ func (p PluginSPIImpl) CreateMachine(ctx context.Context, machineName string, pr
},
}

if providerSpec.MemoryFeatures != nil && providerSpec.MemoryFeatures.Hugepages != nil {
virtualMachine.Spec.Template.Spec.Domain.Memory = &kubevirtv1.Memory{
Hugepages: providerSpec.MemoryFeatures.Hugepages,
}
}

stoyanr marked this conversation as resolved.
Show resolved Hide resolved
if err := c.Create(ctx, virtualMachine); err != nil {
return "", fmt.Errorf("failed to create VirtualMachine: %v", err)
}
Expand Down
8 changes: 8 additions & 0 deletions pkg/kubevirt/validation/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,14 @@ func ValidateKubevirtProviderSpecAndSecret(spec *api.KubeVirtProviderSpec, secre
}
}

if spec.MemoryFeatures != nil && spec.MemoryFeatures.Hugepages != nil {
_, err := resource.ParseQuantity(spec.MemoryFeatures.Hugepages.PageSize)
if err != nil {
validationErrors = append(validationErrors, fmt.Errorf("invalid value of hugepages size '%v'",
spec.MemoryFeatures.Hugepages.PageSize))
}
}

validationErrors = append(validationErrors, validateSecrets(secrets)...)

return validationErrors
Expand Down