-
Notifications
You must be signed in to change notification settings - Fork 369
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
Index migration #505
Index migration #505
Conversation
This only changes the directory structure that will be needed to support custom indexes. The other changes will be in subsequent PRs.
Codecov Report
@@ Coverage Diff @@
## master #505 +/- ##
=========================================
- Coverage 58.51% 57.21% -1.3%
=========================================
Files 22 23 +1
Lines 969 991 +22
=========================================
Hits 567 567
- Misses 346 368 +22
Partials 56 56
Continue to review full report at Codecov.
|
tmpDir, cleanup := testutil.NewTempDir(t) | ||
defer cleanup() | ||
|
||
_ = os.MkdirAll(tmpDir.Path(test.dirPath), os.ModePerm) |
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.
handle err :)
internal/indexmigration/migration.go
Outdated
return err | ||
} | ||
if isMigrated { | ||
klog.Infoln("Already migrated") |
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.
please use leveled logs (e.g. klog.v(2) ) for stuff users won't see.
also "already migrated" is not a good log line by itself.
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.
Sounds good. I've seen that throughout the code base, is there some guide for what levels should be used in certain scenarios? I briefly looked through the klog repo but didn't see anything immediately.
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.
Non-leveled logs: always visible to users
Leveled logs: never visible to users, unless -v LEVEL
is specified.
We frequently use -v 2
or -v 10
etc for debugging.
So use judgement from the rest of the repo. :) If it's too off, we'll comment.
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.
Actually wouldn't we want to display to the user that the migration has already been performed?
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.
🤔 you’re right but this actually sounds like an error.
But both are fine since this is just a one off command.
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.
Ok I've already changed it to use leveled logging, so I'll just leave it that way if you think either way is cool.
internal/indexmigration/migration.go
Outdated
err = gitutil.EnsureCloned(constants.IndexURI, paths.DefaultIndexPath()) | ||
if err != nil { | ||
return err | ||
} | ||
return 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.
this simply can be returned as "errors.Wrap"
internal/indexmigration/migration.go
Outdated
func Migrate(paths environment.Paths) error { | ||
isMigrated, err := Done(paths) | ||
if err != nil { | ||
return err |
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.
we rarely do return err
in this codebase.
try errors.Wrap(err, "failed to check if index migration is complete")
internal/environment/environment.go
Outdated
// DefaultIndexPath returns the base directory where the default plugin index repository is cloned. | ||
func (p Paths) DefaultIndexPath() string { return filepath.Join(p.base, "index", "default") } |
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 feel like we don't need a method like this. Something like we eventually need to refactor this to IndexPath(name string)
.
The method above (IndexPath()
) ideally should not be necessary (except for some tests, e.g. below).
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.
Ya that makes sense, I'll remove it since this will check for the .git
directory.
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.
SGTM.
func init() { | ||
if _, ok := os.LookupEnv("X_KREW_ENABLE_MULTI_INDEX"); ok { |
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.
Maybe add the migration check behind this feature gate to the PreRunE of root as well?
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.
Sure I can add that, I didn't include the check in root to prevent other krew operations when the user hasn't migrated but it makes sense to include it in this PR
/lgtm |
/lgtm |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: ahmetb, chriskim06 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 |
} | ||
|
||
// Migrate removes the index directory and then clones krew-index to the new default index path. | ||
func Migrate(paths environment.Paths) 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.
@chriskim06 This is currently untested. I think this is mostly because the migration code has external dependencies. What about renaming the directory index -> index/default
? Then you could also test it :)
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 not sure I totally understand what you mean about renaming the directory. If you could elaborate a little more I'd love to add a unit test for this. I was thinking that this would be covered more in integration tests after looking at the receiptmigration test.
Since this has the call to gitutil.EnsureCloned
I didn't want that to be called during the unit test. Normally I would do something like using an interface for that function and a different implementation in my test that doesn't actually use git to mock that behavior, but I thought that might overcomplicate this PR.
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.
So what I was trying to say is that the function is hard to test, because it has an external dependency due to the hidden git clone. After the current function exits, the result is the same as if $ mv index index/default
was called (this is just pseudo-mv, it doesn't work like that :) ).
So if your implementation would rely on mv
instead of git-clone
, we could write a unit test for it, because file system operations are fine in unit tests. I think I'll give it a try to see if it works.
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.
Whoops, I meant to reply to this yesterday. But ya, that makes sense, I didn't think to do it that way. It does seem more testable in your PR.
This only adds the migration code to change the directory structure that will be needed to support custom indexes. The other changes will be in subsequent PRs.
I'm using the existence of the
index/default/
index/.git
directory to indicate whether or not a migration needs to be performed.Related issue: #483