Search in sources :

Example 61 with KubernetesEnvironment

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))));
}
Also used : ChePluginEndpoint(org.eclipse.che.api.workspace.server.wsplugins.model.ChePluginEndpoint) KubernetesEnvironment(org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment) Test(org.testng.annotations.Test)

Example 62 with KubernetesEnvironment

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));
}
Also used : ChePluginEndpoint(org.eclipse.che.api.workspace.server.wsplugins.model.ChePluginEndpoint) KubernetesEnvironment(org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment) Test(org.testng.annotations.Test)

Example 63 with KubernetesEnvironment

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);
    });
}
Also used : VolumeMount(io.fabric8.kubernetes.api.model.VolumeMount) ConfigMapVolumeSourceBuilder(io.fabric8.kubernetes.api.model.ConfigMapVolumeSourceBuilder) Container(io.fabric8.kubernetes.api.model.Container) Date(java.util.Date) ZonedDateTime(java.time.ZonedDateTime) PodRole(org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment.PodRole) LoggerFactory(org.slf4j.LoggerFactory) Strings.isNullOrEmpty(com.google.common.base.Strings.isNullOrEmpty) KubernetesEnvironment(org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment) HashMap(java.util.HashMap) NotNull(jakarta.validation.constraints.NotNull) Traced(org.eclipse.che.commons.annotation.Traced) Collections.singletonList(java.util.Collections.singletonList) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) SshPair(org.eclipse.che.api.ssh.shared.model.SshPair) VolumeMountBuilder(io.fabric8.kubernetes.api.model.VolumeMountBuilder) Collectors.toMap(java.util.stream.Collectors.toMap) PodSpec(io.fabric8.kubernetes.api.model.PodSpec) Map(java.util.Map) ConflictException(org.eclipse.che.api.core.ConflictException) NOT_ABLE_TO_PROVISION_SSH_KEYS_MESSAGE(org.eclipse.che.workspace.infrastructure.kubernetes.Warnings.NOT_ABLE_TO_PROVISION_SSH_KEYS_MESSAGE) RuntimeEventsPublisher(org.eclipse.che.workspace.infrastructure.kubernetes.util.RuntimeEventsPublisher) NOT_ABLE_TO_PROVISION_SSH_KEYS(org.eclipse.che.workspace.infrastructure.kubernetes.Warnings.NOT_ABLE_TO_PROVISION_SSH_KEYS) SecretVolumeSourceBuilder(io.fabric8.kubernetes.api.model.SecretVolumeSourceBuilder) Logger(org.slf4j.Logger) WarningImpl(org.eclipse.che.api.workspace.server.model.impl.WarningImpl) KubernetesObjectUtil.isValidConfigMapKeyName(org.eclipse.che.workspace.infrastructure.kubernetes.namespace.KubernetesObjectUtil.isValidConfigMapKeyName) VolumeBuilder(io.fabric8.kubernetes.api.model.VolumeBuilder) SshPairImpl(org.eclipse.che.api.ssh.server.model.impl.SshPairImpl) String.format(java.lang.String.format) ConfigMap(io.fabric8.kubernetes.api.model.ConfigMap) SshManager(org.eclipse.che.api.ssh.server.SshManager) ConfigMapBuilder(io.fabric8.kubernetes.api.model.ConfigMapBuilder) InfrastructureException(org.eclipse.che.api.workspace.server.spi.InfrastructureException) Collectors.toList(java.util.stream.Collectors.toList) Base64(java.util.Base64) List(java.util.List) ServerException(org.eclipse.che.api.core.ServerException) TracingTags(org.eclipse.che.commons.tracing.TracingTags) RuntimeIdentity(org.eclipse.che.api.core.model.workspace.runtime.RuntimeIdentity) Warnings(org.eclipse.che.workspace.infrastructure.kubernetes.Warnings) Secret(io.fabric8.kubernetes.api.model.Secret) VisibleForTesting(com.google.common.annotations.VisibleForTesting) SecretBuilder(io.fabric8.kubernetes.api.model.SecretBuilder) Pattern(java.util.regex.Pattern) Secret(io.fabric8.kubernetes.api.model.Secret) SecretBuilder(io.fabric8.kubernetes.api.model.SecretBuilder)

