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

fix: handle server-ip-within-range case correctly #28

Merged
merged 1 commit into from
Mar 11, 2024

Conversation

starbops
Copy link
Member

@starbops starbops commented Mar 8, 2024

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

Problem:

Given an IPPool object with the following YAML:

apiVersion: network.harvesterhci.io/v1alpha1
kind: IPPool
metadata:
  namespace: default
  name: test-net
spec:
  ipv4Config:
    cidr: 192.168.30.0/24
  networkName: default/test-net

The mutator will fill the missing .spec.ipv4Config.serverIP field, and since there's no router specified, the serverIP will be 192.168.30.1 by default. However, that IP address is within the allocatable range (as the mutator-filled .spec.ipv4Config.pool.start and .spec.ipv4Config.pool.end fields will be 192.168.30.1 and 192.168.30.254, respectively.) In the previous version, though the server IP address will be marked as RESERVED under the .status.ipv4.allocated field, it wasn't handled adequately by the webhook and controller:

  • The validating admission webhook treats the RESERVED IP address the same way as allocated IP addresses. It will fail when validating any further updating requests because it thinks the server IP address is already occupied.
  • The cache-building control loop does not skip the RESERVED IP addresses. They should be skipped just like how we did to the excluded IPs.

Solution:

If the server IP is within the allocatable pool range, it will be marked as "RESERVED" and honored by the webhook and controller's cache-builder reconciliation loop.

  • Splitting the allocated, excluded, and reserved IP address lists
  • The validating webhook only checks if the server IP address falls into the allocated and excluded IP address lists
  • The cache-building control loop skips to allocate reserved IP addresses

Related Issue:

harvester/harvester#5225

Test plan:

  1. Install and enable the harvester-vm-dhcp-controller add-on
    apiVersion: harvesterhci.io/v1beta1
    kind: Addon
    metadata:
      labels:
        addon.harvesterhci.io/experimental: "true"
      namespace: harvester-system
      name: harvester-vm-dhcp-controller
    spec:
      chart: harvester-vm-dhcp-controller
      enabled: true
      repo: https://charts.harvesterhci.io
      valuesContent: |
        image:
          repository: starbops/harvester-vm-dhcp-controller
          tag: fix-5225-head
        agent:
          image:
            repository: starbops/harvester-vm-dhcp-agent
            tag: fix-5225-head
        webhook:
          image:
            repository: starbops/harvester-vm-dhcp-webhook
            tag: fix-5225-head
      version: 0.3.0
  2. Prepare a VM Network (NAD) named test-net
  3. Create a minimal IPPool object associated to the VM Network
    apiVersion: network.harvesterhci.io/v1alpha1
    kind: IPPool
    metadata:
      namespace: default
      name: test-net
    spec:
      ipv4Config:
        cidr: 192.168.30.0/24
      networkName: default/test-net
  4. Check the auto assigned DHCP server IP address. It should be recorded in .spec.ipv4Config.serverIP and marked as RESERVED under .status.ipv4.allocated
  5. Create a new VM and attach to the test-net VM Network
  6. A new IP address should be allocated for the VM and recorded under .status.ipv4.allocated field
  7. Delete the VM
  8. Delete the IPPool object
  9. Check if the agent Pod harvester-system/default-test-net-agent is gone

If the server IP is within the allocatable pool range, it will be marked
as "RESERVED" and honored by the webhook and controller's cache-builder
reconciliation loop.

Signed-off-by: Zespre Chang <[email protected]>
Copy link
Member

@w13915984028 w13915984028 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks.

@starbops starbops merged commit 7e9159d into harvester:main Mar 11, 2024
5 checks passed
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.

3 participants