Search in sources :

Example 1 with IntOrStringBuilder

use of io.fabric8.kubernetes.api.model.IntOrStringBuilder 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 IntOrStringBuilder

use of io.fabric8.kubernetes.api.model.IntOrStringBuilder 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)

Aggregations

IntOrString (io.fabric8.kubernetes.api.model.IntOrString)2 IntOrStringBuilder (io.fabric8.kubernetes.api.model.IntOrStringBuilder)2 ObjectMeta (io.fabric8.kubernetes.api.model.ObjectMeta)2 Service (io.fabric8.kubernetes.api.model.Service)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 ServerServiceBuilder (org.eclipse.che.workspace.infrastructure.kubernetes.server.ServerServiceBuilder)2