-
Notifications
You must be signed in to change notification settings - Fork 7.5k
fix(plugins): reset cache repo modifications before update #31678
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
base: main
Are you sure you want to change the base?
Conversation
Signed-off-by: OlTrenin <[email protected]>
8deffea to
f7e2f40
Compare
| func resetRepo(repo vcs.Repo) error { | ||
| // Check the VCS type to determine the appropriate reset command | ||
| switch repo.Vcs() { | ||
| case vcs.Git: |
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 can see how this will work, but ideally, vcs should add this I would think.
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.
Also, if plugin.yaml is the only problem, maybe just reset that one file.
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.
@TerryHowe hi, okey, I have improved by your comment's 😉
Signed-off-by: OlTrenin <[email protected]>
|
I tested the change locally, and it does fix the failure. I’m not sure about resetting the repository during an update, but it seems like the simplest approach. I’m a bit worried we might miss something when resetting this cache folder. I’m also wondering whether the reset logic should be extracted into a separate function so we can reuse it. |
Thanks for the review! The concerns you raised have already been addressed in the second commit (98598c6):
The cache folder is managed by Helm internally, so resetting this specific file is safe |
|
My concerns stem from your last proposal. I’m wondering whether we still want to keep the change in 1e8ebae. Another option could be to stop checking the dirty state altogether. 🤷
I was thinking about extracting the reset mechanism itself into a generic function that accepts a path and the VCS. So function does less and that way, we could easily reuse it to reset other files in other locations. That said, this might be premature optimization. |
Good point, but I agree it's premature optimization for now. We can always generalize it later if we need to reset other files. Keeping it simple for this PR or should I implement it? |
|
I'm curious about what @gjenkins8 is thinking about this PR. |
Description
This PR fixes the plugin update failure issue where Helm reports "plugin repo was modified" error even when users haven't made any manual modifications to the plugin repository.
Closes #31664
What this PR does / why we need it:
During plugin installation, Helm modifies the
plugin.yamlfile in the cached git repository (located at$HOME/.local/share/helm/cache/plugins/). When users attempt to update the plugin later, theUpdate()function checks if the repository is dirty and returns an error if any modifications are detected. This prevents plugin updates from succeeding.This PR automatically resets local modifications in the cached repository before attempting to update. Since the cached repository is managed entirely by Helm and should not contain user modifications, this is a safe operation that allows updates to proceed successfully.
Changes:
resetRepo()function that discards local modifications using VCS-specific commands (git reset, hg revert, etc.)Update()to automatically reset the cache repository if it's dirty before pulling updatesSpecial notes for your reviewer:
~/.local/share/helm/cache/plugins/), not the actual plugin directory (~/.local/share/helm/plugins/) where users might make local modificationsresetRepo()function supports all VCS types that Helm supports: Git, Mercurial, Bazaar, and SVNIf applicable:
docs neededlabel should be applied if so)TestResetRepo()to test the reset functionalityTestVCSInstallerUpdate()to verify automatic reset during updatesTesting:
The fix was tested with:
TestResetRepo()verifies git reset works correctlyTestVCSInstallerUpdate()confirms updates succeed after modificationsReproducing the original issue (before this PR):
helm plugin install https://github.com/helm-unittest/helm-unittest.git helm plugin update unittest # Error: failed to update plugin unittest, got error (plugin repo was modified) After this PR: helm plugin install https://github.com/helm-unittest/helm-unittest.git helm plugin update unittest