Skip to content

Reflect NICs defined in the VirtualMachine resource to the corresponding VirtualMachineNetworkConfig resource (backport #43)#47

Merged
starbops merged 5 commits intov1.5from
mergify/bp/v1.5/pr-43
Feb 24, 2025
Merged

Reflect NICs defined in the VirtualMachine resource to the corresponding VirtualMachineNetworkConfig resource (backport #43)#47
starbops merged 5 commits intov1.5from
mergify/bp/v1.5/pr-43

Conversation

@mergify
Copy link
Copy Markdown

@mergify mergify bot commented Feb 24, 2025

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

Problem:

The Managed DHCP add-on cannot catch any changes in the virtual machine's MAC address updates. The only way to let the add-on serve IP addresses for the updated MAC addresses is to remove the corresponding VirtualMachineNetworkConfig resource and the controller will automatically create a new one with updated MAC addresses.

Solution:

Introduce a new condition in VirtualMachineNetworkConfig—InSynced—which represents the synchronization between the VirtualMachine and VirtualMachineNetworkConfig resources, especially for the MAC addresses. The vm-controller will flag the condition and reflect the MAC addresses to the vmnetcfg resource. The vmnetcfg-controller will catch the changes, try to remove any stale records, and then update the IPPool resource. After that, InSynced will become True. This unblocks the regular allocation procedure, so the new MAC addresses (if any) will get new IP addresses from the IPPool resource.

Related Issue:

harvester/harvester#7046

Test plan:

  1. Prepare a Harvester cluster of version v1.4.1
  2. Install the harvester-vm-dhcp-controller chart (this PR includes CRD changes and will later update to the harvester/charts repo)
git clone https://github.com/starbops/harvester-vm-dhcp-controller.git -b enh-7046
cd harvester-vm-dhcp-controller
cat <<EOF | tee -a values.yaml
image:
  repository: starbops/harvester-vm-dhcp-controller
  tag: enh-7046-head
agent:
  image:
    repository: starbops/harvester-vm-dhcp-agent
    tag: enh-7046-head
webhook:
  image:
    repository: starbops/harvester-vm-dhcp-webhook
    tag: enh-7046-head
EOF
helm upgrade --install harvester-vm-dhcp-controller ./chart \
--namespace=harvester-system \
--create-namespace \
-f values.yaml
  1. Create two virtual machine networks (NADs)
  2. Create two IPPools for the two networks
  3. Create a virtual machine attaching to the first network
  4. Log in to the virtual machine and check the IP address. It should match the record in VirtualMachineNetworkConfig (vmnetcfg) and the first IPPool. Jot down the IP address for later comparison.
  5. Update the virtual machine; Create a new NIC and attach it to the second network. Restart the virtual machine.
  6. Observe the vmnetcfg; it should reflect the new MAC address, and a new IP address should be acquired from the second pool. Also, check the second IPPool, which should have the same updates. However, the first IP/MAC address should remain the same.
  7. Log in to the virtual machine and check the IP addresses. They should match the records in vmnetcfg and the IPPools. Jot down the IP address for later comparison.
  8. Update the second NIC's MAC address of the virtual machine. Restart the virtual machine.
  9. Observe the vmnetcfg; it should reflect the updated MAC address, and a new IP address might be acquired from the pool (depends on the remaining IP addresses available in the pool). Also, check the IPPool, which should have the same updates. It might obtain the same IP address as before; it could happen, and it's totally normal. Keep an eye on the first IP IP/MAC address, they should remain the same as before.
  10. Log in to the virtual machine and check if the IP addresses match the record in vmnetcfg and the IPPools.
  11. Remove the first NIC of the virtual machine and reboot the virtual machine.
  12. Observe the vmnetcfg; it should contain only the second IP/MAC address. Also, check the first IPPool, the IP address should be given back to the pool.
  13. Log in to the virtual machine and check if the IP address matches the record in vmnetcfg and the IPPool.
    This is an automatic backport of pull request Reflect NICs defined in the VirtualMachine resource to the corresponding VirtualMachineNetworkConfig resource #43 done by Mergify.

Signed-off-by: Zespre Chang <zespre.chang@suse.com>
(cherry picked from commit 0e8e17c)
Signed-off-by: Zespre Chang <zespre.chang@suse.com>
(cherry picked from commit 356595b)
vm-controller will reflect the MAC addresses on the corresponding
vmnetcfg resources. vmnetcfg-controller will sync the status with the
spec, remove the stale records, update the ippool resources, and then
allocate new IP addresses for the new MAC addresses.

Signed-off-by: Zespre Chang <zespre.chang@suse.com>
(cherry picked from commit d6a5209)
Signed-off-by: Zespre Chang <zespre.chang@suse.com>
(cherry picked from commit 4369dc8)
Signed-off-by: Zespre Chang <zespre.chang@suse.com>
(cherry picked from commit 0efc388)
@starbops starbops merged commit a57a498 into v1.5 Feb 24, 2025
4 checks passed
@starbops starbops deleted the mergify/bp/v1.5/pr-43 branch June 23, 2025 07:12
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