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

Auto fill ippool #15

Merged
merged 1 commit into from
Feb 26, 2024
Merged

Auto fill ippool #15

merged 1 commit into from
Feb 26, 2024

Conversation

starbops
Copy link
Member

@starbops starbops commented Jan 29, 2024

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

Problem:

To successfully create the IPPool object, users must specify the pool range, i.e., the start and end IPs, and the DHCP server's IP. The reason why this is bad when it comes to user experience is that:

  • Most of the time, users just want the whole subnet to be allocatable.
  • Users don't give a dime about what the DHCP server's IP is.

Solution:

Implement a mutator to automatically add the missing fields (serverIP, start, and end). Also, if the serverIP or router is within the range consisting of start and end, mark it as RESERVED and make it not allocatable.

Related Issue:

harvester/harvester#5045

Test plan:

  1. Install harvester-vm-dhcp-controller on the Harvester cluster

    helm upgrade --install harvester-vm-dhcp-controller ./chart --namespace=harvester-system
    
  2. Create Cluster Network (ClusterNetwork), Network Config (VlanConfig), and VM Network (NAD) default/test-net

  3. Create an IPPool object associated with the above-created VM Network

    cat <<EOF | kubectl apply -f -
    apiVersion: network.harvesterhci.io/v1alpha1
    kind: IPPool
    metadata:
      namespace: default
      name: test-net
    spec:
      networkName: default/test-net
      ipv4Config:
        cidr: 192.168.0.0/24
    
  4. Check the IPPool's spec and status section, the following fields should be filled:

    • .spec.ipv4Config.serverIP
    • .spec.ipv4Config.pool.start
    • .spec.ipv4Config.pool.end

    For example:

    apiVersion: network.harvesterhci.io/v1alpha1
    kind: IPPool
    metadata:
      ...
      name: test-net
      namespace: default
    spec:
      ipv4Config:
        cidr: 192.168.0.0/24
        pool:
          end: 192.168.0.254
          start: 192.168.0.1
        serverIP: 192.168.0.1
      networkName: default/test-net
    status:
      agentPodRef:
        name: default-test-net-agent
        namespace: harvester-system
      conditions:
      - lastUpdateTime: "2024-01-29T13:00:23Z"
        status: "True"
        type: Registered
      - lastUpdateTime: "2024-01-29T13:00:23Z"
        status: "True"
        type: CacheReady
      - lastUpdateTime: "2024-01-29T13:00:37Z"
        status: "True"
        type: AgentReady
      - lastUpdateTime: "2024-01-29T13:00:23Z"
        status: "False"
        type: Stopped
      ipv4:
        allocated:
          192.168.0.1: RESERVED
        available: 253
        used: 0
      lastUpdate: "2024-01-29T13:00:23Z"
    

    Note that because the serverIP is within the pool range (from start to end), the IP must be marked as RESERVED under the .status.ipv4.allocated field.

@starbops
Copy link
Member Author

Code conflicts are resolved.

ipPool := newObj.(*networkv1.IPPool)

serverIP := ipPool.Spec.IPv4Config.ServerIP
if err := ensureServerIP(
Copy link
Contributor

Choose a reason for hiding this comment

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

we update serverIP in this method, and currently the method signature makes this hard to ready. we should may be return a *string, and use nil/not nil to identify if it has been updated?

return nil, fmt.Errorf(webhook.CreateErr, "IPPool", ipPool.Namespace, ipPool.Name, err)
}
pool := ipPool.Spec.IPv4Config.Pool
if err := ensurePoolRange(
Copy link
Contributor

Choose a reason for hiding this comment

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

we should change the method signature to make the pool object return more specific

If IPPool object is created without explicitly specified the serverIP,
the start and end IP of the pool, the IPPool mutator will try to assign
IPs to them. Also, if the serverIP or router is within the pool range,
i.e., in between the start and end IPs, those IPs will then be marked
as "RESERVED" (by the controller) and will not be allocatable.

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

@ibrokethecloud I've updated the method signatures to make them more explicit. PTAL, thanks!

Copy link
Contributor

@ibrokethecloud ibrokethecloud 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.

Copy link
Member

@bk201 bk201 left a comment

Choose a reason for hiding this comment

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

lgtm!

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