-
Notifications
You must be signed in to change notification settings - Fork 28
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
Conversation
There was a problem hiding this 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.
52dad0f
to
8744fff
Compare
a696b11
to
0e5c199
Compare
Done
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- name: Get Rbd list | |
- name: Get rbd list |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
cmd/commands/rbd.go
Outdated
|
||
var listCmdRbd = &cobra.Command{ | ||
Use: "ls", | ||
Short: "Print the list of subvolumes.", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Short: "Print the list of subvolumes.", | |
Short: "Print the list of rbd volumes.", |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
func List(ctx context.Context, clientsets *k8sutil.Clientsets, clusterNamespace string) { | |
func ListRbdVolumes(ctx context.Context, clientsets *k8sutil.Clientsets, clusterNamespace string) { |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
logging.Fatal(err) | |
logging.Fatal(fmt.Errorf(err, "failed to list CephBlockPools")) |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// var blockPoolNames []string |
?
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// blockPoolNames = append(blockPoolNames, blockPool.Name) |
?
There was a problem hiding this comment.
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
fmt.Fprintln(writer, "poolName\timageName\t") | ||
fmt.Fprintln(writer, "--------\t---------\t") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
writer.Flush() | |
defer writer.Flush() |
and put this where writer is initialized at L45
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
73f2243
to
fd23f52
Compare
a6f54ac
to
312966c
Compare
pkg/rbd/rbd.go
Outdated
blockPoolNames[blockPool.Name] = "--" | ||
} | ||
|
||
cmd := "rbd" |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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!
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
spec.name if its set or else metadata.name https://github.com/rook/rook/blob/c5df2fe7214b51b1297b0250d2153970047c6d74/deploy/examples/radosnamespace.yaml#L4-L9
There was a problem hiding this comment.
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
71428ee
to
bb7e341
Compare
go.mod
Outdated
@@ -1,16 +1,16 @@ | |||
module github.com/rook/kubectl-rook-ceph | |||
|
|||
go 1.22.5 | |||
go 1.23 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
go 1.23 | |
go 1.23 |
let''s not change this one for now, we want to keep what it is rook
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
bb7e341
to
25326a0
Compare
@Madhu-1 ready to review? |
cmd/commands/rbd.go
Outdated
|
||
var listCmdRbd = &cobra.Command{ | ||
Use: "ls", | ||
Short: "Print the list of rbd volumes.", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Short: "Print the list of rbd volumes.", | |
Print the list of rbd images. |
There was a problem hiding this comment.
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} |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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$
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In my code, I get the namespace
via kubectl command and not ceph cli https://github.com/rook/kubectl-rook-ceph/pull/333/files#diff-b4c239a28ac425efccdf14790165fceaf4be580365efb6ccc72068a6800958f8R47
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fmt.Fprintln(writer, "poolName\timageName\tnameSpace\t") | |
fmt.Fprintln(writer, "poolName\timageName\tnamespace\t") |
There was a problem hiding this comment.
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, err := exec.RunCommandInOperatorPod(ctx, clientsets, cmd, args, operatorNamespace, clusterNamespace, true) | ||
if err == nil && len(list) > 0 { | ||
blockPoolNames[poolName][0] = strings.ReplaceAll(list, "\n", "") | ||
} |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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 already
rbd` we dont need to include rbd in the function name as well.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
d917ad6
to
15050f9
Compare
15050f9
to
e158753
Compare
pkg/rbd/rbd.go
Outdated
if blockPoolNames[poolName][1] != "--" { | ||
args = []string{"ls", "--pool=" + poolName, "--namespace=" + blockPoolNames[poolName][1]} | ||
} else { | ||
args = []string{"ls", "--pool=" + poolName} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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]) | |
} |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
f87e024
to
0d59feb
Compare
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]>
There was a problem hiding this 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 | ||
} |
There was a problem hiding this comment.
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
@Madhu-1 I tested these scenario:
|
@subhamkrai PTAL |
shell: bash --noprofile --norc -eo pipefail -x {0} | ||
run: | | ||
set -ex | ||
kubectl rook-ceph ${NS_OPT} rbd ls |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
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:
Checklist: