|
| 1 | +# Adding additional volumes to Nodes |
| 2 | + |
| 3 | +[Github Issue](https://github.com/kubernetes-sigs/cluster-api-provider-ibmcloud/issues/1920) |
| 4 | + |
| 5 | +## Summary |
| 6 | +We want the ability to add additional Volumes to our Machine nodes. |
| 7 | + |
| 8 | +## Proposal |
| 9 | +We will need to make changes to both the API and the controller logic. |
| 10 | +With regards to the API, we will need to add a new `AdditionalVolumes` field to the Machine Spec to contain all the different volumes that are added to the node, the field will be a slice of type `VPCVolume`. As an initial design we can keep the field [append-only](https://kubernetes.io/blog/2022/09/29/enforce-immutability-using-cel/#append-only-list-of-containers). |
| 11 | + |
| 12 | +### API Changes |
| 13 | +The Additional Volumes field will be a part of the `IBMVPCMachineSpec` struct and will be defined as follows: |
| 14 | +```go |
| 15 | + // AdditionalVolumes is the list of additional volumes attached to the disk |
| 16 | + // +kubebuilder:validation:Optional |
| 17 | + // +kubebuilder:validation:MaxItems=10 |
| 18 | + // +kubebuilder:validation:XValidation:rule="oldSelf.all(x, x in self)",message="Values may only be added" |
| 19 | + AdditionalVolumes []*VPCVolume `json:"additionalVolumes,omitempty"` |
| 20 | +``` |
| 21 | + |
| 22 | +The `VPCVolume` struct is [already present](https://github.com/kubernetes-sigs/cluster-api-provider-ibmcloud/blob/3bf33db00c0a46dfc2b78861e8519072fa51b441/api/v1beta2/ibmvpcmachine_types.go#L99) in the API spec and is currently being used to describe the boot disks. |
| 23 | + |
| 24 | +A sample IBMVPCMachineSpec instance with AdditionalDisks would look like the following: |
| 25 | +```yaml |
| 26 | +# apiVersion, kind, metadata... |
| 27 | +spec: |
| 28 | + additionalVolumes: |
| 29 | + - deleteVolumeOnInstanceDelete: true |
| 30 | + encryptionKeyCRN: value |
| 31 | + iops: 1 |
| 32 | + name: VolumeName |
| 33 | + profile: "general-purpose" |
| 34 | + sizeGiB: 1 |
| 35 | + - deleteVolumeOnInstanceDelete: true |
| 36 | + encryptionKeyCRN: value |
| 37 | + iops: 1 |
| 38 | + name: SecondVolumeName |
| 39 | + profile: "general-purpose" |
| 40 | + sizeGiB: 1 |
| 41 | + # Other IBMVPCMachine.Spec fields |
| 42 | +``` |
| 43 | + |
| 44 | +### Controller flow |
| 45 | +The flow for creating Additional Volumes will be similar to creating the Boot Volume. |
| 46 | +We will need to add checks in the admission and mutation webhooks to validate any changes to the field like we do for `VPCVolume`. |
| 47 | +We can allow the field be unset initially so if a user wants to add Volumes after provisioning a machine, they will be able to. |
| 48 | + |
| 49 | +The Machine create flow will be as follows: |
| 50 | +If a user does not add Additional Volumes while creating the Machine, the standard create flow will be followed. |
| 51 | +If they add Additional Volumes when creating the Machine, the Machine reconciler will also create the Additional Volumes and attach them to the machine. |
| 52 | + |
| 53 | +The Machine update flow will be as follows: |
| 54 | +The `AdditionalVolumes` field will be append-only so a user will not be able to remove already created volumes. If a user adds more volumes to the slice, those Volumes will be provisioned and then attached to the machine. |
| 55 | + |
| 56 | +The Delete flow will not change much, the Additional Volumes' deletion flow will be similar to the Boot Volume's. |
| 57 | + |
| 58 | +### Limitation |
| 59 | +The biggest limitation of the current approach will be that the `AdditionalVolumes` field will be append-only and therefore there won't be a way to delete any Additional Volumes that are provisioned without deleting the entire machine. |
| 60 | +This limitation can be addressed later by enhancing the controller flow to manage update scenarios where Volumes are removed from the `AdditionalVolumes` slice. This would also require the append-only nature of the `AdditionalVolumes` field to change. |
0 commit comments