Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

csi: add feature to list rbd images using "rbd ls" #333

Merged
merged 1 commit into from
Dec 9, 2024

Conversation

OdedViner
Copy link
Contributor

@OdedViner OdedViner commented Oct 27, 2024

This PR introduces a new feature to the Rook CLI, enabling users to list RBD images using the rbd ls command. It retrieves and displays RBD images for a given pool and namespace, providing a structured tabular output.

Tested locally:

$ ./bin/kubectl-rook-ceph rbd ls
poolName       imageName                                     namespace    
--------       ---------                                     ---------    
replicapool55  csi-vol-157347bd-2359-447f-8759-94f58794b6d6  ---          
replicapool    csi-vol-f2e19b05-f51a-4897-9f4f-ffe18c9f854e  namespace-a  
replicapool    csi-vol-36a5f126-dd74-4051-ad53-53c1b1e84cf8  namespace-b  
replicapool    ---                                           namespace-c  

Checklist:

  • Commit Message Formatting: Commit titles and messages follow guidelines in the developer guide.
  • Reviewed the developer guide on Submitting a Pull Request
  • Documentation has been updated, if necessary.
  • Unit tests have been added, if necessary.
  • Integration tests have been added, if necessary.

Copy link
Collaborator

@subhamkrai subhamkrai left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@OdedViner please fix the CI error and add a new CI test for this command thanks.

@OdedViner OdedViner force-pushed the add_ls_rbd branch 3 times, most recently from 52dad0f to 8744fff Compare October 28, 2024 14:19
@OdedViner OdedViner changed the title Add rbd ls option csi: add rbd ls option Oct 28, 2024
@OdedViner OdedViner force-pushed the add_ls_rbd branch 2 times, most recently from a696b11 to 0e5c199 Compare October 28, 2024 15:02
@OdedViner
Copy link
Contributor Author

@OdedViner please fix the CI error and add a new CI test for this command thanks.

Done

 set -ex
  kubectl rook-ceph ${NS_OPT} rbd ls replicapool
  shell: /usr/bin/bash --noprofile --norc -eo pipefail -x {0}
  env:
    ROOK_PLUGIN_SKIP_PROMPTS: true
    NS_OPT:  
+ set -ex
+ kubectl rook-ceph rbd ls replicapool
poolName     imageName                                     
--------     ---------                                     
builtin-mgr  --                                            
replicapool  csi-vol-df470f06-d699-4b8c-8f5d-b1436c437e12  

https://github.com/rook/kubectl-rook-ceph/actions/runs/11556764413/job/32165252505?pr=333

@@ -116,6 +116,12 @@ runs:
tests/github-action-helper.sh create_stale_subvolume
subVol=$(kubectl rook-ceph ${NS_OPT} subvolume ls --stale | awk '{print $2}' | grep csi-vol)
kubectl rook_ceph ${NS_OPT} subvolume delete myfs $subVol

- name: Get Rbd list
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- name: Get Rbd list
- name: Get rbd list

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done


var listCmdRbd = &cobra.Command{
Use: "ls",
Short: "Print the list of subvolumes.",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Short: "Print the list of subvolumes.",
Short: "Print the list of rbd volumes.",

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

pkg/rbd/rbd.go Outdated
)

// List retrieves and displays the Ceph block pools and their associated images.
func List(ctx context.Context, clientsets *k8sutil.Clientsets, clusterNamespace string) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
func List(ctx context.Context, clientsets *k8sutil.Clientsets, clusterNamespace string) {
func ListRbdVolumes(ctx context.Context, clientsets *k8sutil.Clientsets, clusterNamespace string) {

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

pkg/rbd/rbd.go Outdated
func List(ctx context.Context, clientsets *k8sutil.Clientsets, clusterNamespace string) {
blockPoolList, err := clientsets.Rook.CephV1().CephBlockPools(clusterNamespace).List(ctx, v1.ListOptions{})
if err != nil {
logging.Fatal(err)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
logging.Fatal(err)
logging.Fatal(fmt.Errorf(err, "failed to list CephBlockPools"))

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

pkg/rbd/rbd.go Outdated
if err != nil {
logging.Fatal(err)
}
// var blockPoolNames []string
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// var blockPoolNames []string

?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

deleted

pkg/rbd/rbd.go Outdated
blockPoolNames = make(map[string]string)

for _, blockPool := range blockPoolList.Items {
// blockPoolNames = append(blockPoolNames, blockPool.Name)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// blockPoolNames = append(blockPoolNames, blockPool.Name)

?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

deleted

pkg/rbd/rbd.go Outdated
Comment on lines 47 to 62
fmt.Fprintln(writer, "poolName\timageName\t")
fmt.Fprintln(writer, "--------\t---------\t")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
fmt.Fprintln(writer, "poolName\timageName\t")
fmt.Fprintln(writer, "--------\t---------\t")
fmt.Fprintln(writer, "poolName\timageName\t")
fmt.Fprintln(writer, "--------\t---------\t")

can we use logging pkg for logging here and below

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$ ./bin/kubectl-rook-ceph rbd ls
Info: poolName  imageName
Info: --------  ---------
Info: builtin-mgr       --
Info: replicapool       csi-vol-f090b7e1-a821-4a71-a7d2-7e3e2aaea8d1

@subhamkrai The output when I use logging is not clear; is it possible to use only fmt.Fprintln ?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm can you prefix with \n for new line and see if that make sense? otherwise if not then feel free to use fmt.Fprintln

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$ ./bin/kubectl-rook-ceph rbd ls
poolName     imageName                                     
--------     ---------                                     
builtin-mgr  --                                            
replicapool  csi-vol-f090b7e1-a821-4a71-a7d2-7e3e2aaea8d1  

output when using fmt.Fprintf

pkg/rbd/rbd.go Outdated
}

// Flush the writer
writer.Flush()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
writer.Flush()
defer writer.Flush()

and put this where writer is initialized at L45

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@OdedViner OdedViner force-pushed the add_ls_rbd branch 3 times, most recently from 73f2243 to fd23f52 Compare October 29, 2024 13:00
@OdedViner OdedViner requested a review from subhamkrai October 30, 2024 09:13
@OdedViner OdedViner force-pushed the add_ls_rbd branch 2 times, most recently from a6f54ac to 312966c Compare November 4, 2024 13:05
pkg/rbd/rbd.go Outdated
blockPoolNames[blockPool.Name] = "--"
}

cmd := "rbd"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We also need to take care of listing the images in the radosNamespace inside the pool not just in default rados namespace

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Madhu-1 Are clusterNamespace and radosNamespace different?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes thats correct, i think we need to accept the --pool --namespace CR names as the arguments or we might end up listing all the pools and all the rados namespaces. @subhamkrai @travisn WDYT?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct, we need to use --namespace also to get the image namespace

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

blockPoolList, err := clientsets.Rook.CephV1().CephBlockPools(clusterNamespace).List(ctx, v1.ListOptions{})

Currently, this code is checking for CephBlockPools CRs only within the specified clusterNamespace (rook-ceph). Would you like to extend the check to see if CephBlockPools CRs exist in other namespaces as well?

If so, we can update it to:

blockPoolList, err := clientsets.Rook.CephV1().CephBlockPools("").List(ctx, v1.ListOptions{})

Using "" as the namespace parameter makes the List call retrieve resources from all namespaces.

Additionally, would you like to include a column for the image namespace? This could help provide more context, as in the following example:

$ ./bin/kubectl-rook-ceph rbd ls
poolName     imageName                                     namespace
--------     ---------                                     ---------
builtin-mgr  --                                           rook-ceph
replicapool  csi-vol-f090b7e1-a821-4a71-a7d2-7e3e2aaea8d1 rook-ceph2

Let me know if you think this approach would be useful!

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, better we test that

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do I need to check the metadata.name field, or should I focus on the spec.mirroring.remoteNamespace field instead?"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Madhu-1 @subhamkrai done. I updated github.com/rook/rook/pkg/apis

@OdedViner OdedViner force-pushed the add_ls_rbd branch 4 times, most recently from 71428ee to bb7e341 Compare November 11, 2024 12:57
go.mod Outdated
@@ -1,16 +1,16 @@
module github.com/rook/kubectl-rook-ceph

go 1.22.5
go 1.23
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
go 1.23
go 1.23

let''s not change this one for now, we want to keep what it is rook

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@subhamkrai subhamkrai requested a review from Madhu-1 November 12, 2024 09:47
@subhamkrai
Copy link
Collaborator

@Madhu-1 ready to review?


var listCmdRbd = &cobra.Command{
Use: "ls",
Short: "Print the list of rbd volumes.",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Short: "Print the list of rbd volumes.",
Print the list of rbd images.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

pkg/rbd/rbd.go Outdated
// Retrieve list of RBD images for each pool
cmd := "rbd"
for poolName := range blockPoolNames {
args := []string{"ls", "--pool=" + poolName}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i dont see we are passing --namespace here? Did we verify this by creating multiple namespaces and see if its working as expected?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this the relevant scenario?

$ kubectl get CephBlockPoolRadosNamespace -A
NAMESPACE   NAME          PHASE   BLOCKPOOL     AGE
rook-ceph   namespace-a   Ready   replicapool   25m
rook-ceph   namespace-b   Ready   replicapool   78s

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I dont see any output

bash-5.1$ rbd ls --pool=replicapool --namespace=namespace-b
bash-5.1$ rbd ls --pool=replicapool --namespace=namespace-a
bash-5.1$ 

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bash-5.1$ ceph osd pool ls detail
pool 1 '.mgr' replicated size 1 min_size 1 crush_rule 1 object_hash rjenkins pg_num 32 pgp_num 32 autoscale_mode on last_change 22 lfor 0/0/20 flags hashpspool stripe_width 0 application mgr read_balance_score 1.00
pool 2 'replicapool' replicated size 1 min_size 1 crush_rule 2 object_hash rjenkins pg_num 32 pgp_num 32 autoscale_mode on last_change 22 lfor 0/0/20 flags hashpspool,selfmanaged_snaps stripe_width 0 application rbd read_balance_score 1.00

bash-5.1$ ceph osd pool ls detail
pool 1 '.mgr' replicated size 1 min_size 1 crush_rule 1 object_hash rjenkins pg_num 32 pgp_num 32 autoscale_mode on last_change 22 lfor 0/0/20 flags hashpspool stripe_width 0 application mgr read_balance_score 1.00
pool 2 'replicapool' replicated size 1 min_size 1 crush_rule 2 object_hash rjenkins pg_num 32 pgp_num 32 autoscale_mode on last_change 22 lfor 0/0/20 flags hashpspool,selfmanaged_snaps stripe_width 0 application rbd read_balance_score 1.00

I don't see namespace-a/b how to configure it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://rook.io/docs/rook/latest/CRDs/Block-Storage/ceph-block-pool-rados-namespace-crd/#creating-a-storage-class use this to create images and pvc or you can use rbd cli to create images in the namespace. if we dont pass the --namespace to the RBD CLI we wont list images in the namespace

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$ cat <<EOF | kubectl apply -f -
apiVersion: ceph.rook.io/v1
kind: CephBlockPoolRadosNamespace
metadata:
  name: namespace-a
  namespace: rook-ceph
spec:
  blockPoolName: replicapool
EOF
cephblockpoolradosnamespace.ceph.rook.io/namespace-a created


$  kubectl -n rook-ceph  get cephblockpoolradosnamespace/namespace-a -o jsonpath='{.status.info.clusterID}'
80fc4f4bacc064be641633e6ed25ba7e

 $ cat <<EOF | kubectl apply -f -
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
  name: rook-ceph-block-rados-ns
provisioner: rook-ceph.rbd.csi.ceph.com # csi-provisioner-name
parameters:
  clusterID: 80fc4f4bacc064be641633e6ed25ba7e
  pool: replicapool
EOF
storageclass.storage.k8s.io/rook-ceph-block-rados-ns created


$ cat <<EOF | kubectl apply -f -
apiVersion: ceph.rook.io/v1
kind: CephBlockPool
metadata:
  name: replicapool
  namespace: rook-ceph
spec:
  replicated:
    size: 3
  mirroring:
    enabled: true
    mode: image
    # schedule(s) of snapshot
    snapshotSchedules:
      - interval: 24h # daily snapshots
        startTime: 14:00:00-05:00
EOF
cephblockpool.ceph.rook.io/replicapool created



$ cat <<EOF | kubectl apply -f -
apiVersion: ceph.rook.io/v1
kind: CephBlockPoolRadosNamespace
metadata:
  name: namespace-a
  namespace: rook-ceph # namespace:cluster
spec:
  # The name of the CephBlockPool CR where the namespace is created.
  blockPoolName: replicapool
  mirroring:
    mode: image
    remoteNamespace: namespace-a # default is the same as the local rados namespace
    # schedule(s) of snapshot
    snapshotSchedules:
      - interval: 24h # daily snapshots
        startTime: 14:00:00-05:00
EOF
cephblockpoolradosnamespace.ceph.rook.io/namespace-a configured

Working with this procedure and CephBlockPoolRadosNamespace stuck in Progressing Phase and "rbd ls --pool=replicapool --namespace=namespace-a" cli stuck

$ kubectl describe CephBlockPoolRadosNamespace namespace-a -n rook-ceph
Name:         namespace-a
Namespace:    rook-ceph
Labels:       <none>
Annotations:  <none>
API Version:  ceph.rook.io/v1
Kind:         CephBlockPoolRadosNamespace
Metadata:
  Creation Timestamp:  2024-11-17T18:06:01Z
  Finalizers:
    cephblockpoolradosnamespace.ceph.rook.io
  Generation:        2
  Resource Version:  2268
  UID:               8078a253-2a23-4787-8b1e-097ba2bdf7c0
Spec:
  Block Pool Name:  replicapool
  Mirroring:
    Mode:              image
    Remote Namespace:  namespace-a
    Snapshot Schedules:
      Interval:    24h
      Start Time:  14:00:00-05:00
Status:
  Info:
    Cluster ID:  80fc4f4bacc064be641633e6ed25ba7e
  Phase:         Progressing
Events:          <none>
$ kubectl -n rook-ceph exec -it deploy/rook-ceph-tools -- bash
bash-5.1$ rbd ls --pool=replicapool --namespace=namespace-a

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please create the pvc from the above storageclass (created for radosnamespace) and then list the images

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and also you dont need to enable mirroring mode (like in above examples)

Copy link
Contributor Author

@OdedViner OdedViner Nov 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is not working for me

cat <<EOF | kubectl apply -f -
apiVersion: ceph.rook.io/v1
kind: CephBlockPoolRadosNamespace
metadata:
  name: namespace-a
  namespace: rook-ceph
spec:
  blockPoolName: replicapool
EOF

$ kubectl -n rook-ceph  get cephblockpoolradosnamespace/namespace-a -o jsonpath='{.status.info.clusterID}'
80fc4f4bacc064be641633e6ed25ba7e

cat <<EOF | kubectl apply -f -
apiVersion: ceph.rook.io/v1
kind: CephBlockPool
metadata:
  name: replicapool
  namespace: rook-ceph # namespace:cluster
spec:
  failureDomain: osd
  replicated:
    size: 1
    # Disallow setting pool with replica 1, this could lead to data loss without recovery.
    # Make sure you're *ABSOLUTELY CERTAIN* that is what you want
    requireSafeReplicaSize: false
EOF


cat <<EOF | kubectl apply -f -
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
  name: rook-ceph-block-rados-ns
provisioner: rook-ceph.rbd.csi.ceph.com # csi-provisioner-name
parameters:
  clusterID: 80fc4f4bacc064be641633e6ed25ba7e
  pool: replicapool
EOF


cat <<EOF | kubectl apply -f -
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: rbd-pvc
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 1Gi
  storageClassName: rook-ceph-block-rados-ns
EOF


$ kubectl get pvc
NAME      STATUS    VOLUME   CAPACITY   ACCESS MODES   STORAGECLASS               VOLUMEATTRIBUTESCLASS   AGE
rbd-pvc   Pending                                      rook-ceph-block-rados-ns   <unset>                 62s

  Type     Reason                Age                From                                                                                                      Message
  ----     ------                ----               ----                                                                                                      -------
  Normal   Provisioning          18s (x7 over 49s)  rook-ceph.rbd.csi.ceph.com_csi-rbdplugin-provisioner-7c8b45d6-ghpk8_8c3f9dcf-a8d5-4cf4-b8fa-d7f00fd6e3d3  External provisioner is provisioning volume for claim "default/rbd-pvc"
  Warning  ProvisioningFailed    18s (x7 over 49s)  rook-ceph.rbd.csi.ceph.com_csi-rbdplugin-provisioner-7c8b45d6-ghpk8_8c3f9dcf-a8d5-4cf4-b8fa-d7f00fd6e3d3  failed to provision volume with StorageClass "rook-ceph-block-rados-ns": rpc error: code = InvalidArgument desc = provided secret is empty
  Normal   ExternalProvisioning  6s (x5 over 49s)   persistentvolume-controller                                                                               Waiting for a volume to be created either by the external provisioner 'rook-ceph.rbd.csi.ceph.com' or manually by the system administrator. If volume creation is delayed, please verify that the provisioner is running and correctly registered.

pkg/rbd/rbd.go Outdated
writer := tabwriter.NewWriter(os.Stdout, 0, 0, 2, ' ', 0)
defer writer.Flush()
// Print header with column names
fmt.Fprintln(writer, "poolName\timageName\tnameSpace\t")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
fmt.Fprintln(writer, "poolName\timageName\tnameSpace\t")
fmt.Fprintln(writer, "poolName\timageName\tnamespace\t")

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

pkg/rbd/rbd.go Outdated
Comment on lines 68 to 88
list, err := exec.RunCommandInOperatorPod(ctx, clientsets, cmd, args, operatorNamespace, clusterNamespace, true)
if err == nil && len(list) > 0 {
blockPoolNames[poolName][0] = strings.ReplaceAll(list, "\n", "")
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what happens if there is an error?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not the expected behavior, user should be able to distinguish between the error or empty images. please return an error message in case of error

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the expected output? For example, I encounter an error every time I use builtin-mgr

error(*fmt.wrapError) *{msg: "rbd: error opening pool 'builtin-mgr': (2) No such file or directory\nrbd: listing images failed: (2) No such file or directory\n. failed to run command. command terminated with exit code 2", err: error(*fmt.wrapError) *{msg: "failed to run command. command terminated with exit code 2", err: error(k8s.io/client-go/util/exec.CodeExitError) *(*error)(0xc000414fd0)}}```
![image](https://github.com/user-attachments/assets/3154c5fb-3716-4835-92f7-2fa273da204d)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to skip special pools as its not meant for user to create the images.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

pkg/rbd/rbd.go Outdated
)

// List retrieves and displays the Ceph block pools and their associated images.
func ListRbdVolumes(ctx context.Context, clientsets *k8sutil.Clientsets, operatorNamespace string, clusterNamespace string) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ListRbdVolumes to ListImagesthe packages name is alreadyrbd` we dont need to include rbd in the function name as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed func name to ListVolumes

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ListImages makes more sense as in RBD its images and we are listing images

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@OdedViner OdedViner force-pushed the add_ls_rbd branch 2 times, most recently from d917ad6 to 15050f9 Compare November 12, 2024 12:31
pkg/rbd/rbd.go Outdated
Comment on lines 68 to 87
if blockPoolNames[poolName][1] != "--" {
args = []string{"ls", "--pool=" + poolName, "--namespace=" + blockPoolNames[poolName][1]}
} else {
args = []string{"ls", "--pool=" + poolName}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if blockPoolNames[poolName][1] != "--" {
args = []string{"ls", "--pool=" + poolName, "--namespace=" + blockPoolNames[poolName][1]}
} else {
args = []string{"ls", "--pool=" + poolName}
}
args := []string{"ls", "--pool=" + poolName}
if blockPoolNames[poolName][1] != "--" {
args = append(args, "--namespace=" + blockPoolNames[poolName][1])
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

pkg/rbd/rbd.go Outdated
}

// Initialize map to store block pool names and associated Rados namespaces
blockPoolNames := make(map[string][]string)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

haing map of string and array of string is so confusing, can use use struct instead of string for better readability?

type poolData struct {
    imageList   string
    namespace   string
}

blockPoolNames := make(map[string][]poolData)

something like above?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

pkg/rbd/rbd.go Outdated
name = blockPoolNameSpace.ObjectMeta.Name
}
if _, exists := blockPoolNames[blockPoolNameSpace.Spec.BlockPoolName]; exists {
blockPoolNames[blockPoolNameSpace.Spec.BlockPoolName][1] = name
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks wrong, we need to keep on appending the namespaces as a single blockpool can have multiple namespaces?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@OdedViner OdedViner force-pushed the add_ls_rbd branch 5 times, most recently from f87e024 to 0d59feb Compare December 5, 2024 17:44
@OdedViner OdedViner changed the title csi: add rbd ls option csi: add feature to list rbd images using "rbd ls" Dec 5, 2024
this pr adds a new feature to list rbd images using the
rbd ls command. it retrieves images for a given pool and
namespace and displays them in a tabular format.

Signed-off-by: Oded Viner <[email protected]>
Copy link
Member

@Madhu-1 Madhu-1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks much better, can you please test where you have only blockpool and images inside the blockpool but there are no namespace exists?

if poolInfo, exists := blockPoolNames[blockPoolNamespace.Spec.BlockPoolName]; exists {
poolInfo.namespaceList = append(poolInfo.namespaceList, name)
blockPoolNames[blockPoolNamespace.Spec.BlockPoolName] = poolInfo
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please add a log if you dont find blockpool !exists check

@OdedViner
Copy link
Contributor Author

OdedViner commented Dec 9, 2024

This looks much better, can you please test where you have only blockpool and images inside the blockpool but there are no namespace exists?

@Madhu-1 I tested these scenario:
1.Without namespace
2.With namespace + storageclass
3.With namespace without storageclass

$ ./bin/kubectl-rook-ceph rbd ls
poolName       imageName                                     namespace    
--------       ---------                                     ---------    
replicapool55  csi-vol-157347bd-2359-447f-8759-94f58794b6d6  ---          
replicapool    csi-vol-f2e19b05-f51a-4897-9f4f-ffe18c9f854e  namespace-a  
replicapool    csi-vol-36a5f126-dd74-4051-ad53-53c1b1e84cf8  namespace-b  
replicapool    ---                                           namespace-c  

@Madhu-1
Copy link
Member

Madhu-1 commented Dec 9, 2024

@subhamkrai PTAL

@subhamkrai subhamkrai merged commit d3a34a2 into rook:master Dec 9, 2024
6 checks passed
shell: bash --noprofile --norc -eo pipefail -x {0}
run: |
set -ex
kubectl rook-ceph ${NS_OPT} rbd ls
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As a follow up, could a validation be added to this test to confirm the expected volume(s) are listed? Otherwise, we might have a regression in the future.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@travisn I will add tests

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @travisn I opened two PRs for this test. I added a sleep statement because of some issues I observed on my local machine.
#342
rook/rook#15157

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants