Skip to content

Support static IP assignment via VM annotations#157

Open
starbops wants to merge 4 commits into
harvester:mainfrom
starbops:feat-5052
Open

Support static IP assignment via VM annotations#157
starbops wants to merge 4 commits into
harvester:mainfrom
starbops:feat-5052

Conversation

@starbops

@starbops starbops commented Jul 6, 2026

Copy link
Copy Markdown
Member

IMPORTANT: Please do not create a Pull Request without creating an issue first.

Problem:
Harvester users need a way to request stable DHCP IP addresses for VM NICs through VM-level configuration. The vm-dhcp-controller already supports static lease behavior through VirtualMachineNetworkConfig.spec.networkConfigs[].ipAddress, but Harvester-created VMs did not have a controller path that populated this field from VM annotations.

Without this, users cannot reliably pin a desired IP per VM interface through the Harvester VM workflow, and changes to a desired IP for an existing MAC are not reconciled cleanly.

Solution:
Add support for static-ip.harvesterhci.io/<nic-name> annotations on VirtualMachine objects.

The VM controller now reads static IP annotations, matches them to VM interface names, validates basic IPv4 syntax, and writes the desired address into the generated VirtualMachineNetworkConfig.

The vmnetcfg controller now treats desired IP changes for an existing MAC as stale allocation state, so the old IP can be released and the new requested IP can be allocated during reconciliation.

The vmnetcfg webhook now validates requested static IPs on create and relevant updates. It rejects invalid requests such as non-IPv4 addresses, IPs outside the subnet or pool range, network or broadcast addresses, excluded/reserved IPs, duplicate desired IPs on the same network, and IPs already allocated to another MAC.

Related Issue:

harvester/harvester#5052

Test plan:

  1. Prepare a Harvester cluster in v1.8.1
  2. Install the vm-dhcp-controller add-on
  3. Configure the vm-dhcp-controller add-on to use the custom-built images
  4. Enable the vm-dhcp-controller add-on
  5. Create a valid VM Network (NAD) and a proper IPPool resource
  6. Create a VM with a static IP annotation
  7. Check the VM has the desired static IP allocated and assigned

starbops added 4 commits July 5, 2026 15:51
Parse static-ip.harvesterhci.io/<nic> annotations after VM NIC configs are resolved and set NetworkConfig.IPAddress for matching IPv4 values.

Sort generated network configs by NIC name to keep vmnetcfg specs deterministic.

Signed-off-by: Zespre Chang <[email protected]>
Mark existing allocations stale when an explicit desired IP changes, while leaving dynamic configs untouched when the annotation is removed.

Keep Allocate from recovering an old status or cache IP when a desired IP is present.

Signed-off-by: Zespre Chang <[email protected]>
Reject desired IPs outside the pool, reserved or excluded addresses, duplicates, and addresses allocated to another MAC.

Validate updates only when desired IP entries are new or changed so unchanged and removed configs do not require NAD/IPPool lookups.

Signed-off-by: Zespre Chang <[email protected]>
Describe annotation format, update and removal semantics, MAC prerequisites, and validation failure surfaces.

Also fix the vmnetcfg example field name to networkConfigs.

Signed-off-by: Zespre Chang <[email protected]>
@starbops starbops changed the title Feat 5052 Support static IP assignment via VM annotations Jul 6, 2026
@starbops
starbops marked this pull request as ready for review July 6, 2026 02:13
@starbops
starbops requested a review from a team July 6, 2026 11:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant