Skip to content

Commit

Permalink
provider: check for RADOS namespace CephResource
Browse files Browse the repository at this point in the history
Signed-off-by: Jose A. Rivera <[email protected]>
  • Loading branch information
jarrpa committed Mar 21, 2024
1 parent 8f94626 commit 498505f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 19 deletions.
26 changes: 9 additions & 17 deletions services/provider/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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"
Expand Down
16 changes: 14 additions & 2 deletions services/provider/server/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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),
Expand Down

0 comments on commit 498505f

Please sign in to comment.