use of org.eclipse.che.api.workspace.server.spi.environment.InternalMachineConfig in project devspaces-images by redhat-developer.
the class BrokerEnvironmentFactory method getBrokersConfigs.
protected BrokersConfigs getBrokersConfigs(Collection<PluginFQN> pluginFQNs, RuntimeIdentity runtimeID, String brokerImage, boolean mergePlugins) throws InfrastructureException {
String configMapName = generateUniqueName(CONFIG_MAP_NAME_SUFFIX);
String configMapVolume = generateUniqueName(BROKER_VOLUME);
ConfigMap configMap = newConfigMap(configMapName, pluginFQNs);
Pod pod = newPod();
List<EnvVar> envVars = Stream.of(authEnableEnvVarProvider.get(runtimeID), machineTokenEnvVarProvider.get(runtimeID)).map(this::asEnvVar).collect(Collectors.toList());
Container container = newContainer(runtimeID, envVars, brokerImage, configMapVolume, mergePlugins);
pod.getSpec().getContainers().add(container);
pod.getSpec().getVolumes().add(newConfigMapVolume(configMapName, configMapVolume));
InternalMachineConfig machineConfig = new InternalMachineConfig();
String machineName = Names.machineName(pod.getMetadata(), container);
BrokersConfigs configs = new BrokersConfigs();
configs.configMaps = singletonMap(configMapName, configMap);
configs.machines = singletonMap(machineName, machineConfig);
configs.pods = singletonMap(pod.getMetadata().getName(), pod);
return configs;
}
use of org.eclipse.che.api.workspace.server.spi.environment.InternalMachineConfig in project che-server by eclipse-che.
the class ServersConverter method provision.
@Override
@Traced
public void provision(T k8sEnv, RuntimeIdentity identity) throws InfrastructureException {
TracingTags.WORKSPACE_ID.set(identity::getWorkspaceId);
SecureServerExposer<T> secureServerExposer = secureServerExposerFactoryProvider.get(k8sEnv).create(identity);
for (PodData podConfig : k8sEnv.getPodsData().values()) {
final PodSpec podSpec = podConfig.getSpec();
for (Container containerConfig : podSpec.getContainers()) {
String machineName = Names.machineName(podConfig, containerConfig);
InternalMachineConfig machineConfig = k8sEnv.getMachines().get(machineName);
if (!machineConfig.getServers().isEmpty()) {
KubernetesServerExposer kubernetesServerExposer = new KubernetesServerExposer<>(externalServerExposer, secureServerExposer, machineName, podConfig, containerConfig, k8sEnv);
kubernetesServerExposer.expose(machineConfig.getServers());
}
}
}
}
use of org.eclipse.che.api.workspace.server.spi.environment.InternalMachineConfig in project che-server by eclipse-che.
the class EnvVarsConverterTest method setUp.
@BeforeMethod
public void setUp() {
testContainer = new Container();
PodSpec podSpec = new PodSpec();
podSpec.setContainers(singletonList(testContainer));
ObjectMeta podMeta = new ObjectMeta();
podMeta.setName("pod");
Pod pod = new Pod();
pod.setSpec(podSpec);
pod.setMetadata(podMeta);
Map<String, Pod> pods = new HashMap<>();
pods.put("pod", pod);
environment = KubernetesEnvironment.builder().setPods(pods).build();
machine = new InternalMachineConfig();
environment.setMachines(Collections.singletonMap(Names.machineName(podMeta, testContainer), machine));
identity = new RuntimeIdentityImpl("wsId", "blah", "bleh", "infraNamespace");
}
use of org.eclipse.che.api.workspace.server.spi.environment.InternalMachineConfig in project che-server by eclipse-che.
the class EnvironmentVariableSecretApplierTest method shouldProvisionContainersWithAutomountOverrideTrue.
@Test
public void shouldProvisionContainersWithAutomountOverrideTrue() throws Exception {
Container container_match1 = new ContainerBuilder().withName("maven").build();
Container container_match2 = new ContainerBuilder().withName("other").build();
DevfileImpl mock_defvile = mock(DevfileImpl.class);
ComponentImpl component = new ComponentImpl();
component.setAlias("maven");
component.setAutomountWorkspaceSecrets(true);
when(podSpec.getContainers()).thenReturn(ImmutableList.of(container_match1, container_match2));
InternalMachineConfig internalMachineConfig = new InternalMachineConfig();
internalMachineConfig.getAttributes().put(DEVFILE_COMPONENT_ALIAS_ATTRIBUTE, "maven");
when(environment.getMachines()).thenReturn(ImmutableMap.of("maven", internalMachineConfig));
when(environment.getDevfile()).thenReturn(mock_defvile);
when(mock_defvile.getComponents()).thenReturn(singletonList(component));
Secret secret = new SecretBuilder().withData(singletonMap("foo", "random")).withMetadata(new ObjectMetaBuilder().withName("test_secret").withAnnotations(ImmutableMap.of(ANNOTATION_ENV_NAME, "MY_FOO", ANNOTATION_MOUNT_AS, "env", ANNOTATION_AUTOMOUNT, "false")).withLabels(emptyMap()).build()).build();
secretApplier.applySecret(environment, runtimeIdentity, secret);
// only first container has env set
assertEquals(container_match1.getEnv().size(), 1);
EnvVar var = container_match1.getEnv().get(0);
assertEquals(var.getName(), "MY_FOO");
assertEquals(var.getValueFrom().getSecretKeyRef().getName(), "test_secret");
assertEquals(var.getValueFrom().getSecretKeyRef().getKey(), "foo");
assertEquals(container_match2.getEnv().size(), 0);
}
use of org.eclipse.che.api.workspace.server.spi.environment.InternalMachineConfig in project che-server by eclipse-che.
the class BrokerEnvironmentFactory method getBrokersConfigs.
protected BrokersConfigs getBrokersConfigs(Collection<PluginFQN> pluginFQNs, RuntimeIdentity runtimeID, String brokerImage, boolean mergePlugins) throws InfrastructureException {
String configMapName = generateUniqueName(CONFIG_MAP_NAME_SUFFIX);
String configMapVolume = generateUniqueName(BROKER_VOLUME);
ConfigMap configMap = newConfigMap(configMapName, pluginFQNs);
Pod pod = newPod();
List<EnvVar> envVars = Stream.of(authEnableEnvVarProvider.get(runtimeID), machineTokenEnvVarProvider.get(runtimeID)).map(this::asEnvVar).collect(Collectors.toList());
Container container = newContainer(runtimeID, envVars, brokerImage, configMapVolume, mergePlugins);
pod.getSpec().getContainers().add(container);
pod.getSpec().getVolumes().add(newConfigMapVolume(configMapName, configMapVolume));
InternalMachineConfig machineConfig = new InternalMachineConfig();
String machineName = Names.machineName(pod.getMetadata(), container);
BrokersConfigs configs = new BrokersConfigs();
configs.configMaps = singletonMap(configMapName, configMap);
configs.machines = singletonMap(machineName, machineConfig);
configs.pods = singletonMap(pod.getMetadata().getName(), pod);
return configs;
}
Aggregations