Skip to content
This repository has been archived by the owner on Oct 10, 2023. It is now read-only.

Discover Plugins from all active contexts and Support Plugin Name conflicts across different Targets #3961

Merged
merged 24 commits into from
Nov 30, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
6b1e347
Use CLIPlugin CR to determine ContextType of the plugin
anujc25 Oct 31, 2022
6820453
Update catalog and plugin manager implementation to include ContextType
anujc25 Nov 10, 2022
8554c75
Add target for standalone plugins CLIPlugin resources
anujc25 Nov 18, 2022
d27fff7
Update implementations of builder plugin to include target in generat…
anujc25 Nov 18, 2022
050fcd0
Add rename to target comment
anujc25 Nov 19, 2022
6c58f54
Update docs
anujc25 Nov 20, 2022
646c683
Address Review Comments
anujc25 Nov 22, 2022
12b1365
Make k8s a special target and remove duplicated plugin from available…
anujc25 Nov 21, 2022
d8f5316
Address Review Comments Part-2
anujc25 Nov 23, 2022
b7fbdc2
Use Context based SplitView to list plugins
anujc25 Nov 23, 2022
82eb1a4
Use Target based SplitView to list contexts
anujc25 Nov 23, 2022
3462917
Address Review Comments Part-3
anujc25 Nov 28, 2022
cccd240
Use underscore as delimeter for pluginName_Target key in catalog
anujc25 Nov 28, 2022
6c93e9b
Fix plugin deletion issue
anujc25 Nov 28, 2022
22c5e12
Update CLIPlugin CRD to 'cliplugins' and 'core-management-plugins' pa…
anujc25 Nov 28, 2022
54bedbb
Address Comments from Demo
anujc25 Nov 29, 2022
de62436
Address Review Comments Part-4
anujc25 Nov 29, 2022
a866977
Fix docker-build for cliplugins
anujc25 Nov 29, 2022
2886ab4
Set current (currentServer) only if context is of type k8s
anujc25 Nov 30, 2022
f466a62
Address Review Comments Part-5
anujc25 Nov 30, 2022
99151fe
Address Review Comments Part-6
anujc25 Nov 30, 2022
4cabafc
Fix unit test
anujc25 Nov 30, 2022
fea415e
Make target field optional in CLIPlugin API
anujc25 Nov 30, 2022
992f974
Do not lock when reading currentContextMap
anujc25 Nov 30, 2022
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
Prev Previous commit
Next Next commit
Fix plugin deletion issue
  • Loading branch information
anujc25 committed Nov 29, 2022
commit 6c93e9bc60d972be0345c2568beb8eb7c5175b56
26 changes: 18 additions & 8 deletions cli/core/pkg/pluginmanager/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -670,32 +670,42 @@ func DeletePlugin(options DeletePluginOptions) error {
return err
}

var matchedPluginDescriptor cliapi.PluginDescriptor
var matchedPluginCatalog *catalog.ContextCatalog
matchedPluginCount := 0

// Add empty serverName for standalone plugins
serverNames = append(serverNames, "")
var catalogContainingPlugin *catalog.ContextCatalog

