use of org.eclipse.che.commons.annotation.Traced in project che-server by eclipse-che.
the class UniqueNamesProvisioner method provision.
@Override
@Traced
public void provision(T k8sEnv, RuntimeIdentity identity) throws InfrastructureException {
final String workspaceId = identity.getWorkspaceId();
TracingTags.WORKSPACE_ID.set(workspaceId);
final Map<String, ConfigMap> configMaps = k8sEnv.getConfigMaps();
Map<String, String> configMapNameTranslation = new HashMap<>();
for (ConfigMap configMap : configMaps.values()) {
final String originalName = configMap.getMetadata().getName();
putLabel(configMap.getMetadata(), Constants.CHE_ORIGINAL_NAME_LABEL, originalName);
final String uniqueName = Names.uniqueResourceName(originalName, workspaceId);
configMap.getMetadata().setName(uniqueName);
configMapNameTranslation.put(originalName, uniqueName);
}
final Collection<PodData> podData = k8sEnv.getPodsData().values();
for (PodData pod : podData) {
final ObjectMeta podMeta = pod.getMetadata();
putLabel(podMeta, Constants.CHE_ORIGINAL_NAME_LABEL, podMeta.getName());
final String podName = Names.uniqueResourceName(podMeta.getName(), workspaceId);
podMeta.setName(podName);
if (configMapNameTranslation.size() > 0) {
rewriteConfigMapNames(pod, configMapNameTranslation);
}
}
// We explicitly need to modify the deployments in the environment to provision unique names
// for them.
final Collection<Deployment> deployments = k8sEnv.getDeploymentsCopy().values();
for (Deployment deployment : deployments) {
final ObjectMeta deploymentMeta = deployment.getMetadata();
final String originalName = deploymentMeta.getName();
putLabel(deploymentMeta, Constants.CHE_ORIGINAL_NAME_LABEL, originalName);
final String deploymentName = Names.uniqueResourceName(originalName, workspaceId);
deploymentMeta.setName(deploymentName);
}
final Set<Ingress> ingresses = new HashSet<>(k8sEnv.getIngresses().values());
k8sEnv.getIngresses().clear();
for (Ingress ingress : ingresses) {
final ObjectMeta ingressMeta = ingress.getMetadata();
putLabel(ingress, Constants.CHE_ORIGINAL_NAME_LABEL, ingressMeta.getName());
final String ingressName = Names.generateName("ingress");
ingressMeta.setName(ingressName);
k8sEnv.getIngresses().put(ingressName, ingress);
}
}
use of org.eclipse.che.commons.annotation.Traced in project che-server by eclipse-che.
the class CommonPVCStrategy method prepare.
@Override
@Traced
public void prepare(KubernetesEnvironment k8sEnv, RuntimeIdentity identity, long timeoutMillis, Map<String, String> startOptions) throws InfrastructureException {
String workspaceId = identity.getWorkspaceId();
TracingTags.WORKSPACE_ID.set(workspaceId);
if (EphemeralWorkspaceUtility.isEphemeral(k8sEnv.getAttributes())) {
return;
}
log.debug("Preparing PVC started for workspace '{}'", workspaceId);
Map<String, PersistentVolumeClaim> claims = k8sEnv.getPersistentVolumeClaims();
if (claims.isEmpty()) {
return;
}
if (claims.size() > 1) {
throw new InfrastructureException(format("The only one PVC MUST be present in common strategy while it contains: %s.", claims.keySet().stream().collect(joining(", "))));
}
PersistentVolumeClaim commonPVC = claims.values().iterator().next();
final KubernetesNamespace namespace = factory.getOrCreate(identity);
final KubernetesPersistentVolumeClaims pvcs = namespace.persistentVolumeClaims();
final Set<String> existing = pvcs.get().stream().map(p -> p.getMetadata().getName()).collect(toSet());
if (!existing.contains(commonPVC.getMetadata().getName())) {
log.debug("Creating PVC for workspace '{}'", workspaceId);
pvcs.create(commonPVC);
if (waitBound) {
log.debug("Waiting for PVC for workspace '{}' to be bound", workspaceId);
pvcs.waitBound(commonPVC.getMetadata().getName(), timeoutMillis);
}
}
final String[] subpaths = (String[]) commonPVC.getAdditionalProperties().remove(format(SUBPATHS_PROPERTY_FMT, workspaceId));
if (preCreateDirs && subpaths != null) {
pvcSubPathHelper.createDirs(identity, workspaceId, commonPVC.getMetadata().getName(), startOptions, subpaths);
}
log.debug("Preparing PVC done for workspace '{}'", workspaceId);
}
use of org.eclipse.che.commons.annotation.Traced in project che-server by eclipse-che.
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.commons.annotation.Traced in project che-server by eclipse-che.
the class ContainerResourceProvisioner method provision.
@Override
@Traced
public void provision(KubernetesEnvironment k8sEnv, RuntimeIdentity identity) throws InfrastructureException {
TracingTags.WORKSPACE_ID.set(identity::getWorkspaceId);
final Map<String, InternalMachineConfig> machines = k8sEnv.getMachines();
for (PodData pod : k8sEnv.getPodsData().values()) {
for (Container container : pod.getSpec().getContainers()) {
// make sure that machine configs have settings for RAM limit and request
InternalMachineConfig machineConfig = machines.get(machineName(pod, container));
ResourceLimitAttributesProvisioner.provisionMemory(machineConfig, Containers.getRamLimit(container), Containers.getRamRequest(container), defaultMachineMaxMemorySizeAttribute, defaultMachineRequestMemorySizeAttribute);
// make sure that machine configs have settings for CPU limit and request
ResourceLimitAttributesProvisioner.provisionCPU(machineConfig, Containers.getCpuLimit(container), Containers.getCpuRequest(container), defaultMachineCpuLimitAttribute, defaultMachineCpuRequestAttribute);
// reapply memory and CPU settings to k8s container to make sure that provisioned
// values above are set. Non-positive value means that limit is disabled, so just
// ignoring them.
final Map<String, String> attributes = machineConfig.getAttributes();
long memLimit = Long.parseLong(attributes.get(MEMORY_LIMIT_ATTRIBUTE));
if (memLimit > 0) {
Containers.addRamLimit(container, memLimit);
}
long memRequest = Long.parseLong(attributes.get(MEMORY_REQUEST_ATTRIBUTE));
if (memRequest > 0) {
Containers.addRamRequest(container, memRequest);
}
float cpuLimit = Float.parseFloat(attributes.get(CPU_LIMIT_ATTRIBUTE));
if (cpuLimit > 0) {
Containers.addCpuLimit(container, cpuLimit);
}
float cpuRequest = Float.parseFloat(attributes.get(CPU_REQUEST_ATTRIBUTE));
if (cpuRequest > 0)
Containers.addCpuRequest(container, cpuRequest);
}
}
}
use of org.eclipse.che.commons.annotation.Traced in project devspaces-images by redhat-developer.
the class SidecarToolingProvisioner method provision.
@Traced
@Beta
public void provision(RuntimeIdentity identity, StartSynchronizer startSynchronizer, E environment, Map<String, String> startOptions) throws InfrastructureException {
Collection<PluginFQN> pluginFQNs = pluginFQNParser.parsePlugins(environment.getAttributes());
if (pluginFQNs.isEmpty()) {
return;
}
LOG.debug("Started sidecar tooling provisioning workspace '{}'", identity.getWorkspaceId());
String recipeType = environment.getType();
ChePluginsApplier pluginsApplier = workspaceNextAppliers.get(recipeType);
if (pluginsApplier == null) {
throw new InfrastructureException("Sidecar tooling configuration is not supported with environment type " + recipeType);
}
boolean isEphemeral = EphemeralWorkspaceUtility.isEphemeral(environment.getAttributes());
boolean mergePlugins = shouldMergePlugins(environment.getAttributes());
List<ChePlugin> chePlugins = pluginBrokerManager.getTooling(identity, startSynchronizer, pluginFQNs, isEphemeral, mergePlugins, startOptions);
pluginsApplier.apply(identity, environment, chePlugins);
artifactsBrokerApplier.apply(environment, identity, pluginFQNs, mergePlugins);
LOG.debug("Finished sidecar tooling provisioning workspace '{}'", identity.getWorkspaceId());
}
Aggregations