use of org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment in project che-server by eclipse-che.
the class SidecarServicesProvisionerTest method shouldNotAddServiceForNotdDiscoverableEndpoint.
@Test
public void shouldNotAddServiceForNotdDiscoverableEndpoint() throws Exception {
List<ChePluginEndpoint> actualEndpoints = asList(new ChePluginEndpoint().name("testE1").targetPort(8080), new ChePluginEndpoint().name("testE2").targetPort(10000).attributes(ImmutableMap.of("discoverable", "false")));
endpoints.addAll(actualEndpoints);
KubernetesEnvironment kubernetesEnvironment = KubernetesEnvironment.builder().build();
provisioner.provision(kubernetesEnvironment);
assertEquals(kubernetesEnvironment.getServices(), toK8sServices(ImmutableList.of(new ChePluginEndpoint().name("testE1").targetPort(8080))));
}
use of org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment in project che-server by eclipse-che.
the class SidecarServicesProvisionerTest method shouldAddServiceForEachEndpoint.
@Test
public void shouldAddServiceForEachEndpoint() throws Exception {
List<ChePluginEndpoint> actualEndpoints = asList(new ChePluginEndpoint().name("testE1").targetPort(8080), new ChePluginEndpoint().name("testE2").targetPort(10000));
endpoints.addAll(actualEndpoints);
KubernetesEnvironment kubernetesEnvironment = KubernetesEnvironment.builder().build();
provisioner.provision(kubernetesEnvironment);
assertEquals(kubernetesEnvironment.getServices(), toK8sServices(actualEndpoints));
}
use of org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment in project che-server by eclipse-che.
the class SshKeysProvisioner method doProvisionSshKeys.
private void doProvisionSshKeys(List<SshPairImpl> sshPairs, KubernetesEnvironment k8sEnv, String wsId) {
Map<String, String> data = sshPairs.stream().filter(sshPair -> !isNullOrEmpty(sshPair.getPrivateKey())).collect(toMap(SshPairImpl::getName, sshPair -> Base64.getEncoder().encodeToString(sshPair.getPrivateKey().getBytes())));
Secret secret = new SecretBuilder().addToData(data).withType(SSH_SECRET_TYPE).withNewMetadata().withName(wsId + SSH_SECRET_NAME_SUFFIX).endMetadata().build();
k8sEnv.getSecrets().put(secret.getMetadata().getName(), secret);
k8sEnv.getPodsData().values().forEach(p -> {
mountSshKeySecret(secret.getMetadata().getName(), p.getSpec(), p.getRole() != PodRole.INJECTABLE);
});
}
use of org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment 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.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment in project che-server by eclipse-che.
the class EphemeralWorkspaceAdapter method replacePVCsWithEmptyDir.
private void replacePVCsWithEmptyDir(KubernetesEnvironment k8sEnv) {
for (PodData pod : k8sEnv.getPodsData().values()) {
PodSpec podSpec = pod.getSpec();
podSpec.getVolumes().stream().filter(v -> v.getPersistentVolumeClaim() != null).forEach(v -> {
v.setPersistentVolumeClaim(null);
v.setEmptyDir(new EmptyDirVolumeSource());
});
}
}
Aggregations