for _, serverName := range serverNames {
c, err := catalog.NewContextCatalog(serverName)
if err != nil {
continue
}
_, ok := c.Get(catalog.PluginNameTarget(options.PluginName, options.Target))
if ok {
catalogContainingPlugin = c
break

pds := c.List()
for i := range pds {
if pds[i].Name == options.PluginName && (options.Target == "" || options.Target == pds[i].Target) {
matchedPluginDescriptor = pds[i]
matchedPluginCatalog = c
matchedPluginCount++
}
}
}

if catalogContainingPlugin == nil {
return fmt.Errorf("could not get plugin path for plugin %q", options.PluginName)
if matchedPluginCount == 0 {
return errors.Errorf("unable to find plugin '%v'", options.PluginName)
}
if matchedPluginCount > 1 {
return errors.Errorf("unable to uniquely identify plugin '%v'. Please specify correct Target(kubernetes[k8s]/mission-control[tmc]) of the plugin with `--target` flag", options.PluginName)
}

if !options.ForceDelete {
if err := component.AskForConfirmation(fmt.Sprintf("Deleting Plugin '%s'. Are you sure?", options.PluginName)); err != nil {
return err
}
}
err = catalogContainingPlugin.Delete(catalog.PluginNameTarget(options.PluginName, options.Target))
err = matchedPluginCatalog.Delete(catalog.PluginNameTarget(matchedPluginDescriptor.Name, matchedPluginDescriptor.Target))
if err != nil {
return fmt.Errorf("plugin %q could not be deleted from cache", options.PluginName)
}
Expand Down
39 changes: 22 additions & 17 deletions cli/core/pkg/pluginmanager/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -528,34 +528,39 @@ func Test_DeletePlugin(t *testing.T) {
defer setupLocalDistoForTesting()()

// Try to delete plugin when plugin is not installed
loginPlugin := DeletePluginOptions{
PluginName: "login",
Target: cliv1alpha1.TargetNone,
ForceDelete: true,
}
err := DeletePlugin(loginPlugin)
err := DeletePlugin(DeletePluginOptions{PluginName: "login", Target: cliv1alpha1.TargetNone, ForceDelete: true})
assertions.NotNil(err)
assertions.Contains(err.Error(), "could not get plugin path for plugin \"login\"")
assertions.Contains(err.Error(), "unable to find plugin 'login'")

// Install login (standalone) package
mockInstallPlugin(assertions, "login", "v0.2.0", cliv1alpha1.TargetNone)

// Try to delete plugin when plugin is installed
clusterPlugin := DeletePluginOptions{
PluginName: "cluster",
Target: cliv1alpha1.TargetTMC,
ForceDelete: true,
}
err = DeletePlugin(clusterPlugin)
err = DeletePlugin(DeletePluginOptions{PluginName: "cluster", Target: cliv1alpha1.TargetTMC, ForceDelete: true})
assertions.NotNil(err)
assertions.Contains(err.Error(), "could not get plugin path for plugin \"cluster\"")
assertions.Contains(err.Error(), "unable to find plugin 'cluster'")

// Install cluster (context) package
// Install cluster (context) package from TMC target
mockInstallPlugin(assertions, "cluster", "v0.2.0", cliv1alpha1.TargetTMC)

// Try to describe plugin when plugin after installing plugin
err = DeletePlugin(clusterPlugin)
// Try to Delete plugin after installing plugin
err = DeletePlugin(DeletePluginOptions{PluginName: "cluster", Target: cliv1alpha1.TargetTMC, ForceDelete: true})
assertions.Nil(err)

// Install cluster (context) package from TMC target
mockInstallPlugin(assertions, "cluster", "v0.2.0", cliv1alpha1.TargetTMC)

// Try to Delete plugin after installing plugin
err = DeletePlugin(DeletePluginOptions{PluginName: "cluster", Target: "", ForceDelete: true})
assertions.Nil(err)

// Install cluster (context) package from TMC target
mockInstallPlugin(assertions, "cluster", "v0.2.0", cliv1alpha1.TargetTMC)
// Install cluster (context) package from k8s target
mockInstallPlugin(assertions, "cluster", "v1.6.0", cliv1alpha1.TargetK8s)
// Try to Delete plugin without passing target after installing plugin with different targets
err = DeletePlugin(DeletePluginOptions{PluginName: "cluster", Target: "", ForceDelete: true})
assertions.Contains(err.Error(), "unable to uniquely identify plugin 'cluster'. Please specify correct Target(kubernetes[k8s]/mission-control[tmc]) of the plugin with `--target` flag")
}

func Test_ValidatePlugin(t *testing.T) {
Expand Down