Skip to content
This repository was archived by the owner on Dec 12, 2024. It is now read-only.

Commit 678adaa

Browse files
oriyardemergify[bot]
authored andcommitted
add replication id
Signed-off-by: oriyarde <[email protected]>
1 parent 597f3f8 commit 678adaa

File tree

10 files changed

+149
-100
lines changed

10 files changed

+149
-100
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ VolumeReplicationClass corresponding to the driver providing replication.
5555
+ `kind` is the kind of resource being replicated. For eg. `PersistentVolumeClaim`
5656
+ `name` is the name of the resource
5757

58+
`replicationHandle` (optional) is an existing (but new) replication id
59+
5860
```yaml
5961
apiVersion: replication.storage.openshift.io/v1alpha1
6062
kind: VolumeReplication
@@ -64,6 +66,7 @@ metadata:
6466
spec:
6567
volumeReplicationClass: volumereplicationclass-sample
6668
replicationState: primary
69+
replicationHandle: replicationHandle # optional
6770
dataSource:
6871
kind: PersistentVolumeClaim
6972
name: myPersistentVolumeClaim # should be in same namespace as VolumeReplication

api/v1alpha1/volumereplication_types.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,10 @@ type VolumeReplicationSpec struct {
6464
// DataSource represents the object associated with the volume
6565
// +kubebuilder:validation:Required
6666
DataSource corev1.TypedLocalObjectReference `json:"dataSource"`
67+
68+
// replicationHandle represents an existing (but new) replication id
69+
// +kubebuilder:validation:Optional
70+
ReplicationHandle string `json:"replicationHandle"`
6771
}
6872

6973
// VolumeReplicationStatus defines the observed state of VolumeReplication

config/crd/bases/replication.storage.openshift.io_volumereplications.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,9 @@ spec:
8383
- secondary
8484
- resync
8585
type: string
86+
replicationHandle:
87+
description: replicationHandle represents an existing (but new) replication id
88+
type: string
8689
volumeReplicationClass:
8790
description: VolumeReplicationClass is the VolumeReplicationClass
8891
name for this VolumeReplication resource

controllers/replication/replication.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,17 @@ type ReplicationResponse struct {
3737

3838
// CommonRequestParameters holds the common parameters across replication operations.
3939
type CommonRequestParameters struct {
40-
VolumeID string
41-
Parameters map[string]string
42-
Secrets map[string]string
43-
Replication client.VolumeReplication
40+
VolumeID string
41+
ReplicationID string
42+
Parameters map[string]string
43+
Secrets map[string]string
44+
Replication client.VolumeReplication
4445
}
4546

4647
func (r *Replication) Enable() *ReplicationResponse {
4748
resp, err := r.Params.Replication.EnableVolumeReplication(
4849
r.Params.VolumeID,
50+
r.Params.ReplicationID,
4951
r.Params.Secrets,
5052
r.Params.Parameters,
5153
)
@@ -56,6 +58,7 @@ func (r *Replication) Enable() *ReplicationResponse {
5658
func (r *Replication) Disable() *ReplicationResponse {
5759
resp, err := r.Params.Replication.DisableVolumeReplication(
5860
r.Params.VolumeID,
61+
r.Params.ReplicationID,
5962
r.Params.Secrets,
6063
r.Params.Parameters,
6164
)
@@ -66,6 +69,7 @@ func (r *Replication) Disable() *ReplicationResponse {
6669
func (r *Replication) Promote() *ReplicationResponse {
6770
resp, err := r.Params.Replication.PromoteVolume(
6871
r.Params.VolumeID,
72+
r.Params.ReplicationID,
6973
r.Force,
7074
r.Params.Secrets,
7175
r.Params.Parameters,
@@ -77,6 +81,7 @@ func (r *Replication) Promote() *ReplicationResponse {
7781
func (r *Replication) Demote() *ReplicationResponse {
7882
resp, err := r.Params.Replication.DemoteVolume(
7983
r.Params.VolumeID,
84+
r.Params.ReplicationID,
8085
r.Params.Secrets,
8186
r.Params.Parameters,
8287
)
@@ -87,6 +92,7 @@ func (r *Replication) Demote() *ReplicationResponse {
8792
func (r *Replication) Resync() *ReplicationResponse {
8893
resp, err := r.Params.Replication.ResyncVolume(
8994
r.Params.VolumeID,
95+
r.Params.ReplicationID,
9096
r.Params.Secrets,
9197
r.Params.Parameters,
9298
)

controllers/volumereplication_controller.go

Lines changed: 50 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,8 @@ func (r *VolumeReplicationReconciler) Reconcile(ctx context.Context, req ctrl.Re
133133
pvErr error
134134
)
135135

136+
replicationHandle := instance.Spec.ReplicationHandle
137+
136138
nameSpacedName := types.NamespacedName{Name: instance.Spec.DataSource.Name, Namespace: req.Namespace}
137139
switch instance.Spec.DataSource.Kind {
138140
case pvcDataSource:
@@ -154,6 +156,9 @@ func (r *VolumeReplicationReconciler) Reconcile(ctx context.Context, req ctrl.Re
154156
}
155157

156158
logger.Info("volume handle", "VolumeHandleName", volumeHandle)
159+
if replicationHandle != "" {
160+
logger.Info("Replication handle", "ReplicationHandleName", replicationHandle)
161+
}
157162

158163
// check if the object is being deleted
159164
if instance.GetDeletionTimestamp().IsZero() {
@@ -167,7 +172,7 @@ func (r *VolumeReplicationReconciler) Reconcile(ctx context.Context, req ctrl.Re
167172
}
168173
} else {
169174
if contains(instance.GetFinalizers(), volumeReplicationFinalizer) {
170-
err := r.disableVolumeReplication(logger, volumeHandle, parameters, secret)
175+
err := r.disableVolumeReplication(logger, volumeHandle, replicationHandle, parameters, secret)
171176
if err != nil {
172177
logger.Error(err, "failed to disable replication")
173178
return ctrl.Result{}, err
@@ -195,7 +200,7 @@ func (r *VolumeReplicationReconciler) Reconcile(ctx context.Context, req ctrl.Re
195200
}
196201

197202
// enable replication on every reconcile
198-
if err = r.enableReplication(logger, volumeHandle, parameters, secret); err != nil {
203+
if err = r.enableReplication(logger, volumeHandle, replicationHandle, parameters, secret); err != nil {
199204
logger.Error(err, "failed to enable replication")
200205
setFailureCondition(instance)
201206
_ = r.updateReplicationStatus(instance, logger, getCurrentReplicationState(instance), err.Error())
@@ -207,14 +212,14 @@ func (r *VolumeReplicationReconciler) Reconcile(ctx context.Context, req ctrl.Re
207212

208213
switch instance.Spec.ReplicationState {
209214
case replicationv1alpha1.Primary:
210-
replicationErr = r.markVolumeAsPrimary(instance, logger, volumeHandle, parameters, secret)
215+
replicationErr = r.markVolumeAsPrimary(instance, logger, volumeHandle, replicationHandle, parameters, secret)
211216

212217
case replicationv1alpha1.Secondary:
213218
// For the first time, mark the volume as secondary and requeue the
214219
// request. For some storage providers it takes some time to determine
215220
// whether the volume need correction example:- correcting split brain.
216221
if instance.Status.State != replicationv1alpha1.SecondaryState {
217-
replicationErr = r.markVolumeAsSecondary(instance, logger, volumeHandle, parameters, secret)
222+
replicationErr = r.markVolumeAsSecondary(instance, logger, volumeHandle, replicationHandle, parameters, secret)
218223
if replicationErr == nil {
219224
logger.Info("volume is not ready to use")
220225
// set the status.State to secondary as the
@@ -230,15 +235,15 @@ func (r *VolumeReplicationReconciler) Reconcile(ctx context.Context, req ctrl.Re
230235
}, nil
231236
}
232237
} else {
233-
replicationErr = r.markVolumeAsSecondary(instance, logger, volumeHandle, parameters, secret)
238+
replicationErr = r.markVolumeAsSecondary(instance, logger, volumeHandle, replicationHandle, parameters, secret)
234239
// resync volume if successfully marked Secondary
235240
if replicationErr == nil {
236-
requeueForResync, replicationErr = r.resyncVolume(instance, logger, volumeHandle, parameters, secret)
241+
requeueForResync, replicationErr = r.resyncVolume(instance, logger, volumeHandle, replicationHandle, parameters, secret)
237242
}
238243
}
239244

240245
case replicationv1alpha1.Resync:
241-
requeueForResync, replicationErr = r.resyncVolume(instance, logger, volumeHandle, parameters, secret)
246+
requeueForResync, replicationErr = r.resyncVolume(instance, logger, volumeHandle, replicationHandle, parameters, secret)
242247

243248
default:
244249
replicationErr = fmt.Errorf("unsupported volume state")
@@ -360,12 +365,15 @@ func (r *VolumeReplicationReconciler) waitForVolumeReplicationResource(logger lo
360365
}
361366

362367
// markVolumeAsPrimary defines and runs a set of tasks required to mark a volume as primary
363-
func (r *VolumeReplicationReconciler) markVolumeAsPrimary(volumeReplicationObject *replicationv1alpha1.VolumeReplication, logger logr.Logger, volumeID string, parameters, secrets map[string]string) error {
368+
func (r *VolumeReplicationReconciler) markVolumeAsPrimary(volumeReplicationObject *replicationv1alpha1.VolumeReplication,
369+
logger logr.Logger, volumeID, replicationID string, parameters, secrets map[string]string) error {
370+
364371
c := replication.CommonRequestParameters{
365-
VolumeID: volumeID,
366-
Parameters: parameters,
367-
Secrets: secrets,
368-
Replication: r.Replication,
372+
VolumeID: volumeID,
373+
ReplicationID: replicationID,
374+
Parameters: parameters,
375+
Secrets: secrets,
376+
Replication: r.Replication,
369377
}
370378

371379
volumeReplication := replication.Replication{
@@ -401,12 +409,14 @@ func (r *VolumeReplicationReconciler) markVolumeAsPrimary(volumeReplicationObjec
401409

402410
// markVolumeAsSecondary defines and runs a set of tasks required to mark a volume as secondary
403411
func (r *VolumeReplicationReconciler) markVolumeAsSecondary(volumeReplicationObject *replicationv1alpha1.VolumeReplication,
404-
logger logr.Logger, volumeID string, parameters, secrets map[string]string) error {
412+
logger logr.Logger, volumeID, replicationID string, parameters, secrets map[string]string) error {
413+
405414
c := replication.CommonRequestParameters{
406-
VolumeID: volumeID,
407-
Parameters: parameters,
408-
Secrets: secrets,
409-
Replication: r.Replication,
415+
VolumeID: volumeID,
416+
ReplicationID: replicationID,
417+
Parameters: parameters,
418+
Secrets: secrets,
419+
Replication: r.Replication,
410420
}
411421

412422
volumeReplication := replication.Replication{
@@ -427,12 +437,14 @@ func (r *VolumeReplicationReconciler) markVolumeAsSecondary(volumeReplicationObj
427437

428438
// resyncVolume defines and runs a set of tasks required to resync the volume
429439
func (r *VolumeReplicationReconciler) resyncVolume(volumeReplicationObject *replicationv1alpha1.VolumeReplication,
430-
logger logr.Logger, volumeID string, parameters, secrets map[string]string) (bool, error) {
440+
logger logr.Logger, volumeID, replicationID string, parameters, secrets map[string]string) (bool, error) {
441+
431442
c := replication.CommonRequestParameters{
432-
VolumeID: volumeID,
433-
Parameters: parameters,
434-
Secrets: secrets,
435-
Replication: r.Replication,
443+
VolumeID: volumeID,
444+
ReplicationID: replicationID,
445+
Parameters: parameters,
446+
Secrets: secrets,
447+
Replication: r.Replication,
436448
}
437449

438450
volumeReplication := replication.Replication{
@@ -467,12 +479,15 @@ func (r *VolumeReplicationReconciler) resyncVolume(volumeReplicationObject *repl
467479
}
468480

469481
// disableVolumeReplication defines and runs a set of tasks required to disable volume replication
470-
func (r *VolumeReplicationReconciler) disableVolumeReplication(logger logr.Logger, volumeID string, parameters, secrets map[string]string) error {
482+
func (r *VolumeReplicationReconciler) disableVolumeReplication(logger logr.Logger, volumeID, replicationID string,
483+
parameters, secrets map[string]string) error {
484+
471485
c := replication.CommonRequestParameters{
472-
VolumeID: volumeID,
473-
Parameters: parameters,
474-
Secrets: secrets,
475-
Replication: r.Replication,
486+
VolumeID: volumeID,
487+
ReplicationID: replicationID,
488+
Parameters: parameters,
489+
Secrets: secrets,
490+
Replication: r.Replication,
476491
}
477492

478493
volumeReplication := replication.Replication{
@@ -494,12 +509,15 @@ func (r *VolumeReplicationReconciler) disableVolumeReplication(logger logr.Logge
494509
}
495510

496511
// enableReplication enable volume replication on the first reconcile
497-
func (r *VolumeReplicationReconciler) enableReplication(logger logr.Logger, volumeID string, parameters, secrets map[string]string) error {
512+
func (r *VolumeReplicationReconciler) enableReplication(logger logr.Logger, volumeID, replicationID string,
513+
parameters, secrets map[string]string) error {
514+
498515
c := replication.CommonRequestParameters{
499-
VolumeID: volumeID,
500-
Parameters: parameters,
501-
Secrets: secrets,
502-
Replication: r.Replication,
516+
VolumeID: volumeID,
517+
ReplicationID: replicationID,
518+
Parameters: parameters,
519+
Secrets: secrets,
520+
Replication: r.Replication,
503521
}
504522

505523
volumeReplication := replication.Replication{

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module github.com/csi-addons/volume-replication-operator
33
go 1.15
44

55
require (
6-
github.com/csi-addons/spec v0.1.0
6+
github.com/csi-addons/spec v0.1.1
77
github.com/go-logr/logr v0.4.0
88
github.com/kubernetes-csi/csi-lib-utils v0.9.1
99
github.com/onsi/ginkgo v1.16.4

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,8 @@ github.com/cpuguy83/go-md2man/v2 v2.0.0/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsr
108108
github.com/creack/pty v1.1.7/go.mod h1:lj5s0c3V2DBrqTV7llrYr5NG6My20zk30Fl46Y7DoTY=
109109
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
110110
github.com/creack/pty v1.1.11/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
111-
github.com/csi-addons/spec v0.1.0 h1:y3TOd7qtnwBQPikGa1VvaL7ObyddAZehYW8DNGBlOyc=
112-
github.com/csi-addons/spec v0.1.0/go.mod h1:Mwq4iLiUV4s+K1bszcWU6aMsR5KPsbIYzzszJ6+56vI=
111+
github.com/csi-addons/spec v0.1.1 h1:Bm9ZVCQ+nYMs7Y5PK+izkzCeer262W4rjCyGpuqu9C4=
112+
github.com/csi-addons/spec v0.1.1/go.mod h1:Mwq4iLiUV4s+K1bszcWU6aMsR5KPsbIYzzszJ6+56vI=
113113
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
114114
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
115115
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=

pkg/client/fake/replication-client.go

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -23,38 +23,38 @@ import (
2323
// ReplicationClient to fake replication operations.
2424
type ReplicationClient struct {
2525
// EnableVolumeReplicationMock mocks EnableVolumeReplication RPC call.
26-
EnableVolumeReplicationMock func(volumeID string, secrets, parameters map[string]string) (*replicationlib.EnableVolumeReplicationResponse, error)
26+
EnableVolumeReplicationMock func(volumeID, replicationID string, secrets, parameters map[string]string) (*replicationlib.EnableVolumeReplicationResponse, error)
2727
// DisableVolumeReplicationMock mocks DisableVolumeReplication RPC call.
28-
DisableVolumeReplicationMock func(volumeID string, secrets, parameters map[string]string) (*replicationlib.DisableVolumeReplicationResponse, error)
28+
DisableVolumeReplicationMock func(volumeID, replicationID string, secrets, parameters map[string]string) (*replicationlib.DisableVolumeReplicationResponse, error)
2929
// PromoteVolumeMock mocks PromoteVolume RPC call.
30-
PromoteVolumeMock func(volumeID string, force bool, secrets, parameters map[string]string) (*replicationlib.PromoteVolumeResponse, error)
30+
PromoteVolumeMock func(volumeID, replicationID string, force bool, secrets, parameters map[string]string) (*replicationlib.PromoteVolumeResponse, error)
3131
// DemoteVolumeMock mocks DemoteVolume RPC call.
32-
DemoteVolumeMock func(volumeID string, secrets, parameters map[string]string) (*replicationlib.DemoteVolumeResponse, error)
32+
DemoteVolumeMock func(volumeID, replicationID string, secrets, parameters map[string]string) (*replicationlib.DemoteVolumeResponse, error)
3333
// ResyncVolumeMock mocks ResyncVolume RPC call.
34-
ResyncVolumeMock func(volumeID string, secrets, parameters map[string]string) (*replicationlib.ResyncVolumeResponse, error)
34+
ResyncVolumeMock func(volumeID, replicationID string, secrets, parameters map[string]string) (*replicationlib.ResyncVolumeResponse, error)
3535
}
3636

3737
// EnableVolumeReplication calls EnableVolumeReplicationMock mock function.
38-
func (rc *ReplicationClient) EnableVolumeReplication(volumeID string, secrets, parameters map[string]string) (*replicationlib.EnableVolumeReplicationResponse, error) {
39-
return rc.EnableVolumeReplicationMock(volumeID, secrets, parameters)
38+
func (rc *ReplicationClient) EnableVolumeReplication(volumeID, replicationID string, secrets, parameters map[string]string) (*replicationlib.EnableVolumeReplicationResponse, error) {
39+
return rc.EnableVolumeReplicationMock(volumeID, replicationID, secrets, parameters)
4040
}
4141

4242
// DisableVolumeReplication calls DisableVolumeReplicationMock mock function.
43-
func (rc *ReplicationClient) DisableVolumeReplication(volumeID string, secrets, parameters map[string]string) (*replicationlib.DisableVolumeReplicationResponse, error) {
44-
return rc.DisableVolumeReplicationMock(volumeID, secrets, parameters)
43+
func (rc *ReplicationClient) DisableVolumeReplication(volumeID, replicationID string, secrets, parameters map[string]string) (*replicationlib.DisableVolumeReplicationResponse, error) {
44+
return rc.DisableVolumeReplicationMock(volumeID, replicationID, secrets, parameters)
4545
}
4646

4747
// PromoteVolume calls PromoteVolumeMock mock function.
48-
func (rc *ReplicationClient) PromoteVolume(volumeID string, force bool, secrets, parameters map[string]string) (*replicationlib.PromoteVolumeResponse, error) {
49-
return rc.PromoteVolumeMock(volumeID, force, secrets, parameters)
48+
func (rc *ReplicationClient) PromoteVolume(volumeID, replicationID string, force bool, secrets, parameters map[string]string) (*replicationlib.PromoteVolumeResponse, error) {
49+
return rc.PromoteVolumeMock(volumeID, replicationID, force, secrets, parameters)
5050
}
5151

5252
// DemoteVolume calls DemoteVolumeMock mock function.
53-
func (rc *ReplicationClient) DemoteVolume(volumeID string, secrets, parameters map[string]string) (*replicationlib.DemoteVolumeResponse, error) {
54-
return rc.DemoteVolumeMock(volumeID, secrets, parameters)
53+
func (rc *ReplicationClient) DemoteVolume(volumeID, replicationID string, secrets, parameters map[string]string) (*replicationlib.DemoteVolumeResponse, error) {
54+
return rc.DemoteVolumeMock(volumeID, replicationID, secrets, parameters)
5555
}
5656

5757
// ResyncVolume calls ResyncVolumeMock function.
58-
func (rc *ReplicationClient) ResyncVolume(volumeID string, secrets, parameters map[string]string) (*replicationlib.ResyncVolumeResponse, error) {
59-
return rc.ResyncVolumeMock(volumeID, secrets, parameters)
58+
func (rc *ReplicationClient) ResyncVolume(volumeID, replicationID string, secrets, parameters map[string]string) (*replicationlib.ResyncVolumeResponse, error) {
59+
return rc.ResyncVolumeMock(volumeID, replicationID, secrets, parameters)
6060
}

0 commit comments

Comments
 (0)