-
Notifications
You must be signed in to change notification settings - Fork 363
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
Add subcommand for migrating the krew home #249
Conversation
Krew cannot re-install itself if it is uninstalled, so it must be skipped in the standard code path.
I'll try to find time to review this.
this is ok
we don't need tests for this, but we have to do quite a bit of manual verification.
this SGTM. I was assuming we can do
hmm this feels hacky. but might be OK. |
cmd/krew/cmd/root.go
Outdated
@@ -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(), |
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 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 *.yaml
s in receipts/
are zero" is cleaner and doesn't require you to do this.
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.
Yes, perfect. That'll do.
cmd/krew/cmd/system.go
Outdated
|
||
// systemCmd represents the system command | ||
var systemCmd = &cobra.Command{ | ||
Use: "system receipts-upgrade", |
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.
can't we nest subcommands? this seems a bit hacky. we should let cobra handle non-existing subcmds etc for us.
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.
Yes, good idea.
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.
don't forget to change the string :P
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.
🤦♂️
test.Krew("system", "receipts-upgrade").RunOrFailOutput() | ||
test.AssertExecutableInPATH("kubectl-" + validPlugin) | ||
|
||
assertReceiptExistsFor(test, validPlugin) |
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.
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.
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.
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?
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.
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
return nil | ||
} | ||
|
||
oldPaths := oldenvironment.MustGetKrewPaths() |
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.
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.
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.
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.
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 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.
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.
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?
It no longer fails in fresh installs.
Codecov Report
@@ 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
Continue to review full report at Codecov.
|
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()
bced34e
to
f73ba27
Compare
/approve |
/lgtm |
This PR adds a new subcommand
krew system
following the logic outlined in #232 (comment).The basic steps are:
$KREW_ROOT/store
and perform some validation on them$KREW_ROOT/bin
and the folder in$KREW_ROOT/store/<plugin>
.kubectl krew install <plugin>
if the previous steps were successfulkrew.yaml
manifest, because that cannot be re-installed (and we know that this is the correct manifest).Notes:
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.
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.
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