Search in sources :

Example 16 with Service

use of io.fabric8.kubernetes.api.model.Service in project che by eclipse.

the class OpenShiftConnector method inspectContainer.

@Override
public ContainerInfo inspectContainer(String containerId) throws IOException {
    Pod pod = getChePodByContainerId(containerId);
    if (pod == null) {
        LOG.warn("No Pod found by container ID {}", containerId);
        return null;
    }
    List<Container> podContainers = pod.getSpec().getContainers();
    if (podContainers.size() > 1) {
        throw new OpenShiftException("Multiple Containers found in Pod.");
    } else if (podContainers.size() < 1 || isNullOrEmpty(podContainers.get(0).getImage())) {
        throw new OpenShiftException(String.format("Container %s not found", containerId));
    }
    String podPullSpec = podContainers.get(0).getImage();
    String tagName = KubernetesStringUtils.getTagNameFromPullSpec(podPullSpec);
    ImageStreamTag tag = getImageStreamTagFromRepo(tagName);
    ImageInfo imageInfo = getImageInfoFromTag(tag);
    String deploymentName = pod.getMetadata().getLabels().get(OPENSHIFT_DEPLOYMENT_LABEL);
    if (deploymentName == null) {
        LOG.warn("No label {} found for Pod {}", OPENSHIFT_DEPLOYMENT_LABEL, pod.getMetadata().getName());
        return null;
    }
    Service svc = getCheServiceBySelector(OPENSHIFT_DEPLOYMENT_LABEL, deploymentName);
    if (svc == null) {
        LOG.warn("No Service found by selector {}={}", OPENSHIFT_DEPLOYMENT_LABEL, deploymentName);
        return null;
    }
    return createContainerInfo(svc, imageInfo, pod, containerId);
}
Also used : KubernetesContainer(org.eclipse.che.plugin.openshift.client.kubernetes.KubernetesContainer) Container(io.fabric8.kubernetes.api.model.Container) Pod(io.fabric8.kubernetes.api.model.Pod) OpenShiftException(org.eclipse.che.plugin.openshift.client.exception.OpenShiftException) ImageStreamTag(io.fabric8.openshift.api.model.ImageStreamTag) KubernetesService(org.eclipse.che.plugin.openshift.client.kubernetes.KubernetesService) Service(io.fabric8.kubernetes.api.model.Service) ImageInfo(org.eclipse.che.plugin.docker.client.json.ImageInfo)

Example 17 with Service

use of io.fabric8.kubernetes.api.model.Service in project camel by apache.

the class KubernetesServicesProducer method doListServiceByLabels.

protected void doListServiceByLabels(Exchange exchange, String operation) throws Exception {
    ServiceList servicesList = null;
    Map<String, String> labels = exchange.getIn().getHeader(KubernetesConstants.KUBERNETES_SERVICE_LABELS, Map.class);
    String namespaceName = exchange.getIn().getHeader(KubernetesConstants.KUBERNETES_NAMESPACE_NAME, String.class);
    if (!ObjectHelper.isEmpty(namespaceName)) {
        NonNamespaceOperation<Service, ServiceList, DoneableService, Resource<Service, DoneableService>> services;
        services = getEndpoint().getKubernetesClient().services().inNamespace(namespaceName);
        for (Map.Entry<String, String> entry : labels.entrySet()) {
            services.withLabel(entry.getKey(), entry.getValue());
        }
        servicesList = services.list();
    } else {
        MixedOperation<Service, ServiceList, DoneableService, Resource<Service, DoneableService>> services;
        services = getEndpoint().getKubernetesClient().services();
        for (Map.Entry<String, String> entry : labels.entrySet()) {
            services.withLabel(entry.getKey(), entry.getValue());
        }
        servicesList = services.list();
    }
    exchange.getOut().setBody(servicesList.getItems());
}
Also used : DoneableService(io.fabric8.kubernetes.api.model.DoneableService) ServiceList(io.fabric8.kubernetes.api.model.ServiceList) Resource(io.fabric8.kubernetes.client.dsl.Resource) DoneableService(io.fabric8.kubernetes.api.model.DoneableService) Service(io.fabric8.kubernetes.api.model.Service) Map(java.util.Map)

Example 18 with Service

use of io.fabric8.kubernetes.api.model.Service in project camel by apache.

the class KubernetesServicesProducer method doGetService.

protected void doGetService(Exchange exchange, String operation) throws Exception {
    Service service = null;
    String serviceName = exchange.getIn().getHeader(KubernetesConstants.KUBERNETES_SERVICE_NAME, String.class);
    String namespaceName = exchange.getIn().getHeader(KubernetesConstants.KUBERNETES_NAMESPACE_NAME, String.class);
    if (ObjectHelper.isEmpty(serviceName)) {
        LOG.error("Get a specific service require specify a service name");
        throw new IllegalArgumentException("Get a specific service require specify a service name");
    }
    if (ObjectHelper.isEmpty(namespaceName)) {
        LOG.error("Get a specific service require specify a namespace name");
        throw new IllegalArgumentException("Get a specific service require specify a namespace name");
    }
    service = getEndpoint().getKubernetesClient().services().inNamespace(namespaceName).withName(serviceName).get();
    exchange.getOut().setBody(service);
}
Also used : DoneableService(io.fabric8.kubernetes.api.model.DoneableService) Service(io.fabric8.kubernetes.api.model.Service)

Example 19 with Service

use of io.fabric8.kubernetes.api.model.Service in project camel by apache.

the class KubernetesServiceAccountsProducerTest method listTest.

@Test
public void listTest() throws Exception {
    if (ObjectHelper.isEmpty(authToken)) {
        return;
    }
    List<ServiceAccount> result = template.requestBody("direct:list", "", List.class);
    boolean fabric8Exists = false;
    Iterator<ServiceAccount> it = result.iterator();
    while (it.hasNext()) {
        ServiceAccount service = it.next();
        if ("fabric8".equalsIgnoreCase(service.getMetadata().getName())) {
            fabric8Exists = true;
        }
    }
    assertTrue(fabric8Exists);
}
Also used : ServiceAccount(io.fabric8.kubernetes.api.model.ServiceAccount) Test(org.junit.Test)

Aggregations

Service (io.fabric8.kubernetes.api.model.Service)14 HashMap (java.util.HashMap)7 ServicePort (io.fabric8.kubernetes.api.model.ServicePort)6 ArrayList (java.util.ArrayList)6 Map (java.util.Map)6 KubernetesService (org.eclipse.che.plugin.openshift.client.kubernetes.KubernetesService)6 Pod (io.fabric8.kubernetes.api.model.Pod)5 ServiceList (io.fabric8.kubernetes.api.model.ServiceList)5 List (java.util.List)5 OpenShiftException (org.eclipse.che.plugin.openshift.client.exception.OpenShiftException)5 Test (org.junit.Test)5 PodList (io.fabric8.kubernetes.api.model.PodList)4 ImageStreamTag (io.fabric8.openshift.api.model.ImageStreamTag)4 Exchange (org.apache.camel.Exchange)4 Processor (org.apache.camel.Processor)4 Container (io.fabric8.kubernetes.api.model.Container)3 DoneableService (io.fabric8.kubernetes.api.model.DoneableService)3 IntOrString (io.fabric8.kubernetes.api.model.IntOrString)3 ServiceAccount (io.fabric8.kubernetes.api.model.ServiceAccount)3 ServiceSpec (io.fabric8.kubernetes.api.model.ServiceSpec)3