|
| 1 | +# IP reuse |
| 2 | + |
| 3 | +## What is IP reuse |
| 4 | + |
| 5 | +As a developer or user there could be a need to make IPAddresses that will be attached to the Kubernetes nodes in the chain of: **BareMetalHost <=> Metal3Machine <=> CAPI Machine <=> Node** objects predictable, for example during the upgrade process and the main goal of this feature is to make that possible. |
| 6 | + |
| 7 | +## Logic behind |
| 8 | + |
| 9 | +As is now, IPPool is an object representing a set of IPAddress pools to be used for IPAddress allocations. An IPClaim is an object representing a request for an IPAddress allocation. Consequently, the IPClaim object name is structured as following: |
| 10 | + |
| 11 | +**IPClaimName** = **Metal3DataName** + **(-)** + **IPPoolName** |
| 12 | + |
| 13 | +Example: metal3datatemplate-0-pool0 |
| 14 | + |
| 15 | +The `Metal3DataName` is derived from the `Metal3DataTemplateName` with an added index (`Metal3DataTemplateName-index`), and the `IPPoolName` comes from the IPPool object directly. (See the [IP Address manager repo](https://github.com/metal3-io/ip-address-manager) for more details on these objects). |
| 16 | +In the CAPM3 workflow, when a Metal3Machine is created and a Metal3Data object is requested, the |
| 17 | +process of choosing an `index` to be appended to the name of the `Metal3DataTemplateName`, is random. |
| 18 | +For example, let's imagine we have two Metal3Machines: `metal3machine-0` and `metal3machine-1` |
| 19 | +which creates the following `metal3datatemplate-0` and `metal3datatemplate-1` Metal3Data objects respectively. However, if two nodes are being upgraded at a time, there is no guarantee that same indices will be appended to the respective objects and in fact it can be in completely reverse order (i.e. `metal3machine-0` will get `m3datatemplate-1` and `metal3machine-1` will get `m3datatemplate-0`). |
| 20 | +In order to make it predictable, we structure IPClaim object name using the BareMetalHost name, as following: |
| 21 | + |
| 22 | +**IPClaimName** = **BareMetalHostName** + **(-)** + **IPPoolName** |
| 23 | + |
| 24 | +Example: node-0-pool0 |
| 25 | + |
| 26 | +Now, the first part consists of `BareMetalHostName` which is the name of the BareMetalHost object, and should always stay the same once created (predictable). The second part of it is kept unchanged. |
| 27 | + |
| 28 | +## What is the use of PreAllocations field |
| 29 | + |
| 30 | +Once we have a predictable `IPClaimName`, we can make use of a |
| 31 | +`PreAllocations map[string]IPAddressStr` field in the IPPool object to achieve our goal. |
| 32 | + |
| 33 | +We simply add the claim name(s) using the new format (BareMetalHost name included) to the `preAllocations` field in the `IPPool`, i.e: |
| 34 | + |
| 35 | +```yaml |
| 36 | +apiVersion: ipam.metal3.io/v1alpha1 |
| 37 | +kind: IPPool |
| 38 | +metadata: |
| 39 | + name: baremetalv4-pool |
| 40 | + namespace: metal3 |
| 41 | +spec: |
| 42 | + clusterName: test1 |
| 43 | + gateway: 192.168.111.1 |
| 44 | + namePrefix: test1-bmv4 |
| 45 | + pools: |
| 46 | + - end: 192.168.111.200 |
| 47 | + start: 192.168.111.100 |
| 48 | + prefix: 24 |
| 49 | + preAllocations: |
| 50 | + node-0-pool0 : 192.168.111.101 |
| 51 | + node-1-pool0: 192.168.111.102 |
| 52 | +status: |
| 53 | + indexes: |
| 54 | + node-0-pool0 : 192.168.111.101 |
| 55 | + node-1-pool0: 192.168.111.102 |
| 56 | +``` |
| 57 | +
|
| 58 | +Since claim names include BareMetalHost names on them, we are able to predict an IPAddress assigned to the specific node. |
| 59 | +
|
| 60 | +## How to enable IP reuse |
| 61 | +
|
| 62 | +To enable the feature, a boolean flag called `enableBMHNameBasedPreallocation` was added. It is configurable via clusterctl and it can be passed to the clusterctl configuration file by the user, i.e: |
| 63 | + |
| 64 | +```yaml |
| 65 | +
|
| 66 | +enableBMHNameBasedPreallocation: true |
| 67 | +
|
| 68 | +``` |
0 commit comments