Skip to content

Commit dfb6033

Browse files
committed
server: send vgrc to clients
Signed-off-by: Rewant Soni <[email protected]>
1 parent eeffce5 commit dfb6033

File tree

1 file changed

+78
-0
lines changed

1 file changed

+78
-0
lines changed

services/provider/server/server.go

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1123,6 +1123,19 @@ func (s *OCSProviderServer) getKubeResources(ctx context.Context, consumer *ocsv
11231123
return nil, err
11241124
}
11251125

1126+
kubeResources, err = s.appendVolumeGroupReplicationClassKubeResources(
1127+
ctx,
1128+
kubeResources,
1129+
consumer,
1130+
consumerConfig,
1131+
storageCluster,
1132+
rbdStorageId,
1133+
mirroringTargetInfo.RbdStorageID,
1134+
)
1135+
if err != nil {
1136+
return nil, err
1137+
}
1138+
11261139
kubeResources, err = s.appendClusterResourceQuotaKubeResources(
11271140
kubeResources,
11281141
consumer,
@@ -1686,6 +1699,71 @@ func (s *OCSProviderServer) appendVolumeReplicationClassKubeResources(
16861699
return kubeResources, nil
16871700
}
16881701

1702+
func (s *OCSProviderServer) appendVolumeGroupReplicationClassKubeResources(
1703+
ctx context.Context,
1704+
kubeResources []client.Object,
1705+
consumer *ocsv1alpha1.StorageConsumer,
1706+
consumerConfig util.StorageConsumerResources,
1707+
storageCluster *ocsv1.StorageCluster,
1708+
rbdStorageId string,
1709+
remoteRbdStorageId string,
1710+
) ([]client.Object, error) {
1711+
if mirrorEnabled, err := s.isConsumerMirrorEnabled(ctx, consumer); err != nil {
1712+
return kubeResources, err
1713+
} else if !mirrorEnabled {
1714+
klog.Infof("skipping distribution of VolumeGroupReplicationClass as mirroring is not enabled for the consumer")
1715+
return kubeResources, nil
1716+
}
1717+
1718+
for i := range consumer.Spec.VolumeGroupReplicationClasses {
1719+
replicationClassName := consumer.Spec.VolumeGroupReplicationClasses[i].Name
1720+
//TODO: The code is written under the assumption VRC name is exactly the same as the template name and there
1721+
// is 1:1 mapping between template and vrc. The restriction will be relaxed in the future
1722+
vgrcTemplate := &templatev1.Template{}
1723+
vgrcTemplate.Name = replicationClassName
1724+
vgrcTemplate.Namespace = consumer.Namespace
1725+
1726+
if err := s.client.Get(ctx, client.ObjectKeyFromObject(vgrcTemplate), vgrcTemplate); err != nil {
1727+
return kubeResources, fmt.Errorf("failed to get VolumeGroupReplicationClass template: %s, %v", replicationClassName, err)
1728+
}
1729+
1730+
if len(vgrcTemplate.Objects) != 1 {
1731+
return kubeResources, fmt.Errorf("unexpected number of Volume Group Replication Class found expected 1")
1732+
}
1733+
1734+
vgrc := &replicationv1alpha1.VolumeGroupReplicationClass{}
1735+
if err := json.Unmarshal(vgrcTemplate.Objects[0].Raw, vgrc); err != nil {
1736+
return kubeResources, fmt.Errorf("failed to unmarshall volume group replication class: %s, %v", replicationClassName, err)
1737+
1738+
}
1739+
1740+
if vgrc.Name != replicationClassName {
1741+
return kubeResources, fmt.Errorf("volume group replication class name mismatch: %s, %v", replicationClassName, vgrc.Name)
1742+
}
1743+
1744+
switch vgrc.Spec.Provisioner {
1745+
case util.RbdDriverName:
1746+
// For VGRC the replicationID will be a combination of RBDStorageID, RemoteRBDStorageID and the poolName
1747+
// pool name is added to the VGRC's template
1748+
poolName := vgrc.Spec.Parameters["pool"]
1749+
storageIDs := []string{rbdStorageId, remoteRbdStorageId, poolName}
1750+
slices.Sort(storageIDs)
1751+
replicationID := util.CalculateMD5Hash(storageIDs)
1752+
vgrc.Spec.Parameters["replication.storage.openshift.io/group-replication-secret-name"] = consumerConfig.GetCsiRbdProvisionerCephUserName()
1753+
vgrc.Spec.Parameters["replication.storage.openshift.io/group-replication-secret-namespace"] = consumer.Status.Client.OperatorNamespace
1754+
vgrc.Spec.Parameters["clusterID"] = consumerConfig.GetRbdClientProfileName()
1755+
util.AddLabel(vgrc, ramenDRStorageIDLabelKey, rbdStorageId)
1756+
util.AddLabel(vgrc, ramenMaintenanceModeLabelKey, "Failover")
1757+
util.AddLabel(vgrc, ramenDRReplicationIDLabelKey, replicationID)
1758+
default:
1759+
return kubeResources, fmt.Errorf("unsupported Provisioner for VolumeGroupReplicationClass")
1760+
}
1761+
kubeResources = append(kubeResources, vgrc)
1762+
}
1763+
1764+
return kubeResources, nil
1765+
}
1766+
16891767
func (s *OCSProviderServer) appendClusterResourceQuotaKubeResources(
16901768
kubeResources []client.Object,
16911769
consumer *ocsv1alpha1.StorageConsumer,

0 commit comments

Comments
 (0)