k8snetworkplumbingwg/whereabouts

[RFE] Optimistic IP assignment

Opened this issue · 0 comments

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