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

Add subcommand for migrating the krew home #249

Merged
merged 13 commits into from
Jul 14, 2019

Conversation

corneliusweig
Copy link
Contributor

This PR adds a new subcommand krew system following the logic outlined in #232 (comment).

The basic steps are:

  • add a check to detect if the krew home needs to be migrated. This check runs before every command.
  • add migration logic
    • build list of plugins by looking at the folders in $KREW_ROOT/store and perform some validation on them
    • remove the link in $KREW_ROOT/bin and the folder in $KREW_ROOT/store/<plugin>.
    • call kubectl krew install <plugin> if the previous steps were successful
  • manually copy over the krew.yaml manifest, because that cannot be re-installed (and we know that this is the correct manifest).

Notes:

  1. I'm not 100% happy with the method how we detect an outdated krew home. One major drawback is that new users will have to run the migration as the very first thing.

  2. So far, I didn't implement as many component tests as I normally would. However this is throw-away code and covered by integration tests. So I think this is acceptable.

  3. Because we want to make the migration code independent from the main logic, I duplicated a lot of code (mainly from pkg/installation/install.go). This was intentional.

Close #232

@k8s-ci-robot k8s-ci-robot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. approved Indicates a PR has been approved by an approver from all required OWNERS files. labels Jul 9, 2019
@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Jul 9, 2019
@ahmetb
Copy link
Member

ahmetb commented Jul 10, 2019

I'll try to find time to review this.

  • I'm not 100% happy with the method how we detect an outdated krew home. One major drawback is that new users will have to run the migration as the very first thing.

this is ok

  • So far, I didn't implement as many component tests as I normally would. However this is throw-away code and covered by integration tests. So I think this is acceptable.

we don't need tests for this, but we have to do quite a bit of manual verification.

  • add migration logic

    • build list of plugins by looking at the folders in $KREW_ROOT/store and perform some validation on them
    • remove the link in $KREW_ROOT/bin and the folder in $KREW_ROOT/store/<plugin>.
    • call kubectl krew install <plugin> if the previous steps were successful

this SGTM. I was assuming we can do krew uninstall but we can’t. Makes sense.

  • manually copy over the krew.yaml manifest, because that cannot be re-installed (and we know that this is the correct manifest).

hmm this feels hacky. but might be OK.

@@ -69,7 +79,9 @@ func init() {
paths.DownloadPath(),
paths.InstallPath(),
paths.BinPath(),
paths.InstallReceiptPath()); err != nil {
// TODO(corneliusweig): re-enable when migration code is removed:
// paths.InstallReceiptPath(),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you can still enable it.
We just need to find a different way to detect. An example could be: :the number of directories in store/ are non-zero but *.yamls in receipts/ are zero" is cleaner and doesn't require you to do this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, perfect. That'll do.

cmd/krew/cmd/system.go Outdated Show resolved Hide resolved

// systemCmd represents the system command
var systemCmd = &cobra.Command{
Use: "system receipts-upgrade",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can't we nest subcommands? this seems a bit hacky. we should let cobra handle non-existing subcmds etc for us.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, good idea.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't forget to change the string :P

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤦‍♂️

cmd/krew/cmd/system.go Outdated Show resolved Hide resolved
test.Krew("system", "receipts-upgrade").RunOrFailOutput()
test.AssertExecutableInPATH("kubectl-" + validPlugin)

assertReceiptExistsFor(test, validPlugin)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: should this be part of ITest? this way you can do:

test.assertReceiptExistsFor(test, validPlugin) just like test.AssertExecutableInPATH("kubectl-" + validPlugin)

also note that it's inconsistent one is exported, the other one isn't.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That depends on whether we want to keep that assertion method. Also, I would consider receipts more of an implementation detail. It's necessary to assert on them in the current test-case, but should we encourage doing so in other integration tests?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in that case we should add a TODO to all these tests + helpers to remove them after the migration code is scrubbed.

pkg/migration/migration.go Outdated Show resolved Hide resolved
pkg/migration/migration.go Outdated Show resolved Hide resolved
return nil
}

oldPaths := oldenvironment.MustGetKrewPaths()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we need oldenvironment package?

Can't we just get KREW_ROOT from the current environment pkg and do filepath.Join(root, "store") etc? This oldenvironment adds a lot of code, I recommend just going for straight brain surgery on version==0.2.x assumption here and "assume" paths.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My thinking was

  • it eases review, because one can do file-diff.
  • I don't have to bother about correctness wrt KREW_ROOT or so, because it's all tried and tested.
  • it raises the abstraction level of the migration code.

Granted, it adds more code than necessary, but it's going to be deleted anyways.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm OK with it. Don't forget to add TODOs to the methods and packages we must delete. Granted, we'll probably delete this code in v0.4.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My hope was that we simply revert the whole commit. I find todos on every method a little excessive (especially since I'm not a big fan of todos). Can we take a middle ground where there's only one todo for a whole package, when the package should be deleted, and one todo for a function outside of such packages?

@codecov-io
Copy link

codecov-io commented Jul 11, 2019

Codecov Report

Merging #249 into master will increase coverage by 0.16%.
The diff coverage is 54.68%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #249      +/-   ##
==========================================
+ Coverage    53.6%   53.76%   +0.16%     
==========================================
  Files          16       18       +2     
  Lines         735      863     +128     
==========================================
+ Hits          394      464      +70     
- Misses        289      342      +53     
- Partials       52       57       +5
Impacted Files Coverage Δ
pkg/receiptsmigration/migration.go 48.14% <48.14%> (ø)
...kg/receiptsmigration/oldenvironment/environment.go 90% <90%> (ø)

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 7b2c944...f73ba27. Read the comment docs.

pkg/testutil/tempdir.go Outdated Show resolved Hide resolved
@ahmetb
Copy link
Member

ahmetb commented Jul 11, 2019

I think at this point we should probably just do manual testing.

- add todos to mark packages and functions for removal
- move `Touch` function out of tempdir.go
- fix `Use` field in system command
- remove obsolete consistency check before uninstall/reinstall
- no need to create the receipts directory during migration as this is created by cmd/krew/cmd/root.go:init()
@corneliusweig corneliusweig changed the title [WIP] Add subcommand for migrating the krew home Add subcommand for migrating the krew home Jul 11, 2019
@k8s-ci-robot k8s-ci-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jul 11, 2019
@ahmetb
Copy link
Member

ahmetb commented Jul 12, 2019

/approve
I added #255 that addresses the need for a script that ensures as we refactor more parts, the migration works. PTAL.

@ahmetb
Copy link
Member

ahmetb commented Jul 14, 2019

/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 14, 2019
@k8s-ci-robot

This comment has been minimized.

@k8s-ci-robot k8s-ci-robot merged commit 5042800 into kubernetes-sigs:master Jul 14, 2019
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/XL Denotes a PR that changes 500-999 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Migrate krew home to add install receipts for installed plugins
4 participants