-
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
Automatic index migration #607
Merged
k8s-ci-robot
merged 8 commits into
kubernetes-sigs:master
from
chriskim06:automatic-index-migration
Jun 10, 2020
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
f5c19b0
Make migration automatic and remove system cmd
chriskim06 016c8f8
Fix typo
chriskim06 b3825b6
Add integration test for no migration scenario
chriskim06 e2c3b0a
Check for existence of default dir in test
chriskim06 bacad93
Fix linting error
chriskim06 5cbc832
Code review changes
chriskim06 424493c
Code review changes
chriskim06 1521b2b
Code review changes
chriskim06 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,8 +19,26 @@ import ( | |
"os" | ||
"strings" | ||
"testing" | ||
|
||
"sigs.k8s.io/krew/pkg/constants" | ||
) | ||
|
||
func TestKrewIndexAutoMigration(t *testing.T) { | ||
skipShort(t) | ||
|
||
test, cleanup := NewTest(t) | ||
defer cleanup() | ||
|
||
test.WithEnv(constants.EnableMultiIndexSwitch, 1).WithDefaultIndex() | ||
prepareOldIndexLayout(test) | ||
|
||
// any command here should cause the index migration to occur | ||
test.Krew("index", "list").RunOrFail() | ||
if !isIndexMigrated(test) { | ||
t.Error("index should have been auto-migrated") | ||
} | ||
} | ||
|
||
func TestKrewUnsupportedVersion(t *testing.T) { | ||
skipShort(t) | ||
|
||
|
@@ -42,6 +60,28 @@ func TestKrewUnsupportedVersion(t *testing.T) { | |
} | ||
} | ||
|
||
func isIndexMigrated(it *ITest) bool { | ||
indexPath := it.TempDir().Path("index/default") | ||
_, err := os.Stat(indexPath) | ||
return err == nil | ||
} | ||
|
||
// TODO remove when testing indexmigration is no longer necessary | ||
func prepareOldIndexLayout(it *ITest) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is this something we should eventually delete? |
||
indexPath := it.TempDir().Path("index/default") | ||
tmpPath := it.TempDir().Path("tmp_index") | ||
newPath := it.TempDir().Path("index") | ||
if err := os.Rename(indexPath, tmpPath); err != nil { | ||
it.t.Fatal(err) | ||
} | ||
if err := os.Remove(newPath); err != nil { | ||
it.t.Fatal(err) | ||
} | ||
if err := os.Rename(tmpPath, newPath); err != nil { | ||
it.t.Fatal(err) | ||
} | ||
} | ||
|
||
func prepareOldKrewRoot(test *ITest) { | ||
// receipts are not present in old krew home | ||
if err := os.RemoveAll(test.tempDir.Path("receipts")); err != nil { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
it seems indexmigration.Migrate already has the check and return:
krew/internal/indexmigration/migration.go
Lines 37 to 46 in ea01855
so we're duplicating
indexmigration.Done
call here.also try adding as many log statements around this path as you can ("detected migration needed, starting..." etc).
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.
Ah good catch!
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.
Should this logging be leveled or always displayed to the user? The confirmation at the end was displayed to the user back when this was a manual process through
system index-upgrade
but now that its automatic should this happen at some log level and be silent normally?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 can show the one-time operations like these to the user (after all they would be shown only "once"):