Skip to content

Commit 92fa8ed

Browse files
committed
Avoid uselessly trying to migrate plugins
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 <marc.khouzam@broadcom.com>
1 parent 92c98e8 commit 92fa8ed

5 files changed

Lines changed: 408 additions & 248 deletions

File tree

pkg/catalog/cleanup.go

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
package catalog
55

66
import (
7-
configlib "github.com/vmware-tanzu/tanzu-plugin-runtime/config"
87
configtypes "github.com/vmware-tanzu/tanzu-plugin-runtime/config/types"
98
)
109

@@ -47,27 +46,24 @@ func DeleteIncorrectPluginEntriesFromCatalog() {
4746
}
4847

4948
// MigrateContextPluginsAsStandaloneIfNeeded updates the catalog cache to move all the
50-
// context-scoped plugins associated with the active context as standalone plugins
49+
// context-scoped plugins as standalone plugins
5150
// and removes the context-scoped plugin mapping from the catalog cache.
52-
// This is to ensure backwards compatibility when user migrates from pre v1.3 version of
53-
// the CLI, the context-scoped plugins are still gets shown as installed
51+
// This is to ensure backwards compatibility when the user migrates from pre v1.3 version of
52+
// the CLI, the context-scoped plugins are still shown as installed
5453
func MigrateContextPluginsAsStandaloneIfNeeded() {
55-
activeContexts, err := configlib.GetAllActiveContextsList()
56-
if err != nil || len(activeContexts) == 0 {
57-
return
58-
}
59-
6054
c, lockedFile, err := getCatalogCache(true)
6155
if err != nil {
6256
return
6357
}
6458
defer lockedFile.Close()
6559

66-
for _, ac := range activeContexts {
67-
for pluginKey, installPath := range c.ServerPlugins[ac] {
60+
for _, association := range c.ServerPlugins {
61+
for pluginKey, installPath := range association {
6862
c.StandAlonePlugins.Add(pluginKey, installPath)
6963
}
70-
delete(c.ServerPlugins, ac)
7164
}
65+
// Delete all entries by reassigning to a new empty map
66+
c.ServerPlugins = make(map[string]PluginAssociation)
67+
7268
_ = saveCatalogCache(c, lockedFile)
7369
}

0 commit comments

Comments
 (0)