Search in sources :

Example 1 with DoneableService

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

Aggregations

DoneableService (io.fabric8.kubernetes.api.model.DoneableService)1 Service (io.fabric8.kubernetes.api.model.Service)1 ServiceList (io.fabric8.kubernetes.api.model.ServiceList)1 Resource (io.fabric8.kubernetes.client.dsl.Resource)1 Map (java.util.Map)1