From 33f4080e168d7ac2e7bd0d68e8eaa14ccf60a877 Mon Sep 17 00:00:00 2001 From: raaizik <132667934+raaizik@users.noreply.github.com> Date: Sun, 9 Jun 2024 11:10:48 +0300 Subject: [PATCH] Sends VolumeGroupSnapshotClass to client Signed-off-by: raaizik <132667934+raaizik@users.noreply.github.com> --- services/provider/server/server.go | 83 +++++++++++++++---------- services/provider/server/server_test.go | 21 +++++++ 2 files changed, 70 insertions(+), 34 deletions(-) diff --git a/services/provider/server/server.go b/services/provider/server/server.go index b7e981824b..9f35d19802 100644 --- a/services/provider/server/server.go +++ b/services/provider/server/server.go @@ -611,19 +611,27 @@ func (s *OCSProviderServer) GetStorageClaimConfig(ctx context.Context, req *pb.S rbdStorageClassData["encryptionKMSID"] = storageRequest.Spec.EncryptionMethod } - extR = append(extR, &pb.ExternalResource{ - Name: "ceph-rbd", - Kind: "StorageClass", - Data: mustMarshal(rbdStorageClassData), - }) - - extR = append(extR, &pb.ExternalResource{ - Name: "ceph-rbd", - Kind: "VolumeSnapshotClass", - Data: mustMarshal(map[string]string{ - "clusterID": rbdStorageClassData["clusterID"], - "csi.storage.k8s.io/snapshotter-secret-name": provisionerSecretName, - })}) + cephRBDClusterID := rbdStorageClassData["clusterID"] + extR = append(extR, + &pb.ExternalResource{ + Name: "ceph-rbd", + Kind: "StorageClass", + Data: mustMarshal(rbdStorageClassData), + }, + &pb.ExternalResource{ + Name: "ceph-rbd", + Kind: "VolumeSnapshotClass", + Data: mustMarshal(map[string]string{ + "clusterID": cephRBDClusterID, + "csi.storage.k8s.io/snapshotter-secret-name": provisionerSecretName, + })}, + &pb.ExternalResource{ + Name: "ceph-rbd", + Kind: "VolumeGroupSnapshotClass", + Data: mustMarshal(map[string]string{ + "clusterID": cephRBDClusterID, + "csi.storage.k8s.io/snapshotter-secret-name": provisionerSecretName, + })}) case "CephFilesystemSubVolumeGroup": subVolumeGroup := &rookCephv1.CephFilesystemSubVolumeGroup{} @@ -634,8 +642,9 @@ func (s *OCSProviderServer) GetStorageClaimConfig(ctx context.Context, req *pb.S provisionerSecretName := storageClaimCephCsiSecretName("provisioner", storageRequestHash) nodeSecretName := storageClaimCephCsiSecretName("node", storageRequestHash) + cephFSClusterID := getSubVolumeGroupClusterID(subVolumeGroup) cephfsStorageClassData := map[string]string{ - "clusterID": getSubVolumeGroupClusterID(subVolumeGroup), + "clusterID": cephFSClusterID, "subvolumegroupname": subVolumeGroup.Name, "fsName": subVolumeGroup.Spec.FilesystemName, "pool": subVolumeGroup.GetLabels()[v1alpha1.CephFileSystemDataPoolLabel], @@ -644,26 +653,32 @@ func (s *OCSProviderServer) GetStorageClaimConfig(ctx context.Context, req *pb.S "csi.storage.k8s.io/controller-expand-secret-name": provisionerSecretName, } - extR = append(extR, &pb.ExternalResource{ - Name: "cephfs", - Kind: "StorageClass", - Data: mustMarshal(cephfsStorageClassData), - }) - - extR = append(extR, &pb.ExternalResource{ - Name: cephRes.Name, - Kind: cephRes.Kind, - Data: mustMarshal(map[string]string{ - "filesystemName": subVolumeGroup.Spec.FilesystemName, - })}) - - extR = append(extR, &pb.ExternalResource{ - Name: "cephfs", - Kind: "VolumeSnapshotClass", - Data: mustMarshal(map[string]string{ - "clusterID": getSubVolumeGroupClusterID(subVolumeGroup), - "csi.storage.k8s.io/snapshotter-secret-name": provisionerSecretName, - })}) + extR = append(extR, + &pb.ExternalResource{ + Name: "cephfs", + Kind: "StorageClass", + Data: mustMarshal(cephfsStorageClassData), + }, + &pb.ExternalResource{ + Name: cephRes.Name, + Kind: cephRes.Kind, + Data: mustMarshal(map[string]string{ + "filesystemName": subVolumeGroup.Spec.FilesystemName, + })}, + &pb.ExternalResource{ + Name: "cephfs", + Kind: "VolumeSnapshotClass", + Data: mustMarshal(map[string]string{ + "clusterID": cephFSClusterID, + "csi.storage.k8s.io/snapshotter-secret-name": provisionerSecretName, + })}, + &pb.ExternalResource{ + Name: "cephfs", + Kind: "VolumeGroupSnapshotClass", + Data: mustMarshal(map[string]string{ + "clusterID": cephFSClusterID, + "csi.storage.k8s.io/snapshotter-secret-name": provisionerSecretName, + })}) } } diff --git a/services/provider/server/server_test.go b/services/provider/server/server_test.go index 25f58c80b6..dacd8f762e 100644 --- a/services/provider/server/server_test.go +++ b/services/provider/server/server_test.go @@ -511,6 +511,14 @@ func TestOCSProviderServerGetStorageClaimConfig(t *testing.T) { "csi.storage.k8s.io/snapshotter-secret-name": "ceph-client-provisioner-8d40b6be71600457b5dec219d2ce2d4c", }, }, + "ceph-rbd-volumegroupsnapshotclass": { + Name: "ceph-rbd", + Kind: "VolumeGroupSnapshotClass", + Data: map[string]string{ + "clusterID": serverNamespace, + "csi.storage.k8s.io/snapshotter-secret-name": "ceph-client-provisioner-8d40b6be71600457b5dec219d2ce2d4c", + }, + }, "ceph-client-provisioner-8d40b6be71600457b5dec219d2ce2d4c": { Name: "ceph-client-provisioner-8d40b6be71600457b5dec219d2ce2d4c", Kind: "Secret", @@ -551,6 +559,15 @@ func TestOCSProviderServerGetStorageClaimConfig(t *testing.T) { "csi.storage.k8s.io/snapshotter-secret-name": "ceph-client-provisioner-0e8555e6556f70d23a61675af44e880c", }, }, + + "cephfs-volumegroupsnapshotclass": { + Name: "cephfs", + Kind: "VolumeGroupSnapshotClass", + Data: map[string]string{ + "clusterID": "8d26c7378c1b0ec9c2455d1c3601c4cd", + "csi.storage.k8s.io/snapshotter-secret-name": "ceph-client-provisioner-0e8555e6556f70d23a61675af44e880c", + }, + }, "ceph-client-provisioner-0e8555e6556f70d23a61675af44e880c": { Name: "ceph-client-provisioner-0e8555e6556f70d23a61675af44e880c", Kind: "Secret", @@ -853,6 +870,8 @@ func TestOCSProviderServerGetStorageClaimConfig(t *testing.T) { name = fmt.Sprintf("%s-volumesnapshotclass", name) } else if extResource.Kind == "StorageClass" { name = fmt.Sprintf("%s-storageclass", name) + } else if extResource.Kind == "VolumeGroupSnapshotClass" { + name = fmt.Sprintf("%s-volumegroupsnapshotclass", name) } mockResoruce, ok := mockBlockPoolClaimExtR[name] assert.True(t, ok) @@ -880,6 +899,8 @@ func TestOCSProviderServerGetStorageClaimConfig(t *testing.T) { name = fmt.Sprintf("%s-volumesnapshotclass", name) } else if extResource.Kind == "StorageClass" { name = fmt.Sprintf("%s-storageclass", name) + } else if extResource.Kind == "VolumeGroupSnapshotClass" { + name = fmt.Sprintf("%s-volumegroupsnapshotclass", name) } mockResoruce, ok := mockShareFilesystemClaimExtR[name] assert.True(t, ok)