Skip to content
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

Merged
merged 1 commit into from
Jul 20, 2019

Conversation

ahmetb
Copy link
Member

@ahmetb ahmetb commented Jul 18, 2019

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. 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.

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 <ahmetb@google.com>
@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. approved Indicates a PR has been approved by an approver from all required OWNERS files. labels Jul 18, 2019
@k8s-ci-robot k8s-ci-robot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Jul 18, 2019
@codecov-io
Copy link

codecov-io commented Jul 18, 2019

Codecov Report

Merging #278 into master will decrease coverage by 0.42%.
The diff coverage is 24.48%.

Impacted file tree graph

@@            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
Impacted Files Coverage Δ
pkg/installation/upgrade.go 0% <0%> (ø) ⬆️
pkg/download/verifier.go 100% <100%> (ø) ⬆️
pkg/installation/install.go 34.31% <17.39%> (+2.31%) ⬆️
pkg/installation/util.go 41.37% <87.5%> (-7.51%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 5969272...aac4bb3. Read the comment docs.

Copy link
Contributor

@corneliusweig corneliusweig left a 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.

pkg/download/verifier.go Show resolved Hide resolved
@@ -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) {
Copy link
Contributor

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?

Copy link
Member Author

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))
Copy link
Contributor

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?

Copy link
Member Author

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.

Copy link
Member Author

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
Copy link
Contributor

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 {
Copy link
Contributor

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.

Copy link
Member Author

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.

Copy link
Contributor

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)
Copy link
Contributor

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.

pkg/installation/util.go Show resolved Hide resolved
pkg/installation/install.go Show resolved Hide resolved
@corneliusweig
Copy link
Contributor

/lgtm
/approve

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jul 20, 2019
@k8s-ci-robot
Copy link
Contributor

[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:
  • OWNERS [ahmetb,corneliusweig]

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Proposal: Use semver to determine plugin versions and upgrades
4 participants