|
| 1 | +# Summary |
| 2 | + |
| 3 | +This document discusses the csi-addons API that allows replication of volume groups to a secondary cluster. |
| 4 | + |
| 5 | +## Terminologies |
| 6 | + |
| 7 | +For the sake of simplicity, we will be using some abbreviations in the document which are as follows: |
| 8 | + |
| 9 | +- DR - Disaster Recovery |
| 10 | +- K8s - Kubernetes |
| 11 | +- PVC - Persistent Volume Claim |
| 12 | +- PV - Persistent Volume |
| 13 | +- Primary - The cluster where the application workloads are actively running add data is written to. It initiates the replication to the secondary cluster. |
| 14 | +- Secondary - The cluster that receives replicated data from the primary cluster. |
| 15 | +- SC - Storage Class |
| 16 | +- VGR - VolumeGroupReplication |
| 17 | +- VGRC - VolumeGroupReplicationClass |
| 18 | +- VR - VolumeReplication |
| 19 | +- VRC - VolumeReplicationClass |
| 20 | + |
| 21 | +## Motivation |
| 22 | + |
| 23 | +Most of the storage vendors provide a mechanism to replicate data to other nodes, clusters, peers. But, there are no K8s APIs that provide replication of a group of volumes at real time. We have K8s VolumeGroupSnapshot APIs provided but that again involves adding another application to take backup and restore it on the secondary cluster. |
| 24 | +Therefore, there was a need to have K8s APIs that represents group of volumes and replicate the group of volumes at real time to provide support for Disaster Recovery (DR). |
| 25 | + |
| 26 | +## Goal |
| 27 | + |
| 28 | +- Provide APIs to support replication of a group of volumes. |
| 29 | + |
| 30 | +## Design for VolumeGroupReplication |
| 31 | + |
| 32 | +This section discusses the API definition, implementation nuances of VolumeGroupReplication (VGR), VolumeGroupReplicationContent (VGRContent) and VolumeGroupReplicationClass (VGRC). |
| 33 | + |
| 34 | +VolumeGroupReplication (VGR) is a namespaced scope resource that contains references to the PVCs that are to be grouped and replicated to a secondary cluster. |
| 35 | + |
| 36 | +VolumeGroupReplicationContent (VGRContent) is a clusterscoped resource that contains volume grouping related information and reference to the PVs part of the group. |
| 37 | + |
| 38 | +VolumeGroupReplicationClass (VGRC) is a clusterscoped resource that contains driver related configuration parameters required for group replication. It is similar to the definition of a StorageClass (SC) in K8s but crafted for VolumeGroupReplication. |
| 39 | + |
| 40 | +### Implementation/Workflow Details |
| 41 | + |
| 42 | + |
| 43 | + |
| 44 | +To start with, admin should create the VRC, VGRC which contains the provisioner (csi driver) that supports replication capability and the volumes (PVCs) should be created using the same provisioner. Also, add the necessary parameters required by the storage vendor to mirror the group to a secondary cluster like the secret name, namespace. |
| 45 | + |
| 46 | +To start replication of the group, the user needs to create a VGR that contains the PVC label selector as the source which would be used to filter the PVCs that are supposed to be part of the same group and replicated to a secondary cluster, along with other required fields like the VRC (created above), VGRC (created above), and the desired replicationState of the VGR. |
| 47 | +The VGR only groups PVCs that are part of the same namespace as that of VGR. |
| 48 | +The `replicationState` indicates the current role of the VGR such as `primary` means the VGR is in the active replication role, sending data to a secondary cluster, or `secondary` that means the VGR is in the passive role, receiving replicated data from the primary cluster (having VGR is not manadatory here when its in passive role). |
| 49 | + |
| 50 | +VGR’s spec consists of a field named external which signifies if the CR should be reconciled and managed by the csi-addons volumegroupreplication_controller or by the storage vendor specific implementation of the VGR controller. |
| 51 | +When set to true the CR won’t be reconciled by the csi-addons “volumegroupreplication_controller”, and the storage vendor is expected to deploy a controller that manages the CR. The value is set to `false` by default. |
| 52 | + |
| 53 | +When a vendor implements their storage specific controller to manage the VGR using the external field, it is the responsibility of the operator/controller watching the VGR to add the necessary validations and issue the required RPCs to enable mirroring on the group at the storage level. |
| 54 | +The VGR creation flow involves creating a VGRContent and a VR as well respectively for it. VGRContent is a cluster scoped CR that is created per VGR. It contains a reference to the VGR in its spec that is used to identify the VGR that manages it. |
| 55 | + |
| 56 | +When a VGR is created, the controller should list all the PVCs that match the label selector and can be a part of the volume group. The controller should then be creating a VGRContent for the VGR that manages the group level operations like creating, modifying, deleting etc, which can again be delegated to another controller that manages the VGRContent. |
| 57 | +Once the group is created the VGRContent should be updated with the `volumeGroupReplicationHandle` that can be checked by the VGR controller to go ahead and create the VR which would manage the mirroring based operations. |
| 58 | +The VGRContent’s Status has to be populated with `volumeHandles` of all the PV’s that are part of the group, where these PVs belong to the PVCs which are filtered using the source in VGR’s Spec.And, in a similar way the VGR’s Status.persistentVolumeClaimsRefList field should be updated with the names of all the PVCs that are part of the group. |
| 59 | + |
| 60 | +In other words, the VGR controller shouldn’t be managing the group managing and mirroring operations on its own, instead it can make use of the existing VR controller which manages mirroring operations of a volume and delegate the group operations to a separate VGRContent controller. |
| 61 | + |
| 62 | +For reference, one can check the implementation of csi-addons controllers for the same: |
| 63 | + |
| 64 | +- [volumereplication_controller](https://github.com/csi-addons/kubernetes-csi-addons/blob/main/internal/controller/replication.storage/volumereplication_controller.go) - It manages the mirroring operations for a volume/group. |
| 65 | +- [volumegroupreplication_controller](https://github.com/csi-addons/kubernetes-csi-addons/blob/main/internal/controller/replication.storage/volumegroupreplication_controller.go) - It manages the flow of VGR and necessary validations to keep the VGR as the source of truth for the user. |
| 66 | +- [volumegroupreplicationcontent_controller](https://github.com/csi-addons/kubernetes-csi-addons/blob/main/internal/controller/replication.storage/volumegroupreplicationcontent_controller.go) - It manages the group level operations for the VGR. |
| 67 | + |
| 68 | +VGR has a Status field that is basically the same as that of VolumeReplication’s Status field and it can be utilized by the storage vendor to populate the current status of replication to the end user and report any errors as such at the CR level. |
| 69 | + |
| 70 | +### Pre-Provisioned VolumeGroup |
| 71 | + |
| 72 | +Admin can create a VGRContent specifying an existing `volumeGroupReplicationHandle` in the storage system and specifying an existing VolumeGroup name and namespace. Then, the user can create a VolumeGroup that points to the VGRContent name. |
| 73 | + |
| 74 | +The VGR controller will filter all the PVCs that match the label selector of the VGR, and the VGRContent controller will issue a Modify RPC call to update the group with any new PVC, or shall return if the group is unchanged. Then, the VGR controller can manage mirroring on the volume group and enable mirroring on the group. |
| 75 | + |
| 76 | +### Delete VolumeGroupReplication |
| 77 | + |
| 78 | +When a VolumeGroupReplication is deleted the controller should first remove the volumes from the group, and then delete the group. Or, it can choose to disable mirroring and then remove the volumes from the group as well. |
| 79 | +Then, delete the VolumeGroup from the storage system. And, delete the VGRContent and perform deletion of VR which would disable the mirroring operations, remove any sanitary annotations from PVCs, VGR if any. Then, at the end the VolumeGroup CR should be deleted by the controller. |
| 80 | + |
| 81 | +## API definition of VolumeGroupReplication (VGR) CRD |
| 82 | + |
| 83 | +- [VR Type Definition](https://github.com/csi-addons/kubernetes-csi-addons/blob/main/api/replication.storage/v1alpha1/volumegroupreplication_types.go) |
| 84 | +- [VR CRD Definition](https://github.com/csi-addons/kubernetes-csi-addons/blob/main/config/crd/bases/replication.storage.openshift.io_volumegroupreplications.yaml) |
| 85 | + |
| 86 | +## API definition of VolumeGroupReplicationContent CRD |
| 87 | + |
| 88 | +- [VR Type Definition](https://github.com/csi-addons/kubernetes-csi-addons/blob/main/api/replication.storage/v1alpha1/volumegroupreplicationcontent_types.go) |
| 89 | +- [VR CRD Definition](https://github.com/csi-addons/kubernetes-csi-addons/blob/main/config/crd/bases/replication.storage.openshift.io_volumegroupreplicationcontents.yaml) |
| 90 | + |
| 91 | +## API definition of VolumeGroupReplicationClass (VGRC) CRD |
| 92 | + |
| 93 | +- [VR Type Definition](https://github.com/csi-addons/kubernetes-csi-addons/blob/main/api/replication.storage/v1alpha1/volumegroupreplicationclass_types.go) |
| 94 | +- [VR CRD Definition](https://github.com/csi-addons/kubernetes-csi-addons/blob/main/config/crd/bases/replication.storage.openshift.io_volumegroupreplicationclasses.yaml) |
| 95 | + |
| 96 | +## Example YAML files |
| 97 | + |
| 98 | +- VolumeGroupReplicationClass (VGRC) CR: |
| 99 | + |
| 100 | +```yaml |
| 101 | +apiVersion: replication.storage.openshift.io/v1alpha1 |
| 102 | +kind: VolumeGroupReplicationClass |
| 103 | +metadata: |
| 104 | + name: volumegroupreplicationclass-sample |
| 105 | +spec: |
| 106 | + provisioner: example.provisioner.io |
| 107 | + parameters: |
| 108 | + clusterID: my-cluster |
| 109 | + replication.storage.openshift.io/group-replication-secret-name: secret-name |
| 110 | + replication.storage.openshift.io/group-replication-secret-namespace: secret-namespace |
| 111 | +``` |
| 112 | +
|
| 113 | +- VolumeGroupReplication (VGR) CR: |
| 114 | +
|
| 115 | +```yaml |
| 116 | +apiVersion: replication.storage.openshift.io/v1alpha1 |
| 117 | +kind: VolumeGroupReplication |
| 118 | +metadata: |
| 119 | + name: volumegroupreplication-sample |
| 120 | + namespace: default |
| 121 | +spec: |
| 122 | + volumeReplicationClassName: volumereplicationclass-sample |
| 123 | + volumeGroupReplicationClassName: volumegroupreplicationclass-sample |
| 124 | + replicationState: primary |
| 125 | + source: |
| 126 | + selector: |
| 127 | + matchLabels: |
| 128 | + appname: test |
| 129 | +status: |
| 130 | + persistentVolumeClaimsRefList: |
| 131 | + - test-pvc |
| 132 | + state: primary |
| 133 | +``` |
0 commit comments