diff --git a/brokers/unified/broker.go b/brokers/unified/broker.go index 51d103cd..9e443010 100644 --- a/brokers/unified/broker.go +++ b/brokers/unified/broker.go @@ -331,12 +331,14 @@ func resolveRelativeExtensionPaths(metas []model.PluginMeta, defaultRegistry str // to be passed back to Che. func ConvertMetaToPlugin(meta model.PluginMeta) model.ChePlugin { return model.ChePlugin{ - ID: meta.ID, - Name: meta.Name, - Publisher: meta.Publisher, - Version: meta.Version, - Containers: meta.Spec.Containers, - Endpoints: meta.Spec.Endpoints, - WorkspaceEnv: meta.Spec.WorkspaceEnv, + ID: meta.ID, + Name: meta.Name, + Type: meta.Type, + Publisher: meta.Publisher, + Version: meta.Version, + Containers: meta.Spec.Containers, + Endpoints: meta.Spec.Endpoints, + WorkspaceEnv: meta.Spec.WorkspaceEnv, + PluginPatcher: meta.Spec.PluginPatcher, } } diff --git a/brokers/unified/broker_test.go b/brokers/unified/broker_test.go index 4a2b57d0..bcb2ba27 100644 --- a/brokers/unified/broker_test.go +++ b/brokers/unified/broker_test.go @@ -283,7 +283,7 @@ func TestBroker_processPlugins(t *testing.T) { metas: []model.PluginMeta{createChePluginMeta("id1"), createCheEditorMeta("id2")}, }, want: want{ - commonPlugins: []model.ChePlugin{createChePlugin("id1"), createChePlugin("id2")}, + commonPlugins: []model.ChePlugin{createChePlugin("id1"), createCheEditorPlugin("id2")}, }, }, { @@ -368,6 +368,7 @@ func TestBroker_processPlugins(t *testing.T) { Name: "name1", Version: "v0.13", ID: "id1", + Type: ChePluginType, Endpoints: []model.Endpoint{ { Name: "end1", @@ -399,6 +400,7 @@ func TestBroker_processPlugins(t *testing.T) { Name: "name2", Version: "v0", ID: "id2", + Type: EditorPluginType, Endpoints: []model.Endpoint{ { Name: "end2", @@ -585,7 +587,8 @@ func TestBroker_processPlugins(t *testing.T) { }, commonPlugins: []model.ChePlugin{ { - ID: "id11", + Type: "che plugin", + ID: "id11", Containers: []model.Container{ { Image: defaultImage, @@ -593,7 +596,8 @@ func TestBroker_processPlugins(t *testing.T) { }, }, { - ID: "id12", + Type: "Che Plugin", + ID: "id12", Containers: []model.Container{ { Image: defaultImage, @@ -601,7 +605,8 @@ func TestBroker_processPlugins(t *testing.T) { }, }, { - ID: "id13", + Type: "cHE plugIN", + ID: "id13", Containers: []model.Container{ { Image: defaultImage, @@ -1443,7 +1448,20 @@ func createMetaWithExtension(ID string, extensions ...string) model.PluginMeta { func createChePlugin(ID string) model.ChePlugin { return model.ChePlugin{ - ID: ID, + ID: ID, + Type: TestChePluginType, + Containers: []model.Container{ + { + Image: defaultImage, + }, + }, + } +} + +func createCheEditorPlugin(ID string) model.ChePlugin { + return model.ChePlugin{ + ID: ID, + Type: TestEditorPluginType, Containers: []model.Container{ { Image: defaultImage, diff --git a/brokers/unified/vscode/broker.go b/brokers/unified/vscode/broker.go index d76a78a7..fefc37ff 100644 --- a/brokers/unified/vscode/broker.go +++ b/brokers/unified/vscode/broker.go @@ -180,6 +180,7 @@ func convertMetaToPlugin(meta model.PluginMeta) model.ChePlugin { return model.ChePlugin{ ID: meta.ID, Name: meta.Name, + Type: meta.Type, Publisher: meta.Publisher, Version: meta.Version, Containers: meta.Spec.Containers, diff --git a/brokers/unified/vscode/broker_test.go b/brokers/unified/vscode/broker_test.go index b2ce9e42..069f1b46 100644 --- a/brokers/unified/vscode/broker_test.go +++ b/brokers/unified/vscode/broker_test.go @@ -233,7 +233,7 @@ func TestBroker_processPlugin(t *testing.T) { }, useLocalhost: false, want: expectedPluginsWithSingleRemotePluginWithSeveralExtensions( - false), + false, vscodePluginType), }, { name: "Successful brokering of remote plugin when extension points to .theia archive, using localhost as the host name", @@ -256,7 +256,7 @@ func TestBroker_processPlugin(t *testing.T) { }, useLocalhost: true, want: expectedPluginsWithSingleRemotePluginWithSeveralExtensions( - true), + true, vscodePluginType), }, { name: "Successful brokering of local plugin with extensions field with several extensions", @@ -333,7 +333,7 @@ func TestBroker_processPlugin(t *testing.T) { }, useLocalhost: false, want: expectedPluginsWithSingleRemotePluginWithSeveralExtensions( - false), + false, vscodePluginType), }, { name: "Successful brokering of remote plugin with extensions field with several extensions, using localhost as the host name", @@ -356,7 +356,7 @@ func TestBroker_processPlugin(t *testing.T) { }, useLocalhost: true, want: expectedPluginsWithSingleRemotePluginWithSeveralExtensions( - true), + true, vscodePluginType), }, { name: "Successful brokering of remote plugin with extensions field with several extensions, using a generated the host name", @@ -381,7 +381,7 @@ func TestBroker_processPlugin(t *testing.T) { }, useLocalhost: false, want: expectedPluginsWithSingleRemotePluginWithSeveralExtensions( - false), + false, vscodePluginType), }, { name: "Successful brokering of remote plugin with extensions field with several extensions, using localhost as the host name", @@ -406,7 +406,7 @@ func TestBroker_processPlugin(t *testing.T) { }, useLocalhost: true, want: expectedPluginsWithSingleRemotePluginWithSeveralExtensions( - true), + true, vscodePluginType), }, { name: "Successful brokering of remote plugin with extensions field with mixed extensions and archives URLs, using a generated host name", @@ -431,7 +431,7 @@ func TestBroker_processPlugin(t *testing.T) { }, useLocalhost: false, want: expectedPluginsWithSingleRemotePluginWithSeveralExtensions( - false), + false, vscodePluginType), }, { name: "Successful brokering of remote plugin with extensions field with mixed extensions and archives URLs, using localhost as the host name", @@ -456,7 +456,7 @@ func TestBroker_processPlugin(t *testing.T) { }, useLocalhost: true, want: expectedPluginsWithSingleRemotePluginWithSeveralExtensions( - true), + true, vscodePluginType), }, { name: "Successful brokering of remote plugin with extensions field with mixed extensions and archives URLs when plugin type is Theia, using a generated host name", @@ -481,7 +481,7 @@ func TestBroker_processPlugin(t *testing.T) { }, useLocalhost: false, want: expectedPluginsWithSingleRemotePluginWithSeveralExtensions( - false), + false, theiaPluginType), }, { name: "Successful brokering of remote plugin with extensions field with mixed extensions and archives URLs when plugin type is Theia, using localhost as the host name", @@ -506,7 +506,7 @@ func TestBroker_processPlugin(t *testing.T) { }, useLocalhost: true, want: expectedPluginsWithSingleRemotePluginWithSeveralExtensions( - true), + true, theiaPluginType), }, } for _, tt := range cases { @@ -538,9 +538,10 @@ func TestBroker_processPlugin(t *testing.T) { } } -func expectedPluginsWithSingleRemotePluginWithSeveralExtensions(usedLocalhost bool) []model.ChePlugin { +func expectedPluginsWithSingleRemotePluginWithSeveralExtensions(usedLocalhost bool, pluginType string) []model.ChePlugin { expectedPlugin := model.ChePlugin{ ID: pluginID, + Type: pluginType, Version: pluginVersion, Publisher: pluginPublisher, Name: pluginName, diff --git a/model/model.go b/model/model.go index 81c5bd6a..aed2e02e 100644 --- a/model/model.go +++ b/model/model.go @@ -50,10 +50,11 @@ type PluginMeta struct { } type PluginMetaSpec struct { - Endpoints []Endpoint `json:"endpoints" yaml:"endpoints"` - Containers []Container `json:"containers" yaml:"containers"` - WorkspaceEnv []EnvVar `json:"workspaceEnv" yaml:"workspaceEnv"` - Extensions []string `json:"extensions" yaml:"extensions"` + Endpoints []Endpoint `json:"endpoints" yaml:"endpoints"` + Containers []Container `json:"containers" yaml:"containers"` + WorkspaceEnv []EnvVar `json:"workspaceEnv" yaml:"workspaceEnv"` + Extensions []string `json:"extensions" yaml:"extensions"` + PluginPatcher PluginPatcher `json:"pluginPatcher" yaml:"pluginPatcher"` } type PluginFQN struct { @@ -98,14 +99,34 @@ type Container struct { Ports []ExposedPort `json:"ports" yaml:"ports"` MemoryLimit string `json:"memoryLimit,omitempty" yaml:"memoryLimit,omitempty"` MountSources bool `json:"mountSources" yaml:"mountSources"` + + // Base root command inside container + Command []string `json:"command" yaml:"command"` + // Arguments of the base root command inside container + Args []string `json:"args" yaml:"args"` } type ChePlugin struct { - ID string `json:"id" yaml:"id"` - Version string `json:"version" yaml:"version"` - Name string `json:"name" yaml:"name"` - Publisher string `json:"publisher" yaml:"publisher"` - Endpoints []Endpoint `json:"endpoints" yaml:"endpoints"` - Containers []Container `json:"containers" yaml:"containers"` - WorkspaceEnv []EnvVar `json:"workspaceEnv" yaml:"workspaceEnv"` + ID string `json:"id" yaml:"id"` + Version string `json:"version" yaml:"version"` + Name string `json:"name" yaml:"name"` + Type string `json:"type" yaml:"type"` + Publisher string `json:"publisher" yaml:"publisher"` + Endpoints []Endpoint `json:"endpoints" yaml:"endpoints"` + Containers []Container `json:"containers" yaml:"containers"` + WorkspaceEnv []EnvVar `json:"workspaceEnv" yaml:"workspaceEnv"` + PluginPatcher PluginPatcher `json:"pluginPatcher" yaml:"pluginPatcher"` +} + +type PluginPatcher struct { + // List init containers + InitContainers []Container `json:"initContainers" yaml:"initContainers"` + + // List plugin types matched to PluginPatcher + PluginTypeMatcher []string `json:"pluginTypeMatcher" yaml:"pluginTypeMatcher"` + + // Command to patch original plugin container command + PluginContainerCommand []string `json:"pluginContainerCommand" yaml:"pluginContainerCommand"` + // Argument to patch original plugin container arguments + PluginContainerArgs []string `json:"pluginContainerArgs" yaml:"pluginContainerArgs"` }