Skip to content

Commit ff76163

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

File tree

27 files changed

+6953
-2
lines changed

27 files changed

+6953
-2
lines changed
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
package util
2+
3+
import (
4+
"context"
5+
"encoding/json"
6+
"fmt"
7+
"slices"
8+
9+
ocsv1a1 "github.com/red-hat-storage/ocs-operator/api/v4/v1alpha1"
10+
11+
replicationv1alpha1 "github.com/csi-addons/kubernetes-csi-addons/api/replication.storage/v1alpha1"
12+
templatev1 "github.com/openshift/api/template/v1"
13+
"sigs.k8s.io/controller-runtime/pkg/client"
14+
)
15+
16+
const (
17+
ramenDRStorageIDLabelKey = "ramendr.openshift.io/storageid"
18+
ramenDRReplicationIDLabelKey = "ramendr.openshift.io/replicationid"
19+
ramenMaintenanceModeLabelKey = "ramendr.openshift.io/maintenancemodes"
20+
)
21+
22+
func VolumeGroupReplicationClassFromTemplate(
23+
ctx context.Context,
24+
kubeClient client.Client,
25+
volumeGroupReplicationClassName string,
26+
consumer *ocsv1a1.StorageConsumer,
27+
consumerConfig StorageConsumerResources,
28+
rbdStorageId,
29+
remoteRbdStorageId string,
30+
) (*replicationv1alpha1.VolumeGroupReplicationClass, error) {
31+
replicationClassName := volumeGroupReplicationClassName
32+
//TODO: The code is written under the assumption VGRC name is exactly the same as the template name and there
33+
// is 1:1 mapping between template and vgrc. The restriction will be relaxed in the future
34+
vgrcTemplate := &templatev1.Template{}
35+
vgrcTemplate.Name = replicationClassName
36+
vgrcTemplate.Namespace = consumer.Namespace
37+
38+
if err := kubeClient.Get(ctx, client.ObjectKeyFromObject(vgrcTemplate), vgrcTemplate); err != nil {
39+
return nil, fmt.Errorf("failed to get VolumeGroupReplicationClass template: %s, %v", replicationClassName, err)
40+
}
41+
42+
if len(vgrcTemplate.Objects) != 1 {
43+
return nil, fmt.Errorf("unexpected number of Volume Group Replication Class found expected 1")
44+
}
45+
46+
vgrc := &replicationv1alpha1.VolumeGroupReplicationClass{}
47+
if err := json.Unmarshal(vgrcTemplate.Objects[0].Raw, vgrc); err != nil {
48+
return nil, fmt.Errorf("failed to unmarshall volume group replication class: %s, %v", replicationClassName, err)
49+
50+
}
51+
52+
if vgrc.Name != replicationClassName {
53+
return nil, fmt.Errorf("volume group replication class name mismatch: %s, %v", replicationClassName, vgrc.Name)
54+
}
55+
56+
switch vgrc.Spec.Provisioner {
57+
case RbdDriverName:
58+
// For VGRC the replicationID will be a combination of RBDStorageID, RemoteRBDStorageID and the poolName
59+
// pool name is added to the VGRC's template
60+
poolName := vgrc.Spec.Parameters["pool"]
61+
storageIDs := []string{rbdStorageId, remoteRbdStorageId, poolName}
62+
slices.Sort(storageIDs)
63+
replicationID := CalculateMD5Hash(storageIDs)
64+
vgrc.Spec.Parameters["replication.storage.openshift.io/group-replication-secret-name"] = consumerConfig.GetCsiRbdProvisionerCephUserName()
65+
vgrc.Spec.Parameters["replication.storage.openshift.io/group-replication-secret-namespace"] = consumer.Status.Client.OperatorNamespace
66+
vgrc.Spec.Parameters["clusterID"] = consumerConfig.GetRbdClientProfileName()
67+
AddLabel(vgrc, ramenDRStorageIDLabelKey, rbdStorageId)
68+
AddLabel(vgrc, ramenMaintenanceModeLabelKey, "Failover")
69+
AddLabel(vgrc, ramenDRReplicationIDLabelKey, replicationID)
70+
default:
71+
return nil, fmt.Errorf("unsupported Provisioner for VolumeGroupReplicationClass")
72+
}
73+
return vgrc, nil
74+
}

deploy/csv-templates/ocs-operator.csv.yaml.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ metadata:
8080
"spec": null
8181
}
8282
]
83-
createdAt: "2025-07-15T15:37:59Z"
83+
createdAt: "2025-07-16T06:14:16Z"
8484
description: Red Hat OpenShift Container Storage provides hyperconverged storage
8585
for applications within an OpenShift cluster.
8686
operators.operatorframework.io/builder: operator-sdk-v1.30.0

deploy/ocs-operator/manifests/ocs-operator.clusterserviceversion.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ metadata:
5757
capabilities: Deep Insights
5858
categories: Storage
5959
containerImage: quay.io/ocs-dev/ocs-operator:latest
60-
createdAt: "2025-07-15T15:37:59Z"
60+
createdAt: "2025-07-16T06:14:16Z"
6161
description: Red Hat OpenShift Container Storage provides hyperconverged storage
6262
for applications within an OpenShift cluster.
6363
external.features.ocs.openshift.io/supported-platforms: '["BareMetal", "None",

metrics/go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ require (
5555
github.com/cloudnative-pg/cloudnative-pg v1.25.1 // indirect
5656
github.com/cloudnative-pg/machinery v0.1.0 // indirect
5757
github.com/containernetworking/cni v1.2.3 // indirect
58+
github.com/csi-addons/kubernetes-csi-addons v0.12.0 // indirect
5859
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
5960
github.com/emicklei/go-restful/v3 v3.12.2 // indirect
6061
github.com/evanphx/json-patch/v5 v5.9.11 // indirect

metrics/go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,8 @@ github.com/cpuguy83/go-md2man v1.0.10/go.mod h1:SmD6nW6nTyfqj6ABTjUi3V3JVMnlJmwc
205205
github.com/cpuguy83/go-md2man/v2 v2.0.0/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
206206
github.com/creack/pty v1.1.7/go.mod h1:lj5s0c3V2DBrqTV7llrYr5NG6My20zk30Fl46Y7DoTY=
207207
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
208+
github.com/csi-addons/kubernetes-csi-addons v0.12.0 h1:RbF2dCjWV4ljynibEOkA0wbwwt/09awjOKgEFC14Bns=
209+
github.com/csi-addons/kubernetes-csi-addons v0.12.0/go.mod h1:8vrXJUZrlI2ms2aZ6qRfp8ieRlpHEefTX5azOFi67o0=
208210
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
209211
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
210212
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM=

metrics/vendor/github.com/csi-addons/kubernetes-csi-addons/LICENSE

Lines changed: 202 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

metrics/vendor/github.com/csi-addons/kubernetes-csi-addons/api/replication.storage/v1alpha1/groupversion_info.go

Lines changed: 36 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)