use of org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment in project che-server by eclipse-che.
the class KubernetesPluginsToolingApplier method apply.
@Override
public void apply(RuntimeIdentity runtimeIdentity, InternalEnvironment internalEnvironment, Collection<ChePlugin> chePlugins) throws InfrastructureException {
if (chePlugins.isEmpty()) {
return;
}
KubernetesEnvironment k8sEnv = (KubernetesEnvironment) internalEnvironment;
Map<String, PodData> pods = k8sEnv.getPodsData();
switch(pods.size()) {
case 0:
addToolingPod(k8sEnv);
pods = k8sEnv.getPodsData();
break;
case 1:
break;
default:
throw new InfrastructureException("Che plugins tooling configuration can be applied to a workspace with one pod only");
}
PodData pod = pods.values().iterator().next();
CommandsResolver commandsResolver = new CommandsResolver(k8sEnv);
for (ChePlugin chePlugin : chePlugins) {
Map<String, ComponentImpl> devfilePlugins = k8sEnv.getDevfile().getComponents().stream().filter(c -> c.getType().equals("cheEditor") || c.getType().equals("chePlugin")).collect(Collectors.toMap(ComponentImpl::getId, Function.identity()));
if (!devfilePlugins.containsKey(chePlugin.getId())) {
throw new InfrastructureException(String.format("The downloaded plugin '%s' configuration does not have the " + "corresponding component in devfile. Devfile contains the following cheEditor/chePlugins: %s", chePlugin.getId(), devfilePlugins.keySet()));
}
ComponentImpl pluginRelatedComponent = devfilePlugins.get(chePlugin.getId());
for (CheContainer container : chePlugin.getInitContainers()) {
Container k8sInitContainer = toK8sContainer(container);
envVars.apply(k8sInitContainer, pluginRelatedComponent.getEnv());
chePluginsVolumeApplier.applyVolumes(pod, k8sInitContainer, container.getVolumes(), k8sEnv);
pod.getSpec().getInitContainers().add(k8sInitContainer);
}
Collection<CommandImpl> pluginRelatedCommands = commandsResolver.resolve(chePlugin);
for (CheContainer container : chePlugin.getContainers()) {
addSidecar(pod, container, chePlugin, k8sEnv, pluginRelatedCommands, pluginRelatedComponent, runtimeIdentity);
}
}
chePlugins.forEach(chePlugin -> populateWorkspaceEnvVars(chePlugin, k8sEnv));
}
use of org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment in project che-server by eclipse-che.
the class KubernetesArtifactsBrokerApplierTest method setUp.
@BeforeMethod
public void setUp() throws Exception {
// Workspace env setup
ObjectMeta workspacePodMeta = new ObjectMetaBuilder().withAnnotations(workspacePodAnnotations).build();
workspacePod = new PodBuilder().withMetadata(workspacePodMeta).withSpec(new PodSpec()).build();
Map<String, ConfigMap> workspaceConfigMaps = new HashMap<>();
workspaceEnvironment = KubernetesEnvironment.builder().setPods(ImmutableMap.of(WORKSPACE_POD_NAME, workspacePod)).setMachines(new HashMap<>()).setConfigMaps(workspaceConfigMaps).build();
// Broker env setup
ObjectMeta brokerPodMeta = new ObjectMetaBuilder().withAnnotations(brokerPodAnnotations).build();
brokerContainer = new ContainerBuilder().withName(BROKER_CONTAINER_NAME).build();
brokerVolume = new VolumeBuilder().build();
Pod brokerPod = new PodBuilder().withMetadata(brokerPodMeta).withNewSpec().withContainers(brokerContainer).withVolumes(brokerVolume).endSpec().build();
brokerConfigMap = new ConfigMapBuilder().addToData(brokerConfigMapData).build();
KubernetesEnvironment brokerEnvironment = KubernetesEnvironment.builder().setPods(ImmutableMap.of(BROKER_POD_NAME, brokerPod)).setConfigMaps(ImmutableMap.of(BROKER_CONFIGMAP_NAME, brokerConfigMap)).setMachines(ImmutableMap.of(BROKER_MACHINE_NAME, brokerMachine)).build();
doReturn(brokerEnvironment).when(brokerEnvironmentFactory).createForArtifactsBroker(any(), any(), anyBoolean());
applier = new KubernetesArtifactsBrokerApplier<>(brokerEnvironmentFactory);
}
use of org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment in project che-server by eclipse-che.
the class GatewayTlsProvisionerTest method provisionTlsForGatewayRouteConfigmaps.
@Test(dataProvider = "tlsProvisionData")
public void provisionTlsForGatewayRouteConfigmaps(ServerConfigImpl server, boolean tlsEnabled, String expectedProtocol) throws Exception {
// given
Map<String, String> composedAnnotations = new HashMap<>(annotations);
composedAnnotations.putAll(Annotations.newSerializer().server("server", server).machineName(machine).annotations());
ConfigMap routeConfigMap = new ConfigMapBuilder().withNewMetadata().withName("route").withAnnotations(composedAnnotations).endMetadata().build();
GatewayTlsProvisioner<KubernetesEnvironment> gatewayTlsProvisioner = new GatewayTlsProvisioner<>(tlsEnabled, gatewayConfigmapLabels, tlsProvisionerProvider);
lenient().when(k8sEnv.getConfigMaps()).thenReturn(singletonMap("route", routeConfigMap));
// when
gatewayTlsProvisioner.provision(k8sEnv, runtimeIdentity);
// then
Map<String, ServerConfigImpl> servers = Annotations.newDeserializer(routeConfigMap.getMetadata().getAnnotations()).servers();
assertEquals(servers.get("server").getProtocol(), expectedProtocol);
}
use of org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment in project che-server by eclipse-che.
the class KubernetesPreviewUrlCommandProvisionerTest method shouldUpdateCommandWhenServiceAndIngressFound.
@Test
public void shouldUpdateCommandWhenServiceAndIngressFound() throws InfrastructureException {
final int PORT = 8080;
final String SERVICE_PORT_NAME = "service-" + PORT;
List<CommandImpl> commands = Collections.singletonList(new CommandImpl("a", "a", "a", new PreviewUrlImpl(PORT, null), Collections.emptyMap()));
KubernetesEnvironment env = KubernetesEnvironment.builder().setCommands(new ArrayList<>(commands)).build();
Mockito.when(mockNamespace.services()).thenReturn(mockServices);
Service service = new Service();
ObjectMeta metadata = new ObjectMeta();
metadata.setName("servicename");
service.setMetadata(metadata);
ServiceSpec spec = new ServiceSpec();
spec.setPorts(Collections.singletonList(new ServicePort(null, SERVICE_PORT_NAME, null, PORT, "TCP", new IntOrString(PORT))));
service.setSpec(spec);
Mockito.when(mockServices.get()).thenReturn(Collections.singletonList(service));
Ingress ingress = new Ingress();
IngressSpec ingressSpec = new IngressSpec();
IngressRule rule = new IngressRule("testhost", new HTTPIngressRuleValue(Collections.singletonList(new HTTPIngressPath(new IngressBackend(null, new IngressServiceBackend("servicename", new ServiceBackendPort(SERVICE_PORT_NAME, PORT))), null, null))));
ingressSpec.setRules(Collections.singletonList(rule));
ingress.setSpec(ingressSpec);
Mockito.when(mockNamespace.ingresses()).thenReturn(mockIngresses);
Mockito.when(mockIngresses.get()).thenReturn(Collections.singletonList(ingress));
previewUrlCommandProvisioner.provision(env, mockNamespace);
assertTrue(env.getCommands().get(0).getAttributes().containsKey("previewUrl"));
assertEquals(env.getCommands().get(0).getAttributes().get("previewUrl"), "testhost");
assertTrue(env.getWarnings().isEmpty());
}
use of org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment in project che-server by eclipse-che.
the class ProxySettingsProvisionerTest method shouldApplyProxySettingsToAllContainers.
@Test
public void shouldApplyProxySettingsToAllContainers() throws Exception {
Map<String, Pod> pods = new HashMap<>();
Pod pod1 = pods.put("pod1", buildPod("pod1", buildContainers(2)));
pods.put("pod2", buildPod("pod2", buildContainers(3)));
KubernetesEnvironment k8sEnv = KubernetesEnvironment.builder().setPods(pods).build();
provisioner.provision(k8sEnv, runtimeId);
assertTrue(k8sEnv.getPodsData().values().stream().flatMap(pod -> pod.getSpec().getContainers().stream()).allMatch(container -> container.getEnv().contains(new EnvVar(HTTP_PROXY, HTTP_PROXY_VALUE, null)) && container.getEnv().contains(new EnvVar(HTTPS_PROXY, HTTPS_PROXY_VALUE, null)) && container.getEnv().contains(new EnvVar(NO_PROXY, NO_PROXY_VALUE, null))));
}
Aggregations