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

Remove receipts migration #603

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,6 @@ jobs:
- name: Run integration tests
run: hack/run-integration-tests.sh

- name: Verify receipt migration from v0.2.x to v0.3.x
run: hack/verify-receipts-upgrade-migration.sh

- name: Create a new release
if: contains(github.ref, 'tags')
id: create_release
Expand Down
7 changes: 5 additions & 2 deletions cmd/krew/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,11 @@ func preRun(cmd *cobra.Command, _ []string) error {
if err != nil {
return err
}
if !isMigrated && cmd.Use != "receipts-upgrade" {
fmt.Fprintln(os.Stderr, "You need to perform a migration to continue using krew.\nPlease run `kubectl krew system receipts-upgrade`")
if !isMigrated {
fmt.Fprintln(os.Stderr, `This version of Krew is not supported anymore. Please manually migrate:
1. Uninstall Krew: https://krew.sigs.k8s.io/docs/user-guide/setup/uninstall/
2. Install latest Krew: https://krew.sigs.k8s.io/docs/user-guide/setup/install/
3. Install the plugins you used`)
return errors.New("krew home outdated")
}

Expand Down
19 changes: 0 additions & 19 deletions cmd/krew/cmd/system.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"github.com/spf13/cobra"

"sigs.k8s.io/krew/internal/indexmigration"
"sigs.k8s.io/krew/internal/receiptsmigration"
"sigs.k8s.io/krew/pkg/constants"
)

Expand All @@ -37,23 +36,6 @@ This command will be removed without further notice from future versions of krew
Hidden: true,
}

// TODO(corneliusweig) remove migration code with v0.4
// systemCmd represents the system command
var receiptsUpgradeCmd = &cobra.Command{
Use: "receipts-upgrade",
Short: "Perform a migration of the krew home",
Long: `Krew became more awesome! To use the new features, you need to run this
one-time migration, which will reinstall all current plugins.

This command will be removed without further notice from future versions of krew.
`,
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
return receiptsmigration.Migrate(paths)
},
PreRunE: func(_ *cobra.Command, _ []string) error { return ensureIndexesUpdated() },
}

var indexUpgradeCmd = &cobra.Command{
Use: "index-upgrade",
Short: "Perform a migration of the krew index",
Expand All @@ -72,6 +54,5 @@ func init() {
if _, ok := os.LookupEnv(constants.EnableMultiIndexSwitch); ok {
systemCmd.AddCommand(indexUpgradeCmd)
}
systemCmd.AddCommand(receiptsUpgradeCmd)
rootCmd.AddCommand(systemCmd)
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd prefer to remove the whole system command. It would make sense to do that in a follow-up PR right after this one, so that we can revert the PR lateron if we find that we need system again.
However, as long as it does nothing, there's no point in leaving it here.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ya I was planning on removing it in the follow up PR where I make the index migration automatic.

}
2 changes: 1 addition & 1 deletion cmd/krew/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ import (
)

func main() {
cmd.Execute()
defer klog.Flush()
cmd.Execute()
}
147 changes: 0 additions & 147 deletions hack/verify-receipts-upgrade-migration.sh

This file was deleted.

80 changes: 8 additions & 72 deletions integration_test/system_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,12 @@
package integrationtest

import (
"bytes"
"os"
"path/filepath"
"strings"
"testing"

"sigs.k8s.io/krew/internal/testutil"
)

func TestKrewSystem(t *testing.T) {
func TestKrewUnsupportedVersion(t *testing.T) {
skipShort(t)

test, cleanup := NewTest(t)
Expand All @@ -35,61 +32,13 @@ func TestKrewSystem(t *testing.T) {
// needs to be after initial installation
prepareOldKrewRoot(test)

test.Krew("system", "receipts-upgrade").RunOrFailOutput()
test.AssertExecutableInPATH("kubectl-" + validPlugin)

assertReceiptExistsFor(test, validPlugin)
}

func TestKrewSystem_ReceiptForKrew(t *testing.T) {
skipShort(t)

test, cleanup := NewTest(t)
defer cleanup()

prepareOldKrewRoot(test)
touch(test.tempDir, "store/krew/ensure-folder-exists")

test.WithDefaultIndex().Krew("system", "receipts-upgrade").RunOrFailOutput()

assertReceiptExistsFor(test, "krew")
}

func TestKrewSystem_IgnoreAdditionalFolders(t *testing.T) {
skipShort(t)

test, cleanup := NewTest(t)
defer cleanup()

prepareOldKrewRoot(test)

touch(test.tempDir, "store/not-a-plugin/ensure-folder-exists")
out := test.WithDefaultIndex().Krew("system", "receipts-upgrade").RunOrFailOutput()

if !bytes.Contains(out, []byte("Skipping plugin not-a-plugin")) {
t.Errorf("Expected a message that 'not-a-plugin' is skipped, but output was:")
t.Log(string(out))
// any command should fail here
out, err := test.Krew("list").Run()
if err == nil {
t.Error("krew should fail when old receipts structure is detected")
}
}

func TestKrewSystem_IgnoreUnknownPlugins(t *testing.T) {
skipShort(t)

test, cleanup := NewTest(t)
defer cleanup()

test.Krew("install",
"--manifest", filepath.Join("testdata", "foo.yaml"),
"--archive", filepath.Join("testdata", "foo.tar.gz")).
RunOrFail()

prepareOldKrewRoot(test)

out := test.WithDefaultIndex().Krew("system", "receipts-upgrade").RunOrFailOutput()

if !bytes.Contains(out, []byte("Skipping plugin foo")) {
t.Errorf("Expected a message that 'foo' is skipped, but output was:")
t.Log(string(out))
if !strings.Contains(string(out), "Uninstall Krew") {
t.Errorf("output should contain instructions on upgrading: %s", string(out))
}
}

Expand All @@ -99,16 +48,3 @@ func prepareOldKrewRoot(test *ITest) {
test.t.Fatal(err)
}
}

func assertReceiptExistsFor(it *ITest, plugin string) {
receipt := "receipts/" + plugin + ".yaml"
_, err := os.Lstat(it.tempDir.Path(receipt))
if err != nil {
it.t.Errorf("Expected plugin receipt %q but found none.", receipt)
}
}

// touch creates a file without content in the temporary directory.
func touch(td *testutil.TempDir, file string) {
td.Write(file, nil)
}
Loading