Repository navigation
Conversation
|
Thank you for your contribution. Since you, the author, are not a member of the Ceph GitHub Org yet, our CI will not automatically run. Any member of the Ceph Org may comment "ok - to - test" (without the dashes) to allow the Jenkins jobs to run. |
16 similar comments
|
Thank you for your contribution. Since you, the author, are not a member of the Ceph GitHub Org yet, our CI will not automatically run. Any member of the Ceph Org may comment "ok - to - test" (without the dashes) to allow the Jenkins jobs to run. |
|
Thank you for your contribution. Since you, the author, are not a member of the Ceph GitHub Org yet, our CI will not automatically run. Any member of the Ceph Org may comment "ok - to - test" (without the dashes) to allow the Jenkins jobs to run. |
|
Thank you for your contribution. Since you, the author, are not a member of the Ceph GitHub Org yet, our CI will not automatically run. Any member of the Ceph Org may comment "ok - to - test" (without the dashes) to allow the Jenkins jobs to run. |
|
Thank you for your contribution. Since you, the author, are not a member of the Ceph GitHub Org yet, our CI will not automatically run. Any member of the Ceph Org may comment "ok - to - test" (without the dashes) to allow the Jenkins jobs to run. |
|
Thank you for your contribution. Since you, the author, are not a member of the Ceph GitHub Org yet, our CI will not automatically run. Any member of the Ceph Org may comment "ok - to - test" (without the dashes) to allow the Jenkins jobs to run. |
|
Thank you for your contribution. Since you, the author, are not a member of the Ceph GitHub Org yet, our CI will not automatically run. Any member of the Ceph Org may comment "ok - to - test" (without the dashes) to allow the Jenkins jobs to run. |
|
Thank you for your contribution. Since you, the author, are not a member of the Ceph GitHub Org yet, our CI will not automatically run. Any member of the Ceph Org may comment "ok - to - test" (without the dashes) to allow the Jenkins jobs to run. |
|
Thank you for your contribution. Since you, the author, are not a member of the Ceph GitHub Org yet, our CI will not automatically run. Any member of the Ceph Org may comment "ok - to - test" (without the dashes) to allow the Jenkins jobs to run. |
|
Thank you for your contribution. Since you, the author, are not a member of the Ceph GitHub Org yet, our CI will not automatically run. Any member of the Ceph Org may comment "ok - to - test" (without the dashes) to allow the Jenkins jobs to run. |
|
Thank you for your contribution. Since you, the author, are not a member of the Ceph GitHub Org yet, our CI will not automatically run. Any member of the Ceph Org may comment "ok - to - test" (without the dashes) to allow the Jenkins jobs to run. |
|
Thank you for your contribution. Since you, the author, are not a member of the Ceph GitHub Org yet, our CI will not automatically run. Any member of the Ceph Org may comment "ok - to - test" (without the dashes) to allow the Jenkins jobs to run. |
|
Thank you for your contribution. Since you, the author, are not a member of the Ceph GitHub Org yet, our CI will not automatically run. Any member of the Ceph Org may comment "ok - to - test" (without the dashes) to allow the Jenkins jobs to run. |
|
Thank you for your contribution. Since you, the author, are not a member of the Ceph GitHub Org yet, our CI will not automatically run. Any member of the Ceph Org may comment "ok - to - test" (without the dashes) to allow the Jenkins jobs to run. |
|
Thank you for your contribution. Since you, the author, are not a member of the Ceph GitHub Org yet, our CI will not automatically run. Any member of the Ceph Org may comment "ok - to - test" (without the dashes) to allow the Jenkins jobs to run. |
|
Thank you for your contribution. Since you, the author, are not a member of the Ceph GitHub Org yet, our CI will not automatically run. Any member of the Ceph Org may comment "ok - to - test" (without the dashes) to allow the Jenkins jobs to run. |
|
Thank you for your contribution. Since you, the author, are not a member of the Ceph GitHub Org yet, our CI will not automatically run. Any member of the Ceph Org may comment "ok - to - test" (without the dashes) to allow the Jenkins jobs to run. |
|
This pull request can no longer be automatically merged: a rebase is needed and changes have to be manually resolved |
ff4a283 to
6f70c26
Compare
|
This pull request can no longer be automatically merged: a rebase is needed and changes have to be manually resolved |
|
|
||
| if (script_put->parsed()) { | ||
| script_put->callback( | ||
| [script_put, &str_script_ctx, &infile, &tenant, |
There was a problem hiding this comment.
This is pretty neat!
To further the consolidation of command code into the callback, could we pass in the CLI11 object and collect parameter values from that instead of binding them to variables in the root function scope? Personally I think it'd be preferable if we could just pass in some cli11 object here instead of str_script_ctx, infile and tenant (which have to be declared elsewhere in a massive list). I guess with 3 parameters it isn't too bad but it would not surprise me if we have commands with many more parameters, in which case this would get quite unwieldy.
I guess as an alternative, moving all the declarations into a smaller scope would help with separating things out? Or maybe we can just keep doing this for now and see how it goes with other commands? ¯\_(ツ)_/¯
| @@ -4340,6 +4340,14 @@ int main(int argc, const char **argv) | |||
| add_multilevel_option(bucket_layout, "--tenant", tenant, tenant_desc); | |||
| add_multilevel_option(bucket_layout, "--format", format, format_desc); | |||
|
|
|||
| // bucket chown options | |||
| add_multilevel_option(bucket_chown, "--bucket,-b", bucket_name, bucket_desc)->option_text("<bucket> REQUIRED"); | |||
There was a problem hiding this comment.
This is just a code organisation thing so not a functional difference and maybe this is just me but: It feels weird to me that we've separated the definition of the subcommand itself, the options/flags for that subcommand, and the callback/behaviour for that subcommand.
I think it would be preferable if the code were sliced by command rather than by type-of-specification, for example.
auto* cmd_bucket = app->add_subcommand("bucket")
cmd_bucket->require_subcommand()
// ...whatever other options for the bucket command as a whole
auto cmd_bucket_list = cmd_bucket->add_subcommand("list")
add_multilevel_option(cmd_bucket_list, "--max-entries")
cmd_bucket_list->callback(...)
auto cmd_bucket_stats = cmd_bucket->add_subcommand("stats")
// ..etcThat way when you want to add a new command (or edit an existing one), all the changes go in one place.
Thoughts?
There was a problem hiding this comment.
I think the argument for keeping each command self-contained makes sense.
One alternative I considered was introducing small helpers for some of the frequently repeated bucket options. For example, a helper that registers --bucket on the bucket subcommands that use it, rather than repeating the same add_multilevel_option() call for each command. That would reduce some of the repetition, but it would also pull the code back toward grouping by option rather than by command, and make adding or modifying a command require touching multiple places.
So I'm leaning toward the per-command layout you suggested. Do you think that kind of deduplication is worth the tradeoff, or would you still prefer keeping each command self-contained?
There was a problem hiding this comment.
Personally I think the duplication is fine, largely because the definition of each option is very simple.
We already have shared constants for the descriptions of common parameters which I think is ok. I don't think I would even argue that the shared descriptions is even strictly necessary: its just a description, if its slightly different between commands then maybe thats fine! But as it stands now, I think having shared descriptions and duplicated definitions is unproblematic.
| bucket_limit_check->callback( | ||
| [&uid_str, &user_id_arg, &cli11_readonly, &cli11_action, | ||
| &user, &bucket_op, &stream_flusher_ptr, &warnings_only, &metadata_key] { | ||
| user_id_arg.from_str(uid_str); |
There was a problem hiding this comment.
Neither uid_str nor user_id_arg appear to be used here. but we reference user. Since uid is an option for bucket limit check rather than a global option, it is only available in this command, which suggests that the initialisation for user should happen in this function too?
I've not checked the other commands but I'd have similar concerns elsewhere, and this is why I'm interested in seeing how small we can get the list of captured variables to be in each command's lambda!
There was a problem hiding this comment.
I was looking into this and had a question about the scope of what you had in mind.
When you suggested that the user initialization should happen in the command, were you only referring to the driver->get_user(...) step, or were you thinking about moving more of the related initialization as well?
I noticed that after get_user() there's also tenant/namespace handling, and later the user id is propagated into bucket_op/user_op, so I wasn't sure where you would draw the boundary for making the command self-contained.
I can see how localizing some of this would make the command more self-contained, but I'm not sure how much of the shared initialization you were thinking of moving.
There was a problem hiding this comment.
Oh I'm just wrong, uid is one of the global options, right. Ok no in that case I think it makes sense to leave the user initialisation where it is.
Since neither uid_str nor user_id_arg are otherwise used in this callback though, does it make sense that they're set here? I see there's a shared initialisation further down in the big ceph_argparse loop. Is that not sufficient on its own? I see several of the bucket commands have this same pattern of capturing uid_str and user_id_arg just to call user_id_arg.from_str(uid_str).
7e5faf6 to
5545f5f
Compare
Add CLI11 as a submodule and parse the bucket and script commands with CLI11. Commands not yet migrated are routed to the legacy parser. Add shell test suites for the migrated commands in src/test/cli/radosgw-admin/. Signed-off-by: Rotem Shapira <[email protected]>
58804fb to
45379e0
Compare
|
@chardan Want to review some C++ modernization? |
Update the expected exit codes that changed on main: - set-min-shards now returns EINVAL (exit 22), not -EINVAL (exit 234). - The commands that returned -ENOENT now exit 2, not 254. - An unknown --access-key now exits 254 with "could not find user for access-key", as on main today. Fix comments that no longer match the rows: - Use the mapped exit codes (1 and 22), not CLI11's own codes (104, 106, 114). - An unrelated flag in space form now takes its value and is warned about; it no longer leaves the value as a stray positional. Check the "is not a valid option" warning also for the --fix and --max-entries= rows, not only the space-form rows. Signed-off-by: Rotem Shapira <[email protected]>
Return EPERM instead of a bare 1 in the CLI11 code. Exit codes don't change, since EPERM is 1. Fix the bucket rm warning to name the flag as it is spelled, --inconsistent-index, not --inconsistent_index. This changes text the user sees. Update ERR_INCONSISTENT in test_cli11_bucket.sh to match. In normalize_cli11_tokens, build the dash spelling of an underscore option with std::replace instead of a character loop, and document the underscore rewrite in the function's header comment. Explain how add_multilevel_strict_int and add_multilevel_binary_flag match the legacy parser, with a TODO for "--fix banana". Reword or remove comments as asked in review. Signed-off-by: Rotem Shapira <[email protected]>
chardan
left a comment
There was a problem hiding this comment.
I'm really happy to see these changes, it's going to make working on the utility a much more pleasant and safe experience, and pave the way to other improvements. I see that other folks have made great comments and got further into this than I did-- so I think you're definitely heading in the right direction. Thanks again for your effort on these PRs!
| #include <iostream> | ||
| #include <memory> | ||
| #include <CLI/CLI.hpp> |
There was a problem hiding this comment.
Ok. Probably a good choice, as CLI11 is flexible and mature. Some libraries involve less boilerplate and are a bit more modern in approach, but this is going to be a just tremendous improvement over what we've got now! Happy to see folks caring about this. (My experience with command-line libraries has been that slightly "stodgy" but flexible really isn't a bad thing.)
| @@ -5,11 +5,16 @@ | |||
| * Copyright (C) 2025 IBM | |||
There was a problem hiding this comment.
We might want to tweak this while we're here.
| } | ||
| }; | ||
|
|
||
| // Registers a value option at every level of the command tree: hidden on all |
There was a problem hiding this comment.
This feels like it's over-explaining..? Most of this sounds like it's the ordinary behavior of the library, are we basically re-explaining the documentation? Assume your audience has a reasonable understanding of similar command-line libraries, if not CLI11 itself.
On the other hand, perhaps better to have too much than too little. Think it over, and go with your taste.
| CLI::Option* add_multilevel_strict_int(CLI::App* cmd, const std::string& name, | ||
| T& target, std::string_view desc = {}) { | ||
| const std::string primary = name.substr(0, name.find(',')); | ||
| CLI::callback_t setter = [&target](const CLI::results_t& res) { |
There was a problem hiding this comment.
Is a Ceph setter() kind of like an Irish, English, or Gordon setter()..?
| const std::string primary = name.substr(0, name.find(',')); | ||
| CLI::callback_t setter = [&target](const CLI::results_t& res) { | ||
| std::string err; | ||
| if constexpr (std::is_same_v<T, int>) { |
There was a problem hiding this comment.
Only for int? No one will request a short, or other numeric type, etc.? I somewhat feel like if the idea is to clamp it to a range we could use std::clamp() and what not..?
chardan
left a comment
There was a problem hiding this comment.
It looks like the comments from other reviewers have been resolved-- please double check to be sure any items that really needed attention are checked over. If that's the case, I think this is very welcome. +1.
|
I read @jacquesh's threads on Two small follow-ups that I did not see in the review yet:
Optional: Thanks for the careful compatibility work on this PR. |
"bucket list --num-shards 5" warns that --num-shards is not a valid option for 'bucket list', but "bucket list --num-shards" did not. CLI11 fails on a flag with no value before storing it, so the warning check, which only looks at stored flags, never saw it. normalize_cli11_tokens now reports such a flag as missing_value_flag. warn_wrong_position_and_unrelated_option warns about it when the command does not own it. Add check_exact to test_cli11_bucket.sh: it checks the whole output line by line, so an unexpected extra warning fails the row. Add rows for an unrelated flag given last with no value, and use check_exact for four existing missing-value rows. Signed-off-by: Rotem Shapira <[email protected]>
|
This pull request can no longer be automatically merged: a rebase is needed and changes have to be manually resolved |
Summary
This PR is the first stage of modernizing
radosgw-admin's command-line interface. It incrementally migrates the argument parsing to CLI11, a modern header-only C++ command-line parsing library. This establishes a single source of truth for command definitions while making the CLI easier to maintain and enabling automatic generation of the--helpoutput and the man page.Related tracker: https://tracker.ceph.com/issues/74508
The migration focuses on preserving backwards compatibility through an incremental migration strategy, allowing migrated and legacy commands to coexist throughout the transition. This PR migrates the
scriptcommands, thebucketcommands and global option handling to CLI11. The remaining command families will be migrated incrementally in later PRs.Background
radosgw-adminhas grown to ~220 commands and ~160 flags over time.The
radosgw-adminuser-facing reference documentation, including the--helpoutput and the man page (doc/man/8/radosgw-admin.rst), is maintained manually through separate mechanisms. In practice, the documentation falls out of sync: an audit found 68 commands and 46 flags present in--helpbut missing from the man page. The--helpoutput is also limited to a single flat listing of commands and options, rather than providing context-aware, command-specific help. These issues have repeatedly affected users (e.g. tracker #40525, #12423, #58310, #44568).In addition, the command line is handled by several separate mechanisms: a long argument-parsing loop that scans the arguments and sets hundreds of local variables, initialization code that processes a subset of options before command execution, and a separate lookup that matches the command words to the operation to execute. As a result, information about commands, options, and their behavior is spread across multiple parts of the implementation, making the code harder to maintain and evolve.
Goals
Define commands and their options once, in code, and automatically generate the
--helpoutput and the man page from the same definitions.Provide hierarchical, context-aware help for individual commands.
Improve maintainability by keeping each command's definition, options, and behavior together.
Preserve backwards compatibility with the existing CLI throughout the migration.
Migrate incrementally, keeping the tool fully functional throughout the transition.
Approach
The project incrementally introduces CLI11 into
radosgw-adminto define migrated commands, their options, and their descriptions. These definitions are used for argument parsing today and will later be used to automatically generate the--helpoutput and the man page.To keep the migration safe, reviewable, and backwards compatible, each command family is migrated incrementally. The migration focuses on moving the argument parsing to CLI11 while existing command implementations are reused unchanged. For each migrated command, the set of supported options for that command is derived from the existing implementation. Command and option descriptions are reused from the existing
usage()text, and existing command metadata (for example whether a command is read-only or requires garbage collection) is preserved.For example, a migrated three-level command,
bucket logging flush, is defined in CLI11 as follows:The callback captures the existing implementation, which is invoked later, after the required setup has completed.
CLI11 parses only the commands that have been migrated. A command it does not recognize is left untouched (
allow_extras) and is handled by the existing legacy parser. Separately, the legacy flag-parsing loop still scans every flag on every run, even for migrated commands, so options are effectively parsed twice during migration; this is a transitional step, not a permanent routing mechanism, and goes away once the legacy parser is retired.Backwards Compatibility
Every command contains years of implicit behavior that users and scripts rely on. The migration therefore aims to preserve existing behavior while it is in progress.
Warnings first, errors later. Where behavior changes are introduced, they follow a gradual migration path: warnings first, with errors only after users have had time to adapt.
Any-position flags. Without compatibility requirements, a flag in CLI11 would only be recognized at the specific command level where it's registered — CLI11 rejects it outright if it appears anywhere else, such as before its subcommand. Legacy, however, parsed flags before the command was even selected, so a flag could appear before, between, or after subcommands. To preserve this, migrated flags are registered at every level of their command; when a flag appears in an unexpected position, a warning is emitted instead of an error.
Global options. Three groups:
--tenant,--uid) are being made true globals — registered once, recognized at any position. Once a flag is made global, it's accepted on every command (even ones with no semantic use for it, as the nature of a global).--conf,--id,--name,--cluster) continue to be handled by the existing early parser; CLI11 documents them in the help footer for every command.Duplicate flags. Without compatibility requirements, CLI11 would reject a flag passed more than once outright (
--bucket foo --bucket barfails to parse at all). Instead, legacy's "last value wins" behavior is preserved by explicitly configuring the option to accept repeats, now paired with a warning instead of staying silent about it.Binary flags. Without compatibility requirements, migrated binary flags could use CLI11's native boolean flags. Instead, legacy parsing behavior is preserved by registering these flags as strings and parsing them ourselves, matching how legacy handled them as integers rather than plain booleans - needed to match behavior such as
--fix false(the space-separated form). One legacy quirk is preserved as-is, but made visible:--fix=bananaused to silently set the flag to true (an invalid value was stored as an error code that happened to be truthy) - the new parser still accepts it and still treats it as true, but now emits a warning instead of failing silently.Integer parsing. Without compatibility requirements, migrated integer options could rely on CLI11's own base-detection (
0x,0,0bprefixes read as hex/octal/binary). Instead, legacy's decimal-only parsing is preserved, requiring custom parsing rather than binding directly to CLI11's integer type. Plain decimal numbers behave identically either way, but legacy also accepts inputs CLI11 would otherwise reject - for example08(an invalid octal literal to CLI11, but a valid decimal 8 to legacy), or10abc/abc(parsed as10/0by some legacy flags instead of being rejected entirely).Aliases. Existing command and option aliases continue to be supported.
Flag spelling (dashes vs. underscores). Legacy accepted both spellings of a flag interchangeably (e.g.
--check-objectsand--check_objects). Migrated flags preserve this: underscore spellings are accepted as before, with an added warning pointing to the dash form.Unrelated options. As legacy code does, on a migrated command CLI11 does not reject an option it doesn't recognize as part of that command, that is an existing option for other commands.
Unknown words. An unknown word (e.g.
banana) causes a failure on a migrated command, the same as it did in legacy.Unknown options. A truly unknown option (e.g.
--banana) is rejected on migratedcommands just as on legacy ones during the transition, the still-running legacy loop provides this rejection. once CLI11 owns the full option set, the rejection moves into the CLI11 path.
Error messages and exit codes. Migrated commands aim to match the error messages and exit codes of their legacy counterparts, but this isn't a strict guarantee in every case - some differences remain where an exact match wasn't practical.
Current Status
The migration is already underway. Several script commands, a growing subset of bucket commands, and global option handling have been migrated to CLI11, with compatibility behavior verified through existing and newly added tests
(
src/test/cli/radosgw-admin/test_cli11_*.sh).The current implementation demonstrates that migrated and legacy commands can coexist while preserving existing behavior. The incremental migration strategy has proven practical across multiple command families and global option handling, including commands with more complex compatibility requirements.
Future Work
Continue migrating the remaining command families to CLI11 using the same incremental migration strategy.
Continue refining the internal structure of the CLI implementation to improve readability, maintainability, and long-term evolution.
Revisit temporary compatibility mechanisms as the migration progresses.
Revisit the long-term organization and ownership of global option handling, evaluating whether additional categories of global options should be managed by CLI11.
Generate the
--helpoutput and man page directly from the CLI11 definitions.Disclosure: AI was used as a development aid during the implementation (research, brainstorming, code generation, and language assistance). The AI-assisted code was manually reviewed, analyzed, and refined to fit the desired design. Where needed, different implementation approaches were explored before selecting the final solution. The resulting code was validated through automated tests and manual comparison with the existing behavior.
Contribution Guidelines
To sign and title your commits, please refer to Submitting Patches to Ceph.
If you are submitting a fix for a stable branch (e.g. "quincy"), please refer to Submitting Patches to Ceph - Backports for the proper workflow.
When filling out the below checklist, you may click boxes directly in the GitHub web UI. When entering or editing the entire PR message in the GitHub web UI editor, you may also select a checklist item by adding an
xbetween the brackets:[x]. Spaces and capitalization matter when checking off items this way.Checklist
Show available Jenkins commands
jenkins test classic perfJenkins Job | Jenkins Job Definitionjenkins test crimson perfJenkins Job | Jenkins Job Definitionjenkins test signedJenkins Job | Jenkins Job Definitionjenkins test make checkJenkins Job | Jenkins Job Definitionjenkins test make check arm64Jenkins Job | Jenkins Job Definitionjenkins test submodulesJenkins Job | Jenkins Job Definitionjenkins test dashboardJenkins Job | Jenkins Job Definitionjenkins test dashboard cephadmJenkins Job | Jenkins Job Definitionjenkins test apiJenkins Job | Jenkins Job Definitionjenkins test docsReadTheDocs | Github Workflow Definitionjenkins test ceph-volume allJenkins Jobs | Jenkins Jobs Definitionjenkins test windowsJenkins Job | Jenkins Job Definitionjenkins test rook e2eJenkins Job | Jenkins Job DefinitionYou must only issue one Jenkins command per-comment. Jenkins does not understand
comments with more than one command.