use of org.eclipse.che.commons.annotation.Traced in project devspaces-images by redhat-developer.
the class KubernetesInternalRuntime method doStartMachine.
/**
* Creates Kubernetes pods and resolves servers using the specified serverResolver.
*
* @param serverResolver server resolver that provide servers by container
* @throws InfrastructureException when any error occurs while creating Kubernetes pods
*/
@Traced
protected void doStartMachine(ServerResolver serverResolver) throws InfrastructureException {
final KubernetesEnvironment environment = getContext().getEnvironment();
final Map<String, InternalMachineConfig> machineConfigs = environment.getMachines();
final String workspaceId = getContext().getIdentity().getWorkspaceId();
LOG.debug("Begin pods creation for workspace '{}'", workspaceId);
PodMerger podMerger = new PodMerger();
Map<String, Map<String, Pod>> injectablePods = environment.getInjectablePodsCopy();
for (Pod toCreate : environment.getPodsCopy().values()) {
ObjectMeta toCreateMeta = toCreate.getMetadata();
List<PodData> injectables = getAllInjectablePods(toCreate, injectablePods);
Pod createdPod;
if (injectables.isEmpty()) {
createdPod = namespace.deployments().deploy(toCreate);
} else {
try {
injectables.add(new PodData(toCreate));
Deployment merged = podMerger.merge(injectables);
merged.getMetadata().setName(toCreate.getMetadata().getName());
createdPod = namespace.deployments().deploy(merged);
} catch (ValidationException e) {
throw new InfrastructureException(e);
}
}
LOG.debug("Creating pod '{}' in workspace '{}'", toCreateMeta.getName(), workspaceId);
storeStartingMachine(createdPod, createdPod.getMetadata(), machineConfigs, serverResolver);
}
for (Deployment toCreate : environment.getDeploymentsCopy().values()) {
PodTemplateSpec template = toCreate.getSpec().getTemplate();
List<PodData> injectables = getAllInjectablePods(template.getMetadata(), template.getSpec().getContainers(), injectablePods);
Pod createdPod;
if (injectables.isEmpty()) {
createdPod = namespace.deployments().deploy(toCreate);
} else {
try {
injectables.add(new PodData(toCreate));
Deployment deployment = podMerger.merge(injectables);
deployment.getMetadata().setName(toCreate.getMetadata().getName());
putAnnotations(deployment.getMetadata(), toCreate.getMetadata().getAnnotations());
putLabels(deployment.getMetadata(), toCreate.getMetadata().getLabels());
createdPod = namespace.deployments().deploy(deployment);
} catch (ValidationException e) {
throw new InfrastructureException(e);
}
}
LOG.debug("Creating deployment '{}' in workspace '{}'", createdPod.getMetadata().getName(), workspaceId);
storeStartingMachine(createdPod, createdPod.getMetadata(), machineConfigs, serverResolver);
}
LOG.debug("Pods creation finished in workspace '{}'", workspaceId);
}
use of org.eclipse.che.commons.annotation.Traced in project devspaces-images by redhat-developer.
the class KubernetesInternalRuntime method createConfigMaps.
@Traced
protected List<ConfigMap> createConfigMaps(KubernetesEnvironment env, RuntimeIdentity identity) throws InfrastructureException {
TracingTags.WORKSPACE_ID.set(identity.getWorkspaceId());
List<ConfigMap> createdConfigMaps = new ArrayList<>();
List<ConfigMap> cheNamespaceConfigMaps = new ArrayList<>();
for (ConfigMap configMap : env.getConfigMaps().values()) {
if (shouldCreateInCheNamespace(configMap)) {
// we collect the che namespace configmaps into separate list
cheNamespaceConfigMaps.add(configMap);
} else {
createdConfigMaps.add(namespace.configMaps().create(configMap));
}
}
// create che namespace configmaps in one batch, because we're doing some extra checks inside
createdConfigMaps.addAll(cheNamespace.createConfigMaps(cheNamespaceConfigMaps, identity));
return createdConfigMaps;
}
use of org.eclipse.che.commons.annotation.Traced in project devspaces-images by redhat-developer.
the class KubernetesInternalRuntime method startMachines.
/**
* Create all machine related objects and start machines.
*
* @throws InfrastructureException when any error occurs while creating Kubernetes objects
*/
@Traced
protected void startMachines() throws InfrastructureException {
KubernetesEnvironment k8sEnv = getContext().getEnvironment();
String workspaceId = getContext().getIdentity().getWorkspaceId();
createSecrets(k8sEnv, workspaceId);
List<ConfigMap> createdConfigMaps = createConfigMaps(k8sEnv, getContext().getIdentity());
List<Service> createdServices = createServices(k8sEnv, workspaceId);
// needed for resolution later on, even though n routes are actually created by ingress
// /workspace{wsid}/server-{port} => service({wsid}):server-port => pod({wsid}):{port}
List<Ingress> readyIngresses = createIngresses(k8sEnv, workspaceId);
listenEvents();
doStartMachine(serverResolverFactory.create(createdServices, readyIngresses, createdConfigMaps));
}
use of org.eclipse.che.commons.annotation.Traced in project devspaces-images by redhat-developer.
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 devspaces-images by redhat-developer.
the class UniqueWorkspacePVCStrategy method prepare.
@Traced
@Override
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;
}
if (k8sEnv.getPersistentVolumeClaims().isEmpty()) {
// no PVCs to prepare
return;
}
final KubernetesPersistentVolumeClaims k8sClaims = factory.getOrCreate(identity).persistentVolumeClaims();
LOG.debug("Creating PVCs for workspace '{}'", workspaceId);
k8sClaims.createIfNotExist(k8sEnv.getPersistentVolumeClaims().values());
if (waitBound) {
LOG.debug("Waiting for PVC(s) of workspace '{}' to be bound", workspaceId);
for (PersistentVolumeClaim pvc : k8sEnv.getPersistentVolumeClaims().values()) {
k8sClaims.waitBound(pvc.getMetadata().getName(), timeoutMillis);
}
}
LOG.debug("Preparing PVCs done for workspace '{}'", workspaceId);
}
Aggregations