-
Notifications
You must be signed in to change notification settings - Fork 916
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
govc: Add -file flag to cluster.module.rm to delete a list of cluster modules read from a file #3194
Conversation
8dc4cfb
to
40d8d7d
Compare
Many thanks @bryanv for the review. I addressed the comments. I should next time not rush a PR before calling it a day 🤦 |
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.
Unless the "list in a file" is a pattern used elsewhere, consider instead the "read from stdin when -
is specified" pattern.
That's a standard unix idiom and allows for use in scripting pipelines.
When used as an isolated command either a <
redirection or a HERE document can be used to transfer a file/inline list to stdin.
continue | ||
} | ||
if err := m.DeleteModule(ctx, moduleID); err != nil { | ||
return 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.
Consider whether you want another flag to continue processing modules on error, or to ignore "unknown module" errors.
Noting because if you end up with a failure somewhere in the 10k, you cannot simply resubmit the file but have to edit it to remove all modules that have already been deleted.
Not blocking, but a nice refinement. If needing to test this the simulator has module support, see this line
We have a few cases where We already have inconsistency where some commands take just the argument needed for a single API call (such as cluster.module.rm currently), but others take N arguments and call the method N within its own loop (such as vm.destroy). We could later add helpers to apply this pattern and others such as parallel API calls, etc., to a broader set of commands. Note that we do also have a way to hide commands and flags by default: Lines 25 to 32 in ba843e5
Used with a flag here for example: govmomi/govc/library/deploy.go Lines 66 to 68 in ba843e5
|
40d8d7d
to
e17d884
Compare
|
||
func (cmd *rm) deleteModule(ctx context.Context, m *cluster.Manager, moduleID string) error { | ||
if err := m.DeleteModule(ctx, moduleID); err != nil { | ||
if cmd.ignoreNotFound && strings.HasSuffix(err.Error(), "404 Not Found") { |
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.
Wondering if we should instead export a function at the library to match the error via a typecast or similar.
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.
Meant to add, we have an issue open for this: #2521
Thanks for the great response. Using stdin also makes the implementation more clean and fulfils the same functionality 👍 I also added bats tests to cover that functionality :-) |
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.
Thanks @chrischdi , lgtm
|
||
func (cmd *rm) deleteModule(ctx context.Context, m *cluster.Manager, moduleID string) error { | ||
if err := m.DeleteModule(ctx, moduleID); err != nil { | ||
if cmd.ignoreNotFound && strings.HasSuffix(err.Error(), "404 Not Found") { |
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.
Meant to add, we have an issue open for this: #2521
Description
This PR adds a
-file
flag to thegovc cluster.module.rm
command.Deleting lots of cluster modules takes a long time.
E.g. deleting 10k cluster modules using bash and the current implementation would take ~5 mins. Example command:
With this PR the following would do the same and only take ~30s:
govc cluster.module.rm - < modules.txt
Closes: #(issue-number)
Type of change
Please mark options that are relevant:
not work as expected)
How Has This Been Tested?
Please describe the tests that you ran to verify your changes. Provide
instructions so we can reproduce. If applicable, please also list any relevant
details for your test configuration.
govc cluster.module.ls | awk '{print $2}' > modules.txt
govc cluster.module.rm -file modules.txt
Checklist:
CONTRIBUTION
guidelines of this project