Skip to content

Commit 0e14403

Browse files
nixpanicmergify[bot]
authored andcommitted
replication: send VolumeReplication operations to the leading controller
Just like NetworkFence operations should be sent to a preferred Controller Server, VolumeReplication operations should be sent there as well. Updates: #422 Signed-off-by: Niels de Vos <ndevos@ibm.com>
1 parent f5192a6 commit 0e14403

File tree

1 file changed

+16
-18
lines changed

1 file changed

+16
-18
lines changed

controllers/replication.storage/volumereplication_controller.go

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ func (r *VolumeReplicationReconciler) Reconcile(ctx context.Context, req ctrl.Re
174174
logger.Info("Replication handle", "ReplicationHandleName", replicationHandle)
175175
}
176176

177-
replicationClient, err := r.getReplicationClient(vrcObj.Spec.Provisioner)
177+
replicationClient, err := r.getReplicationClient(ctx, vrcObj.Spec.Provisioner)
178178
if err != nil {
179179
logger.Error(err, "Failed to get ReplicationClient")
180180

@@ -453,27 +453,25 @@ func getInfoReconcileInterval(parameters map[string]string, logger logr.Logger)
453453
return scheduleTime / 2
454454
}
455455

456-
func (r *VolumeReplicationReconciler) getReplicationClient(driverName string) (grpcClient.VolumeReplication, error) {
457-
conns := r.Connpool.GetByNodeID(driverName, "")
458-
459-
// Iterate through the connections and find the one that matches the driver name
460-
// provided in the VolumeReplication spec; so that corresponding
461-
// operations can be performed.
462-
for _, v := range conns {
463-
for _, cap := range v.Capabilities {
464-
// validate if VOLUME_REPLICATION capability is supported by the driver.
465-
if cap.GetVolumeReplication() == nil {
466-
continue
467-
}
456+
func (r *VolumeReplicationReconciler) getReplicationClient(ctx context.Context, driverName string) (grpcClient.VolumeReplication, error) {
457+
conn, err := r.Connpool.GetLeaderByDriver(ctx, r.Client, driverName)
458+
if err != nil {
459+
return nil, fmt.Errorf("no leader for the ControllerService of driver %q", driverName)
460+
}
468461

469-
// validate of VOLUME_REPLICATION capability is enabled by the storage driver.
470-
if cap.GetVolumeReplication().GetType() == identity.Capability_VolumeReplication_VOLUME_REPLICATION {
471-
return grpcClient.NewReplicationClient(v.Client, r.Timeout), nil
472-
}
462+
for _, cap := range conn.Capabilities {
463+
// validate if VOLUME_REPLICATION capability is supported by the driver.
464+
if cap.GetVolumeReplication() == nil {
465+
continue
466+
}
467+
468+
// validate of VOLUME_REPLICATION capability is enabled by the storage driver.
469+
if cap.GetVolumeReplication().GetType() == identity.Capability_VolumeReplication_VOLUME_REPLICATION {
470+
return grpcClient.NewReplicationClient(conn.Client, r.Timeout), nil
473471
}
474472
}
475473

476-
return nil, fmt.Errorf("no connections for driver: %s", driverName)
474+
return nil, fmt.Errorf("leading CSIAddonsNode %q for driver %q does not support VolumeReplication", conn.Name, driverName)
477475

478476
}
479477

0 commit comments

Comments
 (0)