Skip to content
Permalink
Browse files

Fix upgrade if a plugin installed from manifest (#458)

* Fix upgrade if a plugin installed from manifest

* Dry testdata
  • Loading branch information
ferhatelmas authored and k8s-ci-robot committed Jan 9, 2020
1 parent 40d6289 commit d3103f3b3d044da1973b753835433964c35c2610
Showing with 41 additions and 10 deletions.
  1. +13 −10 cmd/krew/cmd/upgrade.go
  2. +28 −0 integration_test/upgrade_test.go
@@ -64,27 +64,30 @@ kubectl krew upgrade foo bar"`,
for _, name := range pluginNames {
plugin, err := indexscanner.LoadPluginByName(paths.IndexPluginsPath(), name)
if err != nil {
if os.IsNotExist(err) {
if !os.IsNotExist(err) {
return errors.Wrapf(err, "failed to load the plugin manifest for plugin %s", name)
} else if !skipErrors {
return errors.Errorf("plugin %q does not exist in the plugin index", name)
}
return errors.Wrapf(err, "failed to load the plugin manifest for plugin %s", name)
}

fmt.Fprintf(os.Stderr, "Upgrading plugin: %s\n", plugin.Name)
err = installation.Upgrade(paths, plugin)
if ignoreUpgraded && err == installation.ErrIsAlreadyUpgraded {
fmt.Fprintf(os.Stderr, "Skipping plugin %s, it is already on the newest version\n", plugin.Name)
continue
if err == nil {
fmt.Fprintf(os.Stderr, "Upgrading plugin: %s\n", name)
err = installation.Upgrade(paths, plugin)
if ignoreUpgraded && err == installation.ErrIsAlreadyUpgraded {
fmt.Fprintf(os.Stderr, "Skipping plugin %s, it is already on the newest version\n", name)
continue
}
}
if err != nil {
nErrors++
if skipErrors {
fmt.Fprintf(os.Stderr, "WARNING: failed to upgrade plugin %q, skipping (error: %v)\n", plugin.Name, err)
fmt.Fprintf(os.Stderr, "WARNING: failed to upgrade plugin %q, skipping (error: %v)\n", name, err)
continue
}
return errors.Wrapf(err, "failed to upgrade plugin %q", plugin.Name)
return errors.Wrapf(err, "failed to upgrade plugin %q", name)
}
fmt.Fprintf(os.Stderr, "Upgraded plugin: %s\n", plugin.Name)
fmt.Fprintf(os.Stderr, "Upgraded plugin: %s\n", name)
internal.PrintSecurityNotice()
}
if nErrors > 0 {
@@ -75,6 +75,34 @@ func TestKrewUpgradeWhenPlatformNoLongerMatches(t *testing.T) {
}
}

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

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

test.WithIndex().
Krew("install", validPlugin).
RunOrFail()

validPluginPath := filepath.Join(test.Root(), "index", "plugins", validPlugin+constants.ManifestExtension)
if err := os.Remove(validPluginPath); err != nil {
t.Fatalf("can't remove valid plugin from index: %q", validPluginPath)
}

// if upgrading 'all' plugins, must succeed
out := string(test.Krew("upgrade", "--no-update-index").RunOrFailOutput())
if !strings.Contains(out, "WARNING: Some plugins failed to upgrade") {
t.Fatalf("upgrade all plugins output doesn't contain warnings about failed plugins:\n%s", out)
}

// if upgrading a specific plugin, it must fail, because it's not included into index
err := test.Krew("upgrade", validPlugin, "--no-update-index").Run()
if err == nil {
t.Fatal("expected failure when upgraded a specific plugin that is not included in index")
}
}

func resolvePluginSymlink(test *ITest, plugin string) string {
test.t.Helper()
linkToPlugin, err := test.LookupExecutable("kubectl-" + plugin)

0 comments on commit d3103f3

Please sign in to comment.
You can’t perform that action at this time.