This repository has been archived by the owner on Jan 20, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 26
Start remote binary using env and appling ephemeral volume #76
Closed
AndrienkoAleksandr
wants to merge
9
commits into
master
from
startRemoteBinaryUsingEnvAndApplingEphemeralVolume
Closed
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
cacb834
Apply remote plugin runtime injection.
AndrienkoAleksandr 546526b
Add plugin type. Create separated component for runtime injection.
AndrienkoAleksandr 94806a1
Activate runtime injection. Cover code by tests.
AndrienkoAleksandr 096a31a
Fix up.
AndrienkoAleksandr 8a19712
Use remote runtime injection info from init container env variables.
AndrienkoAleksandr 1d73efd
Fix up.
AndrienkoAleksandr 3a83cb1
Start remote binary using env and appling ephemeral volume
AndrienkoAleksandr 0a9eeb0
Handle review feedback.
AndrienkoAleksandr af5340e
Fix up.
AndrienkoAleksandr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,144 @@ | ||
// | ||
// Copyright (c) 2019 Red Hat, Inc. | ||
// This program and the accompanying materials are made | ||
// available under the terms of the Eclipse Public License 2.0 | ||
// which is available at https://www.eclipse.org/legal/epl-2.0/ | ||
// | ||
// SPDX-License-Identifier: EPL-2.0 | ||
// | ||
// Contributors: | ||
// Red Hat, Inc. - initial API and implementation | ||
// | ||
|
||
package unified | ||
|
||
import ( | ||
"errors" | ||
"strings" | ||
|
||
"github.com/eclipse/che-plugin-broker/model" | ||
) | ||
|
||
const ( | ||
CheTheiaEditorName = "che-theia" | ||
|
||
InjectorContainerName = "remote-runtime-injector" | ||
|
||
RemoteEndPointExecutableEnvVar = "PLUGIN_REMOTE_ENDPOINT_EXECUTABLE" | ||
VolumeNameEnvVar = "REMOTE_ENDPOINT_VOLUME_NAME" | ||
) | ||
|
||
type RemotePluginInjection struct { | ||
Volume model.Volume | ||
Env model.EnvVar | ||
Command []string | ||
Args []string | ||
} | ||
|
||
func InjectRemoteRuntime(plugins []model.ChePlugin) error { | ||
editorPlugin, err := findCheTheiaEditor(plugins) | ||
if editorPlugin == nil { | ||
// it's ok, maybe used some another editor instead of che-theia | ||
return nil | ||
} | ||
|
||
injection, err := getRuntimeInjection(editorPlugin) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
for _, plugin := range plugins { | ||
inject(&plugin, injection) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func findCheTheiaEditor(plugins []model.ChePlugin) (*model.ChePlugin, error) { | ||
for _, plugin := range plugins { | ||
if strings.ToLower(plugin.Type) == model.EditorPluginType && | ||
strings.ToLower(plugin.Name) == CheTheiaEditorName && | ||
len(plugin.InitContainers) > 0 { | ||
return &plugin, nil | ||
} | ||
} | ||
return nil, errors.New("Unable to find che-theia editor plugin") | ||
} | ||
|
||
func getRuntimeInjection(editorPlugin *model.ChePlugin) (*RemotePluginInjection, error) { | ||
containerInjector, err := findContainerInjector(editorPlugin.InitContainers) | ||
if err != nil { | ||
// it's ok, older che-theia could be without runtime injection | ||
return nil, nil | ||
} | ||
|
||
runtimeBinaryPathEnv, err := findEnv(RemoteEndPointExecutableEnvVar, containerInjector.Env) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
volumeName, err := findEnv(VolumeNameEnvVar, containerInjector.Env) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
volume, err := findVolume(volumeName.Value, containerInjector.Volumes) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return &RemotePluginInjection{ | ||
Volume: *volume, | ||
Env: *runtimeBinaryPathEnv, | ||
Command: []string{runtimeBinaryPathEnv.Value}, | ||
}, nil | ||
} | ||
|
||
func findContainerInjector(containers []model.Container) (*model.Container, error) { | ||
for _, container := range containers { | ||
if container.Name == InjectorContainerName { | ||
return &container, nil | ||
} | ||
} | ||
return nil, errors.New("Unable to find injector container") | ||
} | ||
|
||
func findEnv(envName string, envVars []model.EnvVar) (*model.EnvVar, error) { | ||
var result *model.EnvVar | ||
for _, envVar := range envVars { | ||
if envVar.Name == envName { | ||
result = &envVar | ||
break | ||
} | ||
} | ||
if result == nil { | ||
return nil, errors.New("Unable to find required env with name " + envName) | ||
} | ||
if result.Value == "" { | ||
return nil, errors.New("Required env with name " + envName + " was found, but value is empty") | ||
} | ||
|
||
return result, nil | ||
} | ||
|
||
func findVolume(volumeName string, volumes []model.Volume) (*model.Volume, error) { | ||
for _, volume := range volumes { | ||
if volume.Name == volumeName { | ||
return &volume, nil | ||
} | ||
} | ||
return nil, errors.New("Unable to find volume by name " + volumeName) | ||
} | ||
|
||
func inject(plugin *model.ChePlugin, injection *RemotePluginInjection) { | ||
pluginType := strings.ToLower(plugin.Type) | ||
|
||
if pluginType != model.TheiaPluginType && pluginType != model.VscodePluginType { | ||
return | ||
} | ||
// sidecar container has one and only one container. | ||
container := &plugin.Containers[0] | ||
|
||
container.Env = append(container.Env, injection.Env) | ||
container.Volumes = append(container.Volumes, injection.Volume) | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If
err == nil
andruntimeBinaryPathEnv.Value == ""
, this will returnnil, nil
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed