-
Notifications
You must be signed in to change notification settings - Fork 368
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
Refactor upgrade machinery to use semver versions #278
Conversation
This change starts using semver version of plugin manifests to: - determine if upgrade is needed - determine if a plugin is installed by looking at receipts installation directory. Other commands are probably not yet using receipts entirely. Signed-off-by: Ahmet Alp Balkan <[email protected]>
Codecov Report
@@ Coverage Diff @@
## master #278 +/- ##
==========================================
- Coverage 55.34% 54.91% -0.43%
==========================================
Files 19 19
Lines 880 874 -6
==========================================
- Hits 487 480 -7
- Misses 337 341 +4
+ Partials 56 53 -3
Continue to review full report at Codecov.
|
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.
Well.. this is not pretty, but it looks mostly fine. I have only found minor things.
However, 24% diff coverage is really sad. I can see that these changes are not testable at the moment, but we need to think what to do about it. Ideally, we should add more integration tests, as they are reasonably fast. Then we can follow up with some more refactorings.
@@ -41,7 +41,7 @@ const ( | |||
krewPluginName = "krew" | |||
) | |||
|
|||
func downloadAndMove(version, uri string, fos []index.FileOperation, downloadPath, installPath, forceDownloadFile string) (dst string, err error) { | |||
func downloadAndMove(version, sha256sum, uri string, fos []index.FileOperation, downloadPath, installPath, forceDownloadFile string) (dst string, err 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.
7 arguments? I hope this is a very very private function. Can you add a todo so we get reminded that this needs to be refactored?
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.
The TODO is already at getDownloadTarget
(see that method's diff). Once that's fixed we'd be just passing the returned struct here to simplify.
return err | ||
} | ||
if ok { | ||
_, err := receipt.Load(p.PluginInstallReceiptPath(plugin.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.
As you are discarding the return value, could you also do a simpler Lstat
?
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 think we need a receipt.Exists
. Let's add 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.
On a second thought, I'm thinking if an empty file named plugin.yaml exists instead of the actual receipt, despite being harmless today, it might complicate things.
This doesn't have a lot of cost. Can we keep?
|
||
func getDownloadTarget(index index.Plugin) (version, uri string, fos []index.FileOperation, bin string, err error) { | ||
func getDownloadTarget(index index.Plugin) (version, sha256sum, uri string, fos []index.FileOperation, bin string, err error) { | ||
// TODO(ahmetb): We have many return values from this method, indicating |
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 !installed { | ||
return ErrIsNotInstalled | ||
|
||
if _, err := receipt.Load(p.PluginInstallReceiptPath(name)); err != nil { |
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.
Again, a simpler Lstat
would do.
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'm inclined to keep this as is. If receipt cannot be parsed during uninstallation, that points to a problem and we should probably stop.
In the future we might introduce a field like status.originIndex
(or like status.installPath
) to determine the installation path. So we'll actually need to use the receipt, soon.
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.
Yeah, that makes sense. Then let's keep it as is.
@@ -137,10 +140,10 @@ func Uninstall(p environment.Paths, name string) error { | |||
if err := os.RemoveAll(pluginInstallPath); err != nil { | |||
return errors.Wrapf(err, "could not remove plugin directory %q", pluginInstallPath) | |||
} | |||
PluginInstallReceiptPath := p.PluginInstallReceiptPath(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.
Woops.. I should have caught this in the review.
/lgtm |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: ahmetb, corneliusweig The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
This change starts using semver version of plugin manifests to:
by looking at receipts installation directory. It doesn't help with other commands just yet.
This fixes #166, and helps with #277 partially.
Other commands are probably not yet using receipts entirely.