Skip to content

Commit

Permalink
Rework plugin brokering to reuse PVC strategies code (#11119)
Browse files Browse the repository at this point in the history
CHE-10879 Rework plugin broker code to reuse PVC strategies code.
Moreover, it applies other OS/K8s provisioners with proxy,
name uniqueness, private docker image registry, pod termination
support.
Signed-off-by: Oleksandr Garagatyi <ogaragat@redhat.com>
  • Loading branch information
Oleksandr Garagatyi authored Sep 11, 2018
1 parent 0c0f69d commit 24ccece
Show file tree
Hide file tree
Showing 11 changed files with 388 additions and 289 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@
import org.eclipse.che.workspace.infrastructure.kubernetes.server.secure.SecureServerExposerFactory;
import org.eclipse.che.workspace.infrastructure.kubernetes.server.secure.SecureServerExposerFactoryProvider;
import org.eclipse.che.workspace.infrastructure.kubernetes.wsplugins.KubernetesPluginsToolingApplier;
import org.eclipse.che.workspace.infrastructure.kubernetes.wsplugins.PluginBrokerManager;
import org.eclipse.che.workspace.infrastructure.kubernetes.wsplugins.SidecarToolingProvisioner;
import org.eclipse.che.workspace.infrastructure.kubernetes.wsplugins.brokerphases.BrokerEnvironmentFactory;
import org.eclipse.che.workspace.infrastructure.kubernetes.wsplugins.brokerphases.KubernetesBrokerEnvironmentFactory;
import org.eclipse.che.workspace.infrastructure.kubernetes.wsplugins.events.BrokerService;

/** @author Sergii Leshchenko */
Expand Down Expand Up @@ -149,5 +153,14 @@ protected void configure() {
.to(new TypeLiteral<DefaultSecureServersFactory<KubernetesEnvironment>>() {});

bind(BrokerService.class);

bind(new TypeLiteral<BrokerEnvironmentFactory<KubernetesEnvironment>>() {})
.to(KubernetesBrokerEnvironmentFactory.class);

bind(PluginBrokerManager.class)
.to(new TypeLiteral<PluginBrokerManager<KubernetesEnvironment>>() {});

bind(SidecarToolingProvisioner.class)
.to(new TypeLiteral<SidecarToolingProvisioner<KubernetesEnvironment>>() {});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public class KubernetesInternalRuntime<E extends KubernetesEnvironment>
private final StartSynchronizer startSynchronizer;
private final Set<InternalEnvironmentProvisioner> internalEnvironmentProvisioners;
private final KubernetesEnvironmentProvisioner<E> kubernetesEnvironmentProvisioner;
private final SidecarToolingProvisioner toolingProvisioner;
private final SidecarToolingProvisioner<E> toolingProvisioner;

@Inject
public KubernetesInternalRuntime(
Expand All @@ -129,7 +129,7 @@ public KubernetesInternalRuntime(
StartSynchronizerFactory startSynchronizerFactory,
Set<InternalEnvironmentProvisioner> internalEnvironmentProvisioners,
KubernetesEnvironmentProvisioner<E> kubernetesEnvironmentProvisioner,
SidecarToolingProvisioner toolingProvisioner,
SidecarToolingProvisioner<E> toolingProvisioner,
@Assisted KubernetesRuntimeContext<E> context,
@Assisted KubernetesNamespace namespace,
@Assisted List<Warning> warnings) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,21 @@
package org.eclipse.che.workspace.infrastructure.kubernetes.wsplugins;

import com.google.common.annotations.Beta;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import javax.inject.Inject;
import javax.inject.Named;
import org.eclipse.che.api.core.model.workspace.runtime.RuntimeIdentity;
import org.eclipse.che.api.core.notification.EventService;
import org.eclipse.che.api.workspace.server.spi.InfrastructureException;
import org.eclipse.che.api.workspace.server.spi.provision.env.AgentAuthEnableEnvVarProvider;
import org.eclipse.che.api.workspace.server.spi.provision.env.MachineTokenEnvVarProvider;
import org.eclipse.che.api.workspace.server.wsplugins.model.ChePlugin;
import org.eclipse.che.api.workspace.server.wsplugins.model.PluginMeta;
import org.eclipse.che.commons.lang.NameGenerator;
import org.eclipse.che.workspace.infrastructure.kubernetes.KubernetesEnvironmentProvisioner;
import org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment;
import org.eclipse.che.workspace.infrastructure.kubernetes.namespace.KubernetesNamespace;
import org.eclipse.che.workspace.infrastructure.kubernetes.namespace.KubernetesNamespaceFactory;
import org.eclipse.che.workspace.infrastructure.kubernetes.namespace.pvc.WorkspaceVolumesStrategy;
import org.eclipse.che.workspace.infrastructure.kubernetes.wsplugins.brokerphases.DeliverMetas;
import org.eclipse.che.workspace.infrastructure.kubernetes.wsplugins.brokerphases.BrokerEnvironmentFactory;
import org.eclipse.che.workspace.infrastructure.kubernetes.wsplugins.brokerphases.DeployBroker;
import org.eclipse.che.workspace.infrastructure.kubernetes.wsplugins.brokerphases.ListenBrokerEvents;
import org.eclipse.che.workspace.infrastructure.kubernetes.wsplugins.brokerphases.PrepareStorage;
Expand All @@ -45,47 +41,26 @@
* @author Oleksandr Garagatyi
*/
@Beta
public class PluginBrokerManager {

private static final String PVC_CLAIM_PROJECTS = "claim-che-workspace";
private static final String CONFIG_MAP_NAME_SUFFIX = "broker-config-map";
private static final String BROKER_VOLUME = "broker-config-volume";
private static final String CONF_FOLDER = "/broker-config";
private static final String CONFIG_FILE = "config.json";
public class PluginBrokerManager<E extends KubernetesEnvironment> {

private final KubernetesNamespaceFactory factory;
private final EventService eventService;
private final WorkspaceVolumesStrategy volumesStrategy;
private final AgentAuthEnableEnvVarProvider authEnableEnvVarProvider;
private final MachineTokenEnvVarProvider machineTokenEnvVarProvider;
private final String pvcName;
private final String pvcQuantity;
private final String pvcAccessMode;
private final String cheWebsocketEndpoint;
private final String pluginBrokerImage;
private final BrokerEnvironmentFactory<E> brokerEnvironmentConfig;
private final KubernetesEnvironmentProvisioner<E> environmentProvisioner;

@Inject
public PluginBrokerManager(
KubernetesNamespaceFactory factory,
EventService eventService,
KubernetesEnvironmentProvisioner<E> environmentProvisioner,
WorkspaceVolumesStrategy volumesStrategy,
AgentAuthEnableEnvVarProvider authEnableEnvVarProvider,
MachineTokenEnvVarProvider machineTokenEnvVarProvider,
@Named("che.infra.kubernetes.pvc.name") String pvcName,
@Named("che.infra.kubernetes.pvc.quantity") String pvcQuantity,
@Named("che.infra.kubernetes.pvc.access_mode") String pvcAccessMode,
@Named("che.websocket.endpoint") String cheWebsocketEndpoint,
@Named("che.workspace.plugin_broker.image") String pluginBrokerImage) {
BrokerEnvironmentFactory<E> brokerEnvironmentConfig) {
this.factory = factory;
this.eventService = eventService;
this.volumesStrategy = volumesStrategy;
this.authEnableEnvVarProvider = authEnableEnvVarProvider;
this.machineTokenEnvVarProvider = machineTokenEnvVarProvider;
this.pvcName = pvcName;
this.pvcQuantity = pvcQuantity;
this.pvcAccessMode = pvcAccessMode;
this.cheWebsocketEndpoint = cheWebsocketEndpoint;
this.pluginBrokerImage = pluginBrokerImage;
this.brokerEnvironmentConfig = brokerEnvironmentConfig;
this.environmentProvisioner = environmentProvisioner;
}

/**
Expand All @@ -95,71 +70,38 @@ public PluginBrokerManager(
* <p>This API is in <b>Beta</b> and is subject to changes or removal.
*/
@Beta
public List<ChePlugin> getTooling(
RuntimeIdentity runtimeID,
Collection<PluginMeta> pluginsMeta,
KubernetesEnvironment environment)
public List<ChePlugin> getTooling(RuntimeIdentity runtimeID, Collection<PluginMeta> pluginsMeta)
throws InfrastructureException {

String workspaceId = runtimeID.getWorkspaceId();

CompletableFuture<List<ChePlugin>> toolingFuture = new CompletableFuture<>();
KubernetesNamespace kubernetesNamespace = factory.create(workspaceId);
E brokerEnvironment = brokerEnvironmentConfig.create(pluginsMeta, runtimeID);

String configMapName = generateUniqueConfigMapName();
environmentProvisioner.provision(brokerEnvironment, runtimeID);

ListenBrokerEvents listenBrokerEvents = getListenEventPhase(workspaceId, toolingFuture);
PrepareStorage prepareStorage = getPrepareStoragePhase(workspaceId, environment);
DeliverMetas deliverMetas =
getDeliverPhaseMetas(kubernetesNamespace, pluginsMeta, configMapName);
PrepareStorage prepareStorage = getPrepareStoragePhase(workspaceId, brokerEnvironment);
WaitBrokerResult waitBrokerResult = getWaitBrokerPhase(toolingFuture);
DeployBroker deployBroker = getDeployBrokerPhase(kubernetesNamespace, runtimeID, configMapName);
DeployBroker deployBroker = getDeployBrokerPhase(kubernetesNamespace, brokerEnvironment);

listenBrokerEvents
.then(prepareStorage)
.then(deliverMetas)
.then(deployBroker)
.then(waitBrokerResult);
listenBrokerEvents.then(prepareStorage).then(deployBroker).then(waitBrokerResult);
return listenBrokerEvents.execute();
}

private String generateUniqueConfigMapName() {
return NameGenerator.generate(CONFIG_MAP_NAME_SUFFIX, 6);
}

private ListenBrokerEvents getListenEventPhase(
String workspaceId, CompletableFuture<List<ChePlugin>> toolingFuture) {
return new ListenBrokerEvents(workspaceId, toolingFuture, eventService);
}

private PrepareStorage getPrepareStoragePhase(
String workspaceId, KubernetesEnvironment environment) {
return new PrepareStorage(
workspaceId, environment, volumesStrategy, pvcName, pvcAccessMode, pvcQuantity);
}

private DeliverMetas getDeliverPhaseMetas(
KubernetesNamespace kubernetesNamespace,
Collection<PluginMeta> pluginsMeta,
String configMapName) {
return new DeliverMetas(kubernetesNamespace, pluginsMeta, CONFIG_FILE, configMapName);
String workspaceId, KubernetesEnvironment brokerEnvironment) {
return new PrepareStorage(workspaceId, brokerEnvironment, volumesStrategy);
}

private DeployBroker getDeployBrokerPhase(
KubernetesNamespace kubernetesNamespace, RuntimeIdentity runtimeId, String configMapName)
throws InfrastructureException {
return new DeployBroker(
kubernetesNamespace,
runtimeId.getWorkspaceId(),
cheWebsocketEndpoint,
CONF_FOLDER,
CONFIG_FILE,
PVC_CLAIM_PROJECTS,
BROKER_VOLUME,
configMapName,
pluginBrokerImage,
Arrays.asList(
authEnableEnvVarProvider.get(runtimeId), machineTokenEnvVarProvider.get(runtimeId)));
KubernetesNamespace kubernetesNamespace, KubernetesEnvironment brokerEnvironment) {
return new DeployBroker(kubernetesNamespace, brokerEnvironment);
}

private WaitBrokerResult getWaitBrokerPhase(CompletableFuture<List<ChePlugin>> toolingFuture) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,25 +31,24 @@
* @author Oleksandr Garagatyi
*/
@Beta
public class SidecarToolingProvisioner {
public class SidecarToolingProvisioner<E extends KubernetesEnvironment> {

private final Map<String, ChePluginsApplier> workspaceNextAppliers;
private final PluginMetaRetriever pluginMetaRetriever;
private final PluginBrokerManager pluginBrokerManager;
private final PluginBrokerManager<E> pluginBrokerManager;

@Inject
public SidecarToolingProvisioner(
Map<String, ChePluginsApplier> workspaceNextAppliers,
PluginMetaRetriever pluginMetaRetriever,
PluginBrokerManager pluginBrokerManager) {
PluginBrokerManager<E> pluginBrokerManager) {
this.workspaceNextAppliers = ImmutableMap.copyOf(workspaceNextAppliers);
this.pluginMetaRetriever = pluginMetaRetriever;
this.pluginBrokerManager = pluginBrokerManager;
}

@Beta
public void provision(RuntimeIdentity id, KubernetesEnvironment environment)
throws InfrastructureException {
public void provision(RuntimeIdentity id, E environment) throws InfrastructureException {

Collection<PluginMeta> pluginsMeta = pluginMetaRetriever.get(environment.getAttributes());
if (pluginsMeta.isEmpty()) {
Expand All @@ -63,7 +62,7 @@ public void provision(RuntimeIdentity id, KubernetesEnvironment environment)
"Sidecar tooling configuration is not supported with recipe type " + recipeType);
}

List<ChePlugin> chePlugins = pluginBrokerManager.getTooling(id, pluginsMeta, environment);
List<ChePlugin> chePlugins = pluginBrokerManager.getTooling(id, pluginsMeta);

pluginsApplier.apply(environment, chePlugins);
}
Expand Down
Loading

0 comments on commit 24ccece

Please sign in to comment.