Search in sources :

Example 1 with ServerServiceBuilder

use of org.eclipse.che.workspace.infrastructure.kubernetes.server.ServerServiceBuilder in project devspaces-images by redhat-developer.

the class AsyncStorageProvisioner method createStorageServiceIfNotExist.

/**
 * Create service for serving rsync connection
 */
private void createStorageServiceIfNotExist(KubernetesClient k8sClient, String namespace, String userId) {
    ServiceResource<Service> serviceResource = k8sClient.services().inNamespace(namespace).withName(ASYNC_STORAGE);
    if (serviceResource.get() != null) {
        // service already exist
        return;
    }
    ObjectMeta meta = new ObjectMeta();
    meta.setName(ASYNC_STORAGE);
    meta.setNamespace(namespace);
    meta.setLabels(of(CHE_USER_ID_LABEL, userId));
    IntOrString targetPort = new IntOrStringBuilder().withIntVal(SERVICE_PORT).withStrVal(valueOf(SERVICE_PORT)).build();
    ServicePort port = new ServicePortBuilder().withName("rsync-port").withProtocol("TCP").withPort(SERVICE_PORT).withTargetPort(targetPort).build();
    ServiceSpec spec = new ServiceSpec();
    spec.setPorts(singletonList(port));
    spec.setSelector(of(CHE_DEPLOYMENT_NAME_LABEL, ASYNC_STORAGE));
    ServerServiceBuilder serviceBuilder = new ServerServiceBuilder();
    Service service = serviceBuilder.withPorts(singletonList(port)).withSelectorEntry(CHE_DEPLOYMENT_NAME_LABEL, ASYNC_STORAGE).withName(ASYNC_STORAGE).build();
    k8sClient.services().inNamespace(namespace).create(service);
}
Also used : ObjectMeta(io.fabric8.kubernetes.api.model.ObjectMeta) ServicePort(io.fabric8.kubernetes.api.model.ServicePort) ServicePortBuilder(io.fabric8.kubernetes.api.model.ServicePortBuilder) IntOrString(io.fabric8.kubernetes.api.model.IntOrString) ServerServiceBuilder(org.eclipse.che.workspace.infrastructure.kubernetes.server.ServerServiceBuilder) ServiceSpec(io.fabric8.kubernetes.api.model.ServiceSpec) Service(io.fabric8.kubernetes.api.model.Service) IntOrStringBuilder(io.fabric8.kubernetes.api.model.IntOrStringBuilder)

Example 2 with ServerServiceBuilder

use of org.eclipse.che.workspace.infrastructure.kubernetes.server.ServerServiceBuilder in project che-server by eclipse-che.

the class AbstractJwtProxyProvisioner method ensureJwtProxyInjected.

private void ensureJwtProxyInjected(KubernetesEnvironment k8sEnv, String machineName, PodData pod) throws InfrastructureException {
    if (!k8sEnv.getMachines().containsKey(JWT_PROXY_MACHINE_NAME)) {
        k8sEnv.getMachines().put(JWT_PROXY_MACHINE_NAME, createJwtProxyMachine());
        Pod jwtProxyPod = createJwtProxyPod();
        k8sEnv.addInjectablePod(machineName, JWT_PROXY_MACHINE_NAME, jwtProxyPod);
        Map<String, String> initConfigMapData = new HashMap<>();
        initConfigMapData.put(JWT_PROXY_PUBLIC_KEY_FILE, PUBLIC_KEY_HEADER + java.util.Base64.getEncoder().encodeToString(keyPair.getPublic().getEncoded()) + PUBLIC_KEY_FOOTER);
        initConfigMapData.put(JWT_PROXY_CONFIG_FILE, proxyConfigBuilder.build());
        ConfigMap jwtProxyConfigMap = new ConfigMapBuilder().withNewMetadata().withName(getConfigMapName()).endMetadata().withData(initConfigMapData).build();
        k8sEnv.getConfigMaps().put(jwtProxyConfigMap.getMetadata().getName(), jwtProxyConfigMap);
        Service jwtProxyService = new ServerServiceBuilder().withName(serviceName).withSelectorEntry(CHE_ORIGINAL_NAME_LABEL, pod.getMetadata().getName()).withMachineName(JWT_PROXY_MACHINE_NAME).withPorts(emptyList()).build();
        k8sEnv.getServices().put(jwtProxyService.getMetadata().getName(), jwtProxyService);
    }
}
Also used : Pod(io.fabric8.kubernetes.api.model.Pod) ConfigMap(io.fabric8.kubernetes.api.model.ConfigMap) HashMap(java.util.HashMap) ConfigMapBuilder(io.fabric8.kubernetes.api.model.ConfigMapBuilder) ServerServiceBuilder(org.eclipse.che.workspace.infrastructure.kubernetes.server.ServerServiceBuilder) Service(io.fabric8.kubernetes.api.model.Service)

Example 3 with ServerServiceBuilder

use of org.eclipse.che.workspace.infrastructure.kubernetes.server.ServerServiceBuilder in project che-server by eclipse-che.

the class AsyncStorageProvisioner method createStorageServiceIfNotExist.

/**
 * Create service for serving rsync connection
 */
