Skip to content

Commit 38c406f

Browse files
committed
Enhance plugin installation UX
PR updates the plugin installation UX, - As part of plugin installation in-progress message, it adds total plugins needs to installed and the number of plugins being installed The in-progress message will disappear once the installation completes. Next plugin in-progress will be shown. - No log messages will be showed once the plugin installation completes.
1 parent 68ce55d commit 38c406f

2 files changed

Lines changed: 51 additions & 24 deletions

File tree

pkg/pluginmanager/essentials.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ func installPluginsFromEssentialPluginGroup(name, version string) (string, error
6969
if err != nil {
7070
return "", fmt.Errorf("failed to install plugins from group: %w", err)
7171
}
72+
log.Successf("successfully installed all plugins from group '%s'", groupWithVersion)
7273

7374
// If the installation is successful, return the group with version.
7475
return groupWithVersion, nil

pkg/pluginmanager/manager.go

Lines changed: 50 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ const (
5858
errorNoActiveContexForGivenContextType = "there is no active context for the given context type `%v`"
5959
)
6060

61+
var totalPluginsToInstall = 0
62+
var pluginsInstalled = 0
6163
var execCommand = exec.Command
6264

6365
type DeletePluginOptions struct {
@@ -609,24 +611,30 @@ func InstallPluginsFromGroup(pluginName, groupIDAndVersion string, options ...Pl
609611
// InstallPluginsFromGivenPluginGroup installs either the specified plugin or all plugins from given plugin group plugins.
610612
func InstallPluginsFromGivenPluginGroup(pluginName, groupIDAndVersion string, pg *plugininventory.PluginGroup) (string, error) {
611613
numErrors := 0
612-
numInstalled := 0
613614
mandatoryPluginsExist := false
614615
pluginExist := false
616+
pluginsInstalled = 0
617+
618+
pluginsToInstall := make([]*plugininventory.PluginGroupPluginEntry, 0)
615619
for _, plugin := range pg.Versions[pg.RecommendedVersion] {
616620
if pluginName == cli.AllPlugins || pluginName == plugin.Name {
617621
pluginExist = true
618622
if plugin.Mandatory {
619623
mandatoryPluginsExist = true
620-
err := InstallStandalonePlugin(plugin.Name, plugin.Version, plugin.Target)
621-
if err != nil {
622-
numErrors++
623-
log.Warningf("unable to install plugin '%s': %v", plugin.Name, err.Error())
624-
} else {
625-
numInstalled++
626-
}
624+
pluginsToInstall = append(pluginsToInstall, plugin) // Add mandatory plugin to the slice
627625
}
628626
}
629627
}
628+
totalPluginsToInstall = len(pluginsToInstall)
629+
for _, plugin := range pluginsToInstall {
630+
err := InstallStandalonePlugin(plugin.Name, plugin.Version, plugin.Target)
631+
if err != nil {
632+
numErrors++
633+
log.Warningf("unable to install plugin '%s': %v", plugin.Name, err.Error())
634+
} else {
635+
pluginsInstalled++
636+
}
637+
}
630638

631639
if !pluginExist {
632640
return groupIDAndVersion, fmt.Errorf("plugin '%s' is not part of the group '%s'", pluginName, groupIDAndVersion)
@@ -643,7 +651,7 @@ func InstallPluginsFromGivenPluginGroup(pluginName, groupIDAndVersion string, pg
643651
return groupIDAndVersion, fmt.Errorf("could not install %d plugin(s) from group '%s'", numErrors, groupIDAndVersion)
644652
}
645653

646-
if numInstalled == 0 {
654+
if pluginsInstalled == 0 {
647655
return groupIDAndVersion, fmt.Errorf("plugin '%s' is not part of the group '%s'", pluginName, groupIDAndVersion)
648656
}
649657

@@ -744,7 +752,10 @@ func installOrUpgradePlugin(p *discovery.Discovered, version string, installTest
744752
}
745753

746754
// Log message based on different installation conditions
747-
installingMsg, installedMsg, errMsg := getPluginInstallationMessage(p, version, plugin != nil, isPluginAlreadyInstalled)
755+
installingMsg, _, errMsg := getPluginInstallationMessage(p, version, plugin != nil, isPluginAlreadyInstalled)
756+
757+
installingMsg = fmt.Sprintf("[%v/%v] %v", pluginsInstalled, totalPluginsToInstall, installingMsg)
758+
errMsg = fmt.Sprintf("[%v/%v] %v", pluginsInstalled, totalPluginsToInstall, errMsg)
748759

749760
var spinner component.OutputWriterSpinner
750761

@@ -762,8 +773,7 @@ func installOrUpgradePlugin(p *discovery.Discovered, version string, installTest
762773
// Initialize the spinner
763774
spinner = component.NewOutputWriterSpinner(component.WithOutputStream(os.Stderr),
764775
component.WithSpinnerText(installingMsg),
765-
component.WithSpinnerStarted(),
766-
component.WithSpinnerFinalText(installedMsg, log.LogTypeINFO))
776+
component.WithSpinnerStarted())
767777

768778
defer spinner.StopSpinner()
769779

@@ -1154,29 +1164,45 @@ func UpdatePluginsInstallationStatus(plugins []discovery.Discovered) {
11541164
// InstallDiscoveredContextPlugins installs the given context scope plugins
11551165
func InstallDiscoveredContextPlugins(plugins []discovery.Discovered) error {
11561166
var errList []error
1157-
var err error
1158-
installed := false
1167+
1168+
// Slice to capture plugins to install
1169+
var pluginsToInstall []discovery.Discovered
1170+
11591171
UpdatePluginsInstallationStatus(plugins)
1172+
1173+
// Capture plugins that need install/update
11601174
for idx := range plugins {
1161-
if plugins[idx].Status == common.PluginStatusNotInstalled || plugins[idx].Status == common.PluginStatusUpdateAvailable {
1162-
installed = true
1163-
p := plugins[idx]
1164-
err = InstallPluginFromContext(p.Name, p.RecommendedVersion, p.Target, p.ContextName)
1165-
if err != nil {
1166-
errList = append(errList, err)
1167-
}
1175+
if plugins[idx].Status == common.PluginStatusNotInstalled ||
1176+
plugins[idx].Status == common.PluginStatusUpdateAvailable {
1177+
pluginsToInstall = append(pluginsToInstall, plugins[idx])
11681178
}
11691179
}
1170-
err = kerrors.NewAggregate(errList)
1180+
totalPluginsToInstall = len(pluginsToInstall)
1181+
// Now install captured plugins
1182+
for idx := range pluginsToInstall {
1183+
err := InstallPluginFromContext(pluginsToInstall[idx].Name, pluginsToInstall[idx].RecommendedVersion, pluginsToInstall[idx].Target, pluginsToInstall[idx].ContextName)
1184+
if err != nil {
1185+
errList = append(errList, err)
1186+
} else {
1187+
pluginsInstalled++
1188+
}
1189+
}
1190+
1191+
// Aggregate errors
1192+
err := kerrors.NewAggregate(errList)
11711193
if err != nil {
11721194
return err
11731195
}
11741196

1175-
if !installed {
1197+
// Output install status
1198+
if len(pluginsToInstall) == 0 {
11761199
log.Info("All required plugins are already installed and up-to-date")
1200+
} else if pluginsInstalled == totalPluginsToInstall {
1201+
log.Infof("Successfully installed all required %v plugins", pluginsInstalled)
11771202
} else {
1178-
log.Info("Successfully installed all required plugins")
1203+
log.Infof("Successfully installed %v of %v required plugins", pluginsInstalled, totalPluginsToInstall)
11791204
}
1205+
11801206
return nil
11811207
}
11821208

0 commit comments

Comments
 (0)