diff --git a/pkg/kubevirt/apis/provider_spec.go b/pkg/kubevirt/apis/provider_spec.go index d7802ed..ce6b2b8 100644 --- a/pkg/kubevirt/apis/provider_spec.go +++ b/pkg/kubevirt/apis/provider_spec.go @@ -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. @@ -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. diff --git a/pkg/kubevirt/core/core.go b/pkg/kubevirt/core/core.go index 56a0549..8688a56 100644 --- a/pkg/kubevirt/core/core.go +++ b/pkg/kubevirt/core/core.go @@ -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, + } + } + if err := c.Create(ctx, virtualMachine); err != nil { return "", fmt.Errorf("failed to create VirtualMachine: %v", err) } diff --git a/pkg/kubevirt/validation/validation.go b/pkg/kubevirt/validation/validation.go index ae094d7..25c8927 100644 --- a/pkg/kubevirt/validation/validation.go +++ b/pkg/kubevirt/validation/validation.go @@ -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