diff --git a/docs/data-sources/virtualmachine.md b/docs/data-sources/virtualmachine.md index b61e34f2..8e269ada 100644 --- a/docs/data-sources/virtualmachine.md +++ b/docs/data-sources/virtualmachine.md @@ -49,6 +49,7 @@ data "harvester_virtualmachine" "opensuse154" { - **message** (String) - **network_interface** (List of Object) (see [below for nested schema](#nestedatt--network_interface)) - **node_name** (String) +- **reserved_memory** (String) - **restart_after_update** (Boolean) restart vm after the vm is updated - **run_strategy** (String) more info: https://kubevirt.io/user-guide/virtual_machines/run_strategies/ - **secure_boot** (Boolean) EFI must be enabled to use this feature diff --git a/docs/resources/virtualmachine.md b/docs/resources/virtualmachine.md index ad117d0f..ca7add09 100644 --- a/docs/resources/virtualmachine.md +++ b/docs/resources/virtualmachine.md @@ -71,9 +71,10 @@ resource "harvester_virtualmachine" "ubuntu20" { efi = true secure_boot = true - run_strategy = "RerunOnFailure" - hostname = "ubuntu20" - machine_type = "q35" + run_strategy = "RerunOnFailure" + hostname = "ubuntu20" + reserved_memory = "100Mi" + machine_type = "q35" network_interface { name = "nic-1" @@ -228,6 +229,7 @@ resource "harvester_virtualmachine" "opensuse154" { - **machine_type** (String) - **memory** (String) - **namespace** (String) +- **reserved_memory** (String) - **restart_after_update** (Boolean) restart vm after the vm is updated - **run_strategy** (String) more info: https://kubevirt.io/user-guide/virtual_machines/run_strategies/ - **secure_boot** (Boolean) EFI must be enabled to use this feature diff --git a/examples/resources/harvester_virtualmachine/resource.tf b/examples/resources/harvester_virtualmachine/resource.tf index 28680fa0..ade26e02 100644 --- a/examples/resources/harvester_virtualmachine/resource.tf +++ b/examples/resources/harvester_virtualmachine/resource.tf @@ -56,9 +56,10 @@ resource "harvester_virtualmachine" "ubuntu20" { efi = true secure_boot = true - run_strategy = "RerunOnFailure" - hostname = "ubuntu20" - machine_type = "q35" + run_strategy = "RerunOnFailure" + hostname = "ubuntu20" + reserved_memory = "100Mi" + machine_type = "q35" network_interface { name = "nic-1" diff --git a/internal/provider/virtualmachine/resource_virtualmachine_constructor.go b/internal/provider/virtualmachine/resource_virtualmachine_constructor.go index 40b061d8..2f089ce5 100644 --- a/internal/provider/virtualmachine/resource_virtualmachine_constructor.go +++ b/internal/provider/virtualmachine/resource_virtualmachine_constructor.go @@ -122,6 +122,21 @@ func (c *Constructor) Setup() util.Processors { return nil }, }, + { + Field: constants.FieldVirtualMachineReservedMemory, + Parser: func(i interface{}) error { + reservedMemory := i.(string) + if reservedMemory != "" { + vmBuilder.Annotations(map[string]string{ + harvesterutil.AnnotationReservedMemory: reservedMemory, + }) + } else { + delete(vmBuilder.VirtualMachine.Annotations, harvesterutil.AnnotationReservedMemory) + } + return nil + }, + Required: true, + }, { Field: constants.FieldVirtualMachineSSHKeys, Parser: func(i interface{}) error { diff --git a/internal/provider/virtualmachine/schema_virtualmachine.go b/internal/provider/virtualmachine/schema_virtualmachine.go index 83561c8b..c0547c35 100644 --- a/internal/provider/virtualmachine/schema_virtualmachine.go +++ b/internal/provider/virtualmachine/schema_virtualmachine.go @@ -23,6 +23,10 @@ func Schema() map[string]*schema.Schema { Optional: true, Computed: true, }, + constants.FieldVirtualMachineReservedMemory: { + Type: schema.TypeString, + Optional: true, + }, constants.FieldVirtualMachineRestartAfterUpdate: { Type: schema.TypeBool, Optional: true, diff --git a/pkg/constants/constants_virtualmachine.go b/pkg/constants/constants_virtualmachine.go index 94155edf..c04475ee 100644 --- a/pkg/constants/constants_virtualmachine.go +++ b/pkg/constants/constants_virtualmachine.go @@ -5,6 +5,7 @@ const ( FieldVirtualMachineMachineType = "machine_type" FieldVirtualMachineHostname = "hostname" + FieldVirtualMachineReservedMemory = "reserved_memory" FieldVirtualMachineRestartAfterUpdate = "restart_after_update" FieldVirtualMachineStart = "start" FieldVirtualMachineRunStrategy = "run_strategy" diff --git a/pkg/importer/resource_virtualmachine_importer.go b/pkg/importer/resource_virtualmachine_importer.go index e4b395bf..86ec1e90 100644 --- a/pkg/importer/resource_virtualmachine_importer.go +++ b/pkg/importer/resource_virtualmachine_importer.go @@ -34,6 +34,10 @@ func (v *VMImporter) HostName() string { return v.VirtualMachine.Spec.Template.Spec.Hostname } +func (v *VMImporter) ReservedMemory() string { + return v.VirtualMachine.Annotations[harvesterutil.AnnotationReservedMemory] +} + func (v *VMImporter) Description() string { return v.VirtualMachine.Annotations[builder.AnnotationKeyDescription] } @@ -336,6 +340,7 @@ func ResourceVirtualMachineStateGetter(vm *kubevirtv1.VirtualMachine, vmi *kubev constants.FieldVirtualMachineCPU: vmImporter.CPU(), constants.FieldVirtualMachineMemory: vmImporter.Memory(), constants.FieldVirtualMachineHostname: vmImporter.HostName(), + constants.FieldVirtualMachineReservedMemory: vmImporter.ReservedMemory(), constants.FieldVirtualMachineMachineType: vmImporter.MachineType(), constants.FieldVirtualMachineRunStrategy: string(runStrategy), constants.FieldVirtualMachineNetworkInterface: networkInterface,