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

Commit

Permalink
Merge pull request #20 from mfranczy/add-hugepages-support
Browse files Browse the repository at this point in the history
Add hugepages support
  • Loading branch information
stoyanr authored Oct 1, 2020
2 parents fd91bed + 4e25514 commit 628efd4
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
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,
}
}

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

0 comments on commit 628efd4

Please sign in to comment.