Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reflect NICs defined in the VirtualMachine resource to the corresponding VirtualMachineNetworkConfig resource #43

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

starbops
Copy link
Member

@starbops starbops commented Feb 11, 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.

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 <[email protected]>
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