Skip to content

Commit

Permalink
Avoid uselessly trying to migrate plugins
Browse files Browse the repository at this point in the history
The only time we need to migrate context-scope plugins is after moving
from a CLI < 1.3 to a newer one.  This commit makes use of the existing
global initializer to do this migration once, for all contexts.

This avoids an unnecessary slow down for every CLI commands, especially
shell completion which should be as fast as possible.

Signed-off-by: Marc Khouzam <[email protected]>
  • Loading branch information
marckhouzam committed Nov 28, 2024
1 parent 92c98e8 commit 92fa8ed
Show file tree
Hide file tree
Showing 5 changed files with 408 additions and 248 deletions.
20 changes: 8 additions & 12 deletions pkg/catalog/cleanup.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
package catalog

import (
configlib "github.com/vmware-tanzu/tanzu-plugin-runtime/config"
configtypes "github.com/vmware-tanzu/tanzu-plugin-runtime/config/types"
)

Expand Down Expand Up @@ -47,27 +46,24 @@ func DeleteIncorrectPluginEntriesFromCatalog() {
}

// MigrateContextPluginsAsStandaloneIfNeeded updates the catalog cache to move all the
// context-scoped plugins associated with the active context as standalone plugins
// context-scoped plugins as standalone plugins
// and removes the context-scoped plugin mapping from the catalog cache.
// This is to ensure backwards compatibility when user migrates from pre v1.3 version of
// the CLI, the context-scoped plugins are still gets shown as installed
// This is to ensure backwards compatibility when the user migrates from pre v1.3 version of
// the CLI, the context-scoped plugins are still shown as installed
func MigrateContextPluginsAsStandaloneIfNeeded() {
activeContexts, err := configlib.GetAllActiveContextsList()
if err != nil || len(activeContexts) == 0 {
return
}

c, lockedFile, err := getCatalogCache(true)
if err != nil {
return
}
defer lockedFile.Close()

for _, ac := range activeContexts {
for pluginKey, installPath := range c.ServerPlugins[ac] {
for _, association := range c.ServerPlugins {
for pluginKey, installPath := range association {
c.StandAlonePlugins.Add(pluginKey, installPath)
}
delete(c.ServerPlugins, ac)
}
// Delete all entries by reassigning to a new empty map
c.ServerPlugins = make(map[string]PluginAssociation)

_ = saveCatalogCache(c, lockedFile)
}
Loading

0 comments on commit 92fa8ed

Please sign in to comment.