private void createStorageServiceIfNotExist(KubernetesClient k8sClient, String namespace, String userId) {
    ServiceResource<Service> serviceResource = k8sClient.services().inNamespace(namespace).withName(ASYNC_STORAGE);
    if (serviceResource.get() != null) {
        // service already exist
        return;
    }
    ObjectMeta meta = new ObjectMeta();
    meta.setName(ASYNC_STORAGE);
    meta.setNamespace(namespace);
    meta.setLabels(of(CHE_USER_ID_LABEL, userId));
    IntOrString targetPort = new IntOrStringBuilder().withIntVal(SERVICE_PORT).withStrVal(valueOf(SERVICE_PORT)).build();
    ServicePort port = new ServicePortBuilder().withName("rsync-port").withProtocol("TCP").withPort(SERVICE_PORT).withTargetPort(targetPort).build();
    ServiceSpec spec = new ServiceSpec();
    spec.setPorts(singletonList(port));
    spec.setSelector(of(CHE_DEPLOYMENT_NAME_LABEL, ASYNC_STORAGE));
    ServerServiceBuilder serviceBuilder = new ServerServiceBuilder();
    Service service = serviceBuilder.withPorts(singletonList(port)).withSelectorEntry(CHE_DEPLOYMENT_NAME_LABEL, ASYNC_STORAGE).withName(ASYNC_STORAGE).build();
    k8sClient.services().inNamespace(namespace).create(service);
}
Also used : ObjectMeta(io.fabric8.kubernetes.api.model.ObjectMeta) ServicePort(io.fabric8.kubernetes.api.model.ServicePort) ServicePortBuilder(io.fabric8.kubernetes.api.model.ServicePortBuilder) IntOrString(io.fabric8.kubernetes.api.model.IntOrString) ServerServiceBuilder(org.eclipse.che.workspace.infrastructure.kubernetes.server.ServerServiceBuilder) ServiceSpec(io.fabric8.kubernetes.api.model.ServiceSpec) Service(io.fabric8.kubernetes.api.model.Service) IntOrStringBuilder(io.fabric8.kubernetes.api.model.IntOrStringBuilder)

Example 4 with ServerServiceBuilder

use of org.eclipse.che.workspace.infrastructure.kubernetes.server.ServerServiceBuilder in project devspaces-images by redhat-developer.

the class AbstractJwtProxyProvisioner method ensureJwtProxyInjected.

private void ensureJwtProxyInjected(KubernetesEnvironment k8sEnv, String machineName, PodData pod) throws InfrastructureException {
    if (!k8sEnv.getMachines().containsKey(JWT_PROXY_MACHINE_NAME)) {
        k8sEnv.getMachines().put(JWT_PROXY_MACHINE_NAME, createJwtProxyMachine());
        Pod jwtProxyPod = createJwtProxyPod();
        k8sEnv.addInjectablePod(machineName, JWT_PROXY_MACHINE_NAME, jwtProxyPod);
        Map<String, String> initConfigMapData = new HashMap<>();
        initConfigMapData.put(JWT_PROXY_PUBLIC_KEY_FILE, PUBLIC_KEY_HEADER + java.util.Base64.getEncoder().encodeToString(keyPair.getPublic().getEncoded()) + PUBLIC_KEY_FOOTER);
        initConfigMapData.put(JWT_PROXY_CONFIG_FILE, proxyConfigBuilder.build());
        ConfigMap jwtProxyConfigMap = new ConfigMapBuilder().withNewMetadata().withName(getConfigMapName()).endMetadata().withData(initConfigMapData).build();
        k8sEnv.getConfigMaps().put(jwtProxyConfigMap.getMetadata().getName(), jwtProxyConfigMap);
        Service jwtProxyService = new ServerServiceBuilder().withName(serviceName).withSelectorEntry(CHE_ORIGINAL_NAME_LABEL, pod.getMetadata().getName()).withMachineName(JWT_PROXY_MACHINE_NAME).withPorts(emptyList()).build();
        k8sEnv.getServices().put(jwtProxyService.getMetadata().getName(), jwtProxyService);
    }
}
Also used : Pod(io.fabric8.kubernetes.api.model.Pod) ConfigMap(io.fabric8.kubernetes.api.model.ConfigMap) HashMap(java.util.HashMap) ConfigMapBuilder(io.fabric8.kubernetes.api.model.ConfigMapBuilder) ServerServiceBuilder(org.eclipse.che.workspace.infrastructure.kubernetes.server.ServerServiceBuilder) Service(io.fabric8.kubernetes.api.model.Service)

Aggregations

Service (io.fabric8.kubernetes.api.model.Service)4 ServerServiceBuilder (org.eclipse.che.workspace.infrastructure.kubernetes.server.ServerServiceBuilder)4 ConfigMap (io.fabric8.kubernetes.api.model.ConfigMap)2 ConfigMapBuilder (io.fabric8.kubernetes.api.model.ConfigMapBuilder)2 IntOrString (io.fabric8.kubernetes.api.model.IntOrString)2 IntOrStringBuilder (io.fabric8.kubernetes.api.model.IntOrStringBuilder)2 ObjectMeta (io.fabric8.kubernetes.api.model.ObjectMeta)2 Pod (io.fabric8.kubernetes.api.model.Pod)2 ServicePort (io.fabric8.kubernetes.api.model.ServicePort)2 ServicePortBuilder (io.fabric8.kubernetes.api.model.ServicePortBuilder)2 ServiceSpec (io.fabric8.kubernetes.api.model.ServiceSpec)2 HashMap (java.util.HashMap)2