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);
}
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);
}
}
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);
}
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);
}
}
Aggregations