Skip to content

Commit d96af1e

Browse files
sebastian-delbajolet-hashicorp
authored andcommitted
Add support for KVM memory ballooning
1 parent 58b90ab commit d96af1e

File tree

8 files changed

+35
-4
lines changed

8 files changed

+35
-4
lines changed

builder/proxmox/clone/config.hcl2spec.go

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

builder/proxmox/common/config.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ type Config struct {
5050

5151
Boot string `mapstructure:"boot"`
5252
Memory int `mapstructure:"memory"`
53+
BalloonMinimum int `mapstructure:"ballooning_minimum"`
5354
Cores int `mapstructure:"cores"`
5455
CPUType string `mapstructure:"cpu_type"`
5556
Sockets int `mapstructure:"sockets"`
@@ -187,6 +188,9 @@ func (c *Config) Prepare(upper interface{}, raws ...interface{}) ([]string, []st
187188
log.Printf("Memory %d is too small, using default: 512", c.Memory)
188189
c.Memory = 512
189190
}
191+
if c.Memory < c.BalloonMinimum {
192+
errs = packersdk.MultiErrorAppend(errs, fmt.Errorf("ballooning_minimum (%d) must be lower than memory (%d)", c.BalloonMinimum, c.Memory))
193+
}
190194
if c.Cores < 1 {
191195
log.Printf("Number of cores %d is too small, using default: 1", c.Cores)
192196
c.Cores = 1

builder/proxmox/common/config.hcl2spec.go

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

builder/proxmox/common/step_start_vm.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,13 @@ func (s *stepStartVM) Run(ctx context.Context, state multistep.StateBag) multist
131131
Onboot: &c.Onboot,
132132
}
133133

134+
// 0 disables the ballooning device, which is useful for all VMs
135+
// and should be kept enabled by default.
136+
// See https://github.com/hashicorp/packer-plugin-proxmox/issues/127#issuecomment-1464030102
137+
if c.BalloonMinimum > 0 {
138+
config.Balloon = c.BalloonMinimum
139+
}
140+
134141
if c.PackerForce {
135142
ui.Say("Force set, checking for existing artifact on PVE cluster")
136143
vmRef, err := getExistingTemplate(c, client)

builder/proxmox/iso/config.hcl2spec.go

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs-partials/builder/proxmox/common/Config-not-required.mdx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626

2727
- `memory` (int) - Memory
2828

29+
- `ballooning_minimum` (int) - Balloon Minimum
30+
2931
- `cores` (int) - Cores
3032

3133
- `cpu_type` (string) - CPU Type

docs/builders/clone.mdx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,14 @@ in the image's Cloud-Init settings for provisioning.
9191
and are limited to the range 100-999999999.
9292
If not given, the next free ID on the cluster will be used.
9393

94-
- `memory` (int) - How much memory, in megabytes, to give the virtual
95-
machine. Defaults to `512`.
94+
- `memory` (int) - How much memory (in megabytes) to give the virtual
95+
machine. If `ballooning_minimum` is also set, `memory` defines the maximum amount
96+
of memory the VM will be able to use.
97+
Defaults to `512`.
98+
99+
- `ballooning_minimum` (int) - Setting this option enables KVM memory ballooning and
100+
defines the minimum amount of memory (in megabytes) the VM will have.
101+
Defaults to `0` (memory ballooning disabled).
96102

97103
- `cores` (int) - How many CPU cores to give the virtual machine. Defaults
98104
to `1`.

docs/builders/iso.mdx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,14 @@ in the image's Cloud-Init settings for provisioning.
102102
and are limited to the range 100-999999999.
103103
If not given, the next free ID on the cluster will be used.
104104

105-
- `memory` (int) - How much memory, in megabytes, to give the virtual
106-
machine. Defaults to `512`.
105+
- `memory` (int) - How much memory (in megabytes) to give the virtual
106+
machine. If `ballooning_minimum` is also set, `memory` defines the maximum amount
107+
of memory the VM will be able to use.
108+
Defaults to `512`.
109+
110+
- `ballooning_minimum` (int) - Setting this option enables KVM memory ballooning and
111+
defines the minimum amount of memory (in megabytes) the VM will have.
112+
Defaults to `0` (memory ballooning disabled).
107113

108114
- `cores` (int) - How many CPU cores to give the virtual machine. Defaults
109115
to `1`.

0 commit comments

Comments
 (0)