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

Ephemeral volume for che containers #74

Merged
merged 5 commits into from
Sep 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
95 changes: 68 additions & 27 deletions brokers/unified/vscode/broker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -236,6 +236,7 @@ func TestBroker_processPlugin(t *testing.T) {
{
Name: "Volume-for-init-container",
MountPath: "/test-volume",
Ephemeral: false,
},
},
Env: []model.EnvVar{
Expand All @@ -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",
Expand Down Expand Up @@ -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,
Expand All @@ -603,6 +643,7 @@ func expectedPluginsWithSingleRemotePluginWithInitContainer(usedLocalhost bool)
{
Name: "Volume-for-init-container",
MountPath: "/test-volume",
Ephemeral: ephemeral,
},
},
Env: []model.EnvVar{
Expand All @@ -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),
Expand Down
1 change: 1 addition & 0 deletions model/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down