From 498505ff09bcf9a65d4735cc0b6d8eefb980328b Mon Sep 17 00:00:00 2001 From: "Jose A. Rivera" Date: Thu, 21 Mar 2024 07:32:20 -0500 Subject: [PATCH] provider: check for RADOS namespace CephResource Signed-off-by: Jose A. Rivera --- services/provider/server/server.go | 26 +++++++++---------------- services/provider/server/server_test.go | 16 +++++++++++++-- 2 files changed, 23 insertions(+), 19 deletions(-) diff --git a/services/provider/server/server.go b/services/provider/server/server.go index dbb0e9cac0..a61cd2fd79 100644 --- a/services/provider/server/server.go +++ b/services/provider/server/server.go @@ -582,24 +582,10 @@ func (s *OCSProviderServer) GetStorageClassClaimConfig(ctx context.Context, req }), }) - case "CephBlockPool": + case "CephBlockPoolRadosNamespace": storageClassName = "ceph-rbd" storageClassData["clusterID"] = s.namespace - - // Check if the StorageClassRequest has an associated RADOS Namespace - for _, rnsRes := range storageClassRequest.Status.CephResources { - if rnsRes.Kind == "CephBlockPoolRadosNamespace" { - rns := &rookCephv1.CephBlockPoolRadosNamespace{} - err = s.client.Get(ctx, types.NamespacedName{Name: rnsRes.Name, Namespace: s.namespace}, rns) - if err != nil { - return nil, status.Errorf(codes.Internal, "failed to get %s CephBlockPoolRadosNamespace. %v", rnsRes.Name, err) - } - storageClassData["clusterID"] = rns.Status.Info["clusterID"] - storageClassData["radosnamespace"] = rns.Name - cephRes.CephClients = rnsRes.CephClients - break - } - } + storageClassData["radosnamespace"] = cephRes.Name nodeCephClientSecret, _, err := s.getCephClientInformation(ctx, cephRes.CephClients["node"]) if err != nil { @@ -611,7 +597,13 @@ func (s *OCSProviderServer) GetStorageClassClaimConfig(ctx context.Context, req return nil, status.Error(codes.Internal, err.Error()) } - storageClassData["pool"] = cephRes.Name + rns := &rookCephv1.CephBlockPoolRadosNamespace{} + err = s.client.Get(ctx, types.NamespacedName{Name: cephRes.Name, Namespace: s.namespace}, rns) + if err != nil { + return nil, status.Errorf(codes.Internal, "failed to get %s CephBlockPoolRadosNamespace. %v", cephRes.Name, err) + } + + storageClassData["pool"] = rns.Spec.BlockPoolName storageClassData["imageFeatures"] = "layering,deep-flatten,exclusive-lock,object-map,fast-diff" storageClassData["csi.storage.k8s.io/fstype"] = "ext4" storageClassData["imageFormat"] = "2" diff --git a/services/provider/server/server_test.go b/services/provider/server/server_test.go index c48752f75b..b4e1411de2 100644 --- a/services/provider/server/server_test.go +++ b/services/provider/server/server_test.go @@ -494,6 +494,7 @@ func TestOCSProviderServerGetStorageClassClaimConfig(t *testing.T) { Data: map[string]string{ "clusterID": serverNamespace, "pool": "cephblockpool", + "radosnamespace": "cephradosnamespace", "imageFeatures": "layering,deep-flatten,exclusive-lock,object-map,fast-diff", "csi.storage.k8s.io/fstype": "ext4", "imageFormat": "2", @@ -585,8 +586,8 @@ func TestOCSProviderServerGetStorageClassClaimConfig(t *testing.T) { Status: ocsv1alpha1.StorageClassRequestStatus{ CephResources: []*ocsv1alpha1.CephResourcesSpec{ { - Name: "cephblockpool", - Kind: "CephBlockPool", + Name: "cephradosnamespace", + Kind: "CephBlockPoolRadosNamespace", CephClients: map[string]string{ "node": "995e66248ad3e8642de868f461cdd827", "provisioner": "3de200d5c23524a4612bde1fdbeb717e", @@ -825,6 +826,17 @@ func TestOCSProviderServerGetStorageClassClaimConfig(t *testing.T) { } assert.NoError(t, client.Create(ctx, subVolGroup)) + radosNamespace := &rookCephv1.CephBlockPoolRadosNamespace{ + ObjectMeta: metav1.ObjectMeta{ + Name: "cephradosnamespace", + Namespace: server.namespace, + }, + Spec: rookCephv1.CephBlockPoolRadosNamespaceSpec{ + BlockPoolName: "cephblockpool", + }, + } + assert.NoError(t, client.Create(ctx, radosNamespace)) + // get the storage class request config for block pool req := pb.StorageClassClaimConfigRequest{ StorageConsumerUUID: string(consumerResource.UID),