Example 64 with KubernetesEnvironment

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);
}
Also used : VolumeMount(io.fabric8.kubernetes.api.model.VolumeMount) Workspace(org.eclipse.che.api.core.model.workspace.Workspace) PERSONAL_ACCOUNT(org.eclipse.che.api.user.server.UserManager.PERSONAL_ACCOUNT) Inject(com.google.inject.Inject) Page(org.eclipse.che.api.core.Page) LoggerFactory(org.slf4j.LoggerFactory) Strings.isNullOrEmpty(com.google.common.base.Strings.isNullOrEmpty) KubernetesEnvironment(org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment) AccountImpl(org.eclipse.che.account.spi.AccountImpl) Traced(org.eclipse.che.commons.annotation.Traced) KubernetesNamespace(org.eclipse.che.workspace.infrastructure.kubernetes.namespace.KubernetesNamespace) Map(java.util.Map) Named(javax.inject.Named) Collectors.toSet(java.util.stream.Collectors.toSet) KubernetesObjectUtil.newPVC(org.eclipse.che.workspace.infrastructure.kubernetes.namespace.KubernetesObjectUtil.newPVC) WorkspaceManager(org.eclipse.che.api.workspace.server.WorkspaceManager) Logger(org.slf4j.Logger) Set(java.util.Set) KubernetesPersistentVolumeClaims(org.eclipse.che.workspace.infrastructure.kubernetes.namespace.KubernetesPersistentVolumeClaims) Collectors(java.util.stream.Collectors) String.format(java.lang.String.format) Collectors.joining(java.util.stream.Collectors.joining) KubernetesNamespaceFactory(org.eclipse.che.workspace.infrastructure.kubernetes.namespace.KubernetesNamespaceFactory) InfrastructureException(org.eclipse.che.api.workspace.server.spi.InfrastructureException) ServerException(org.eclipse.che.api.core.ServerException) TracingTags(org.eclipse.che.commons.tracing.TracingTags) RuntimeIdentity(org.eclipse.che.api.core.model.workspace.runtime.RuntimeIdentity) PersistentVolumeClaim(io.fabric8.kubernetes.api.model.PersistentVolumeClaim) WorkspaceImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl) PersistentVolumeClaim(io.fabric8.kubernetes.api.model.PersistentVolumeClaim) InfrastructureException(org.eclipse.che.api.workspace.server.spi.InfrastructureException) KubernetesPersistentVolumeClaims(org.eclipse.che.workspace.infrastructure.kubernetes.namespace.KubernetesPersistentVolumeClaims) KubernetesNamespace(org.eclipse.che.workspace.infrastructure.kubernetes.namespace.KubernetesNamespace) Traced(org.eclipse.che.commons.annotation.Traced)

Example 65 with KubernetesEnvironment

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());
        });
    }
}
Also used : Logger(org.slf4j.Logger) LoggerFactory(org.slf4j.LoggerFactory) KubernetesEnvironment(org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment) HashMap(java.util.HashMap) Singleton(javax.inject.Singleton) Inject(javax.inject.Inject) InfrastructureException(org.eclipse.che.api.workspace.server.spi.InfrastructureException) EmptyDirVolumeSource(io.fabric8.kubernetes.api.model.EmptyDirVolumeSource) PodSpec(io.fabric8.kubernetes.api.model.PodSpec) Map(java.util.Map) RuntimeIdentity(org.eclipse.che.api.core.model.workspace.runtime.RuntimeIdentity) PodData(org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment.PodData) PersistentVolumeClaim(io.fabric8.kubernetes.api.model.PersistentVolumeClaim) PodData(org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment.PodData) EmptyDirVolumeSource(io.fabric8.kubernetes.api.model.EmptyDirVolumeSource) PodSpec(io.fabric8.kubernetes.api.model.PodSpec)

Aggregations

KubernetesEnvironment (org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment)94 Test (org.testng.annotations.Test)68 Map (java.util.Map)30 HashMap (java.util.HashMap)28 Service (io.fabric8.kubernetes.api.model.Service)26 Container (io.fabric8.kubernetes.api.model.Container)24 Pod (io.fabric8.kubernetes.api.model.Pod)24 PodBuilder (io.fabric8.kubernetes.api.model.PodBuilder)22 CommandImpl (org.eclipse.che.api.workspace.server.model.impl.CommandImpl)20 PodData (org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment.PodData)20 ArrayList (java.util.ArrayList)19 ConfigMap (io.fabric8.kubernetes.api.model.ConfigMap)18 IntOrString (io.fabric8.kubernetes.api.model.IntOrString)18 ServicePort (io.fabric8.kubernetes.api.model.ServicePort)18 RuntimeIdentity (org.eclipse.che.api.core.model.workspace.runtime.RuntimeIdentity)18 InfrastructureException (org.eclipse.che.api.workspace.server.spi.InfrastructureException)18 PersistentVolumeClaim (io.fabric8.kubernetes.api.model.PersistentVolumeClaim)14 PodSpec (io.fabric8.kubernetes.api.model.PodSpec)14 ServerConfigImpl (org.eclipse.che.api.workspace.server.model.impl.ServerConfigImpl)14 InternalRecipe (org.eclipse.che.api.workspace.server.spi.environment.InternalRecipe)14