diff --git a/brokers/unified/vscode/broker_test.go b/brokers/unified/vscode/broker_test.go index 6cf93635..be39d411 100644 --- a/brokers/unified/vscode/broker_test.go +++ b/brokers/unified/vscode/broker_test.go @@ -213,7 +213,7 @@ func TestBroker_processPlugin(t *testing.T) { want: expectedNoPlugin(), }, { - name: "Successful brokering of remote plugin with initContainers", + name: "Successful brokering of remote plugin with initContainers and persisted volume", meta: model.PluginMeta{ Type: vscodePluginType, ID: pluginID, @@ -236,6 +236,7 @@ func TestBroker_processPlugin(t *testing.T) { { Name: "Volume-for-init-container", MountPath: "/test-volume", + Ephemeral: false, }, }, Env: []model.EnvVar{ @@ -249,8 +250,47 @@ func TestBroker_processPlugin(t *testing.T) { }, }, useLocalhost: false, - want: expectedPluginsWithSingleRemotePluginWithInitContainer( - false), + want: expectedPluginsWithSingleRemotePluginWithInitContainer(false), + }, + { + name: "Successful brokering of remote plugin with initContainers and ephemeral volume", + meta: model.PluginMeta{ + Type: vscodePluginType, + ID: pluginID, + Version: pluginVersion, + Publisher: pluginPublisher, + Name: pluginName, + Spec: model.PluginMetaSpec{ + Extensions: []string{ + "https://red-hot-chilli.peppers/plugin.theia", + }, + Containers: []model.Container{ + { + Image: image, + }, + }, + InitContainers: []model.Container{ + { + Image: image, + Volumes: []model.Volume{ + { + Name: "Volume-for-init-container", + MountPath: "/test-volume", + Ephemeral: true, + }, + }, + Env: []model.EnvVar{ + { + Name: "ExecBin", + Value: "/test-volume/someExecBin", + }, + }, + }, + }, + }, + }, + useLocalhost: false, + want: expectedPluginsWithSingleRemotePluginWithInitContainer(true), }, { name: "Successful brokering of remote plugin when extension points to .theia archive, using a generated host name", @@ -578,7 +618,7 @@ func TestBroker_processPlugin(t *testing.T) { } } -func expectedPluginsWithSingleRemotePluginWithInitContainer(usedLocalhost bool) []model.ChePlugin { +func expectedPluginsWithSingleRemotePluginWithInitContainer(ephemeral bool) []model.ChePlugin { expectedPlugin := model.ChePlugin{ ID: pluginID, Version: pluginVersion, @@ -603,6 +643,7 @@ func expectedPluginsWithSingleRemotePluginWithInitContainer(usedLocalhost bool) { Name: "Volume-for-init-container", MountPath: "/test-volume", + Ephemeral: ephemeral, }, }, Env: []model.EnvVar{ @@ -614,30 +655,30 @@ func expectedPluginsWithSingleRemotePluginWithInitContainer(usedLocalhost bool) }, }, } - if !usedLocalhost { - expectedPlugin.Containers[0].Ports = []model.ExposedPort{ - { - ExposedPort: 4242, - }, - } - expectedPlugin.Containers[0].Env = []model.EnvVar{ - { - Name: "THEIA_PLUGIN_ENDPOINT_PORT", - Value: "4242", - }, - } - expectedPlugin.Endpoints = []model.Endpoint{ - model.Endpoint{ - Name: "randomString1234567890", - Public: false, - TargetPort: 4242, - }, - } - expectedPlugin.WorkspaceEnv = append(expectedPlugin.WorkspaceEnv, model.EnvVar{ - Name: "THEIA_PLUGIN_REMOTE_ENDPOINT_" + strings.ReplaceAll(pluginPublisher+"_"+pluginName+"_"+pluginVersion, " ", "_"), - Value: "ws://randomString1234567890:4242", - }) + + expectedPlugin.Containers[0].Ports = []model.ExposedPort{ + { + ExposedPort: 4242, + }, + } + expectedPlugin.Containers[0].Env = []model.EnvVar{ + { + Name: "THEIA_PLUGIN_ENDPOINT_PORT", + Value: "4242", + }, } + expectedPlugin.Endpoints = []model.Endpoint{ + model.Endpoint{ + Name: "randomString1234567890", + Public: false, + TargetPort: 4242, + }, + } + expectedPlugin.WorkspaceEnv = append(expectedPlugin.WorkspaceEnv, model.EnvVar{ + Name: "THEIA_PLUGIN_REMOTE_ENDPOINT_" + strings.ReplaceAll(pluginPublisher+"_"+pluginName+"_"+pluginVersion, " ", "_"), + Value: "ws://randomString1234567890:4242", + }) + expectedPlugin.Containers[0].Env = append(expectedPlugin.Containers[0].Env, model.EnvVar{ Name: "THEIA_PLUGINS", Value: "local-dir:///plugins/sidecars/" + getPluginUniqueName(expectedPlugin), diff --git a/model/model.go b/model/model.go index cb763356..c3b2e7d4 100644 --- a/model/model.go +++ b/model/model.go @@ -84,6 +84,7 @@ type Command struct { type Volume struct { MountPath string `json:"mountPath" yaml:"mountPath"` Name string `json:"name" yaml:"name"` + Ephemeral bool `json:"ephemeral" yaml:"ephemeral"` } type ExposedPort struct {