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

[RFE] Optimistic IP assignment #510

Open
zeeke opened this issue Oct 11, 2024 · 0 comments
Open

[RFE] Optimistic IP assignment #510

zeeke opened this issue Oct 11, 2024 · 0 comments
Assignees
Labels
enhancement New feature or request

Comments

@zeeke
Copy link
Member

zeeke commented Oct 11, 2024

Is your feature request related to a problem? Please describe.
Improving the locking system of the plugin, in order to get better performances.

Describe the solution you'd like
Instead of acquiring a lease on a shared object, each plugin instance could calculate a free IP address in advance and
then try to acuire a lease around it. This can be viewed as a sort of "optimistic IPAM".

Describe alternatives you've considered
The already implemented "Preallocated Node Slices" mechanism is an alternative, but it requires more components and moving part. This proposal only involves the CNI plugin itself.

Additional context
Following diagrams describes the differences between the actual approach (no preallocated slices) and the proposed one.

Regular whereabouts IP assignment

sequenceDiagram
    activate PodA
    PodA->>+Lease/whereabouts: acquire
    rect rgb(191, 223, 255)
        PodA->>IPPool: Get
        PodA->>+PodA: findIP 192.168.1.1
        PodA->>IPPool: Update +192.168.1.1
        Lease/whereabouts-->>-PodA: release
        deactivate PodA
    end
    
    activate PodB
    PodB->>+Lease/whereabouts: acquire
    rect rgb(191, 223, 255)
        PodB->>IPPool: Get
        PodB->>+PodB: findIP 192.168.1.2
        PodB->>IPPool: Update +192.168.1.2
        Lease/whereabouts-->>-PodB: release
        deactivate PodB
    end
Loading

Optimistic IP assignment

sequenceDiagram

    participant PodA
    participant Lease/whereabouts_192.168.1.1
    participant IPPool
    participant Lease/whereabouts_192.168.1.2
    participant PodB

    activate PodA
    PodA->>+PodA: findIP 192.168.1.1
    PodA->>+Lease/whereabouts_192.168.1.1: acquire

    activate PodB
    PodB->>+PodB: findIP 192.168.1.1
    PodB--xLease/whereabouts_192.168.1.1: acquire / timeout

    PodB->>+PodB: findIP 192.168.1.2
    PodB->>+Lease/whereabouts_192.168.1.2: acquire


    rect rgb(191, 223, 255)
        PodA->>IPPool: Get
        PodB->>IPPool: Get
        PodA->>IPPool: Update +192.168.1.1
        PodB->>IPPool: Update +192.168.1.2
        Lease/whereabouts_192.168.1.1-->>-PodA: release
        Lease/whereabouts_192.168.1.2-->>-PodB: release
        deactivate PodA
        deactivate PodB
    end
Loading

The optimistic IP assignment, especially if adding a randomness in the address selection, should avoid having multiple CNI instances asking to lock the same Lease.

This flow diagram describes the main step of the approach:

flowchart TD
    A["ipPool := k8s.IPPools().Get()"] -->B
    B["ip := findAssignableIP(ipPool)"] --> C
    C{"lease := k8s.Acquire('whereabouts_' + ip.String())"}
    C -->|lease OK| E
    C -->|"lease Timeout (~1s)"| F
    E["k8s.Patch of ipPool.Allocations[ip.String()] = podRef"]
    F["another whereabouts instance is assigning the same IP"] --> A
Loading

Feedback on this proposal is very welcome

@zeeke zeeke added the enhancement New feature or request label Oct 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants