Skip to content

Commit

Permalink
CHE-11071 Add injecting of auth related env vars into Plugin Broker Pod
Browse files Browse the repository at this point in the history
  • Loading branch information
sleshchenko committed Sep 7, 2018
1 parent a1eb95a commit a0fbf69
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
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;
Expand All @@ -20,6 +21,8 @@
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;
Expand Down Expand Up @@ -53,6 +56,8 @@ public class PluginBrokerManager {
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;
Expand All @@ -64,6 +69,8 @@ public PluginBrokerManager(
KubernetesNamespaceFactory factory,
EventService eventService,
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,
Expand All @@ -72,6 +79,8 @@ public PluginBrokerManager(
this.factory = factory;
this.eventService = eventService;
this.volumesStrategy = volumesStrategy;
this.authEnableEnvVarProvider = authEnableEnvVarProvider;
this.machineTokenEnvVarProvider = machineTokenEnvVarProvider;
this.pvcName = pvcName;
this.pvcQuantity = pvcQuantity;
this.pvcAccessMode = pvcAccessMode;
Expand All @@ -93,6 +102,7 @@ public List<ChePlugin> getTooling(
throws InfrastructureException {

String workspaceId = runtimeID.getWorkspaceId();

CompletableFuture<List<ChePlugin>> toolingFuture = new CompletableFuture<>();
KubernetesNamespace kubernetesNamespace = factory.create(workspaceId);

Expand All @@ -103,8 +113,7 @@ public List<ChePlugin> getTooling(
DeliverMetas deliverMetas =
getDeliverPhaseMetas(kubernetesNamespace, pluginsMeta, configMapName);
WaitBrokerResult waitBrokerResult = getWaitBrokerPhase(toolingFuture);
DeployBroker deployBroker =
getDeployBrokerPhase(kubernetesNamespace, workspaceId, configMapName);
DeployBroker deployBroker = getDeployBrokerPhase(kubernetesNamespace, runtimeID, configMapName);

listenBrokerEvents
.then(prepareStorage)
Expand Down Expand Up @@ -137,17 +146,20 @@ private DeliverMetas getDeliverPhaseMetas(
}

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

private WaitBrokerResult getWaitBrokerPhase(CompletableFuture<List<ChePlugin>> toolingFuture) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,16 @@
package org.eclipse.che.workspace.infrastructure.kubernetes.wsplugins.brokerphases;

import static java.util.Collections.singletonMap;
import static java.util.stream.Collectors.toList;
import static org.eclipse.che.workspace.infrastructure.kubernetes.namespace.KubernetesObjectUtil.newVolume;
import static org.eclipse.che.workspace.infrastructure.kubernetes.namespace.KubernetesObjectUtil.newVolumeMount;
import static org.slf4j.LoggerFactory.getLogger;

import com.google.common.annotations.Beta;
import io.fabric8.kubernetes.api.model.Container;
import io.fabric8.kubernetes.api.model.ContainerBuilder;
import io.fabric8.kubernetes.api.model.EnvVar;
import io.fabric8.kubernetes.api.model.EnvVarBuilder;
import io.fabric8.kubernetes.api.model.Pod;
import io.fabric8.kubernetes.api.model.PodBuilder;
import io.fabric8.kubernetes.api.model.Quantity;
Expand All @@ -27,6 +30,7 @@
import java.util.List;
import org.eclipse.che.api.workspace.server.spi.InfrastructureException;
import org.eclipse.che.api.workspace.server.wsplugins.model.ChePlugin;
import org.eclipse.che.commons.lang.Pair;
import org.eclipse.che.workspace.infrastructure.kubernetes.namespace.KubernetesDeployments;
import org.eclipse.che.workspace.infrastructure.kubernetes.namespace.KubernetesNamespace;
import org.slf4j.Logger;
Expand All @@ -53,6 +57,7 @@ public class DeployBroker extends BrokerPhase {
private final String configMapName;
private final String pluginBrokerImage;
private final KubernetesNamespace kubernetesNamespace;
private final List<EnvVar> envVars;

public DeployBroker(
KubernetesNamespace kubernetesNamespace,
Expand All @@ -63,7 +68,8 @@ public DeployBroker(
String pvcClaimProjects,
String brokerVolume,
String configMapName,
String pluginBrokerImage) {
String pluginBrokerImage,
List<Pair<String, String>> envVars) {
this.kubernetesNamespace = kubernetesNamespace;
this.workspaceId = workspaceId;
this.cheWebsocketEndpoint = cheWebsocketEndpoint;
Expand All @@ -73,6 +79,7 @@ public DeployBroker(
this.brokerVolume = brokerVolume;
this.configMapName = configMapName;
this.pluginBrokerImage = pluginBrokerImage;
this.envVars = envVars.stream().map(this::asEnvVar).collect(toList());
}

@Override
Expand Down Expand Up @@ -109,6 +116,7 @@ private Pod newPod(String podName, String workspaceId) {
.withVolumeMounts(
newVolumeMount(pvcClaimProjects, "/plugins", workspaceId + "/plugins"),
new VolumeMount(confFolder + "/", brokerVolume, true, null))
.withEnv(envVars)
.withNewResources()
.withLimits(singletonMap("memory", new Quantity("250Mi")))
.endResources()
Expand All @@ -131,4 +139,8 @@ private Pod newPod(String podName, String workspaceId) {
.endSpec()
.build();
}

private EnvVar asEnvVar(Pair<String, String> envVar) {
return new EnvVarBuilder().withName(envVar.first).withValue(envVar.second).build();
}
}

0 comments on commit a0fbf69

Please sign in to comment.