use of org.eclipse.che.api.workspace.server.spi.environment.InternalMachineConfig in project devspaces-images by redhat-developer.
the class KubernetesInternalRuntime method storeStartingMachine.
/**
* Puts createdPod in the {@code machines} map and sends the starting event for this machine
*/
private void storeStartingMachine(Pod createdPod, ObjectMeta toCreateMeta, Map<String, InternalMachineConfig> machineConfigs, ServerResolver serverResolver) throws InfrastructureException {
final String workspaceId = getContext().getIdentity().getWorkspaceId();
for (Container container : createdPod.getSpec().getContainers()) {
String machineName = Names.machineName(toCreateMeta, container);
LOG.debug("Creating machine '{}' in workspace '{}'", machineName, workspaceId);
// Sometimes we facing NPE trying to retrieve machine config. Possible names mismatch. Need to
// get more info on that cases.
InternalMachineConfig machineConfig = Optional.ofNullable(machineConfigs.get(machineName)).orElseThrow(() -> {
LOG.error("Workspace '{}' start failed. Machine with name '{}' requested but not found in configs map. Present machines are: {}.", workspaceId, machineName, String.join(",", machineConfigs.keySet()));
return new InfrastructureException(format("Unable to start the workspace '%s' due to an internal inconsistency while composing the workspace runtime." + "Please report a bug. If possible, include the details from Che devfile and server log in bug report (your admin can help with that)", workspaceId));
});
machines.put(getContext().getIdentity(), new KubernetesMachineImpl(workspaceId, machineName, createdPod.getMetadata().getName(), container.getName(), MachineStatus.STARTING, machineConfig.getAttributes(), serverResolver.resolve(machineName)));
eventPublisher.sendStartingEvent(machineName, getContext().getIdentity());
}
}
use of org.eclipse.che.api.workspace.server.spi.environment.InternalMachineConfig in project devspaces-images by redhat-developer.
the class PVCProvisioner method convertCheVolumes.
/**
* Converts {@link Volume} specified in {@link MachineConfig#getVolumes()} to {@link
* PersistentVolumeClaim}s and provision them to {@link KubernetesEnvironment}. The machines
* corresponding pods and containers are updated in accordance.
*
* @param k8sEnv environment to provision
* @param workspaceId identifier of workspace to which the specified environment belongs to
*/
public void convertCheVolumes(KubernetesEnvironment k8sEnv, String workspaceId) {
Map<String, PersistentVolumeClaim> volumeName2PVC = groupByVolumeName(k8sEnv.getPersistentVolumeClaims().values());
for (PodData pod : k8sEnv.getPodsData().values()) {
final PodSpec podSpec = pod.getSpec();
List<Container> containers = new ArrayList<>();
containers.addAll(podSpec.getContainers());
containers.addAll(podSpec.getInitContainers());
for (Container container : containers) {
final String machineName = Names.machineName(pod, container);
InternalMachineConfig machineConfig = k8sEnv.getMachines().get(machineName);
if (machineConfig == null) {
continue;
}
Map<String, Volume> volumes = machineConfig.getVolumes();
addMachineVolumes(workspaceId, k8sEnv, volumeName2PVC, pod, container, volumes);
}
}
}
use of org.eclipse.che.api.workspace.server.spi.environment.InternalMachineConfig in project devspaces-images by redhat-developer.
the class EnvVarsConverter method provision.
@Override
@Traced
public void provision(KubernetesEnvironment k8sEnv, RuntimeIdentity identity) throws InfrastructureException {
TracingTags.WORKSPACE_ID.set(identity::getWorkspaceId);
for (PodData pod : k8sEnv.getPodsData().values()) {
for (Container container : pod.getSpec().getContainers()) {
String machineName = Names.machineName(pod, container);
InternalMachineConfig machineConf = k8sEnv.getMachines().get(machineName);
// we need to combine the env vars from the machine config with the variables already
// present in the container. Let's key the variables by name and use the map for merging
Map<String, EnvVar> envVars = machineConf.getEnv().entrySet().stream().map(e -> new EnvVar(e.getKey(), e.getValue(), null)).collect(toMap(EnvVar::getName, identity()));
// the env vars defined in our machine config take precedence over the ones already defined
// in the container, if any
container.getEnv().forEach(v -> envVars.putIfAbsent(v.getName(), v));
// The environment variable expansion only works if a variable that is referenced
// is already defined earlier in the list of environment variables.
// We need to produce a list where variables that reference others always appear later
// in the list.
List<EnvVar> sorted = topoSort.sort(envVars.values());
container.setEnv(sorted);
}
}
}
use of org.eclipse.che.api.workspace.server.spi.environment.InternalMachineConfig in project devspaces-images by redhat-developer.
the class KubernetesPluginsToolingApplierTest method setsSourceAndPluginAttributeForMachineAssociatedWithSidecar.
@Test
public void setsSourceAndPluginAttributeForMachineAssociatedWithSidecar() throws Exception {
ChePlugin chePlugin = createChePlugin();
applier.apply(runtimeIdentity, internalEnvironment, singletonList(chePlugin));
InternalMachineConfig machineConfig = getOneAndOnlyNonUserMachine(internalEnvironment);
Map<String, String> attributes = machineConfig.getAttributes();
assertEquals(attributes.get(CONTAINER_SOURCE_ATTRIBUTE), TOOL_CONTAINER_SOURCE);
assertEquals(attributes.get(PLUGIN_MACHINE_ATTRIBUTE), chePlugin.getId());
}
use of org.eclipse.che.api.workspace.server.spi.environment.InternalMachineConfig in project devspaces-images by redhat-developer.
the class KubernetesPluginsToolingApplierTest method shouldUseContainerNameForMachinesName.
@Test
public void shouldUseContainerNameForMachinesName() throws Exception {
// given
internalEnvironment.getMachines().clear();
ChePlugin chePlugin = createChePlugin("publisher/plugin1/0.2.1", createContainer("container1"));
// when
applier.apply(runtimeIdentity, internalEnvironment, singletonList(chePlugin));
// then
Map<String, InternalMachineConfig> machines = internalEnvironment.getMachines();
assertEquals(machines.size(), 1);
validateContainerNameName(machines.keySet().iterator().next(), "container1");
}
Aggregations