use of io.fabric8.kubernetes.api.model.ServiceList in project camel by apache.
the class KubernetesServicesProducer method doList.
protected void doList(Exchange exchange, String operation) throws Exception {
ServiceList servicesList = null;
String namespaceName = exchange.getIn().getHeader(KubernetesConstants.KUBERNETES_NAMESPACE_NAME, String.class);
if (!ObjectHelper.isEmpty(namespaceName)) {
servicesList = getEndpoint().getKubernetesClient().services().inNamespace(namespaceName).list();
} else {
servicesList = getEndpoint().getKubernetesClient().services().list();
}
exchange.getOut().setBody(servicesList.getItems());
}
use of io.fabric8.kubernetes.api.model.ServiceList in project che by eclipse.
the class OpenShiftConnector method getCheServiceBySelector.
private Service getCheServiceBySelector(String selectorKey, String selectorValue) {
ServiceList svcs = openShiftClient.services().inNamespace(this.openShiftCheProjectName).list();
Service svc = svcs.getItems().stream().filter(s -> s.getSpec().getSelector().containsKey(selectorKey)).filter(s -> s.getSpec().getSelector().get(selectorKey).equals(selectorValue)).findAny().orElse(null);
if (svc == null) {
LOG.warn("No Service with selector {}={} could be found", selectorKey, selectorValue);
}
return svc;
}
use of io.fabric8.kubernetes.api.model.ServiceList in project che by eclipse.
the class OpenShiftConnector method inspectNetwork.
@Override
public Network inspectNetwork(InspectNetworkParams params) throws IOException {
String netId = params.getNetworkId();
ServiceList services = openShiftClient.services().inNamespace(this.openShiftCheProjectName).list();
Map<String, ContainerInNetwork> containers = new HashMap<>();
for (Service svc : services.getItems()) {
String selector = svc.getSpec().getSelector().get(OPENSHIFT_DEPLOYMENT_LABEL);
if (selector == null || !selector.startsWith(CHE_OPENSHIFT_RESOURCES_PREFIX)) {
continue;
}
PodList pods = openShiftClient.pods().inNamespace(openShiftCheProjectName).withLabel(OPENSHIFT_DEPLOYMENT_LABEL, selector).list();
for (Pod pod : pods.getItems()) {
String podName = pod.getMetadata().getName();
ContainerInNetwork container = new ContainerInNetwork().withName(podName).withIPv4Address(svc.getSpec().getClusterIP());
String podId = KubernetesStringUtils.getLabelFromContainerID(pod.getMetadata().getLabels().get(CHE_CONTAINER_IDENTIFIER_LABEL_KEY));
if (podId == null) {
continue;
}
containers.put(podId, container);
}
}
List<IpamConfig> ipamConfig = new ArrayList<>();
Ipam ipam = new Ipam().withDriver("bridge").withOptions(Collections.emptyMap()).withConfig(ipamConfig);
return new Network().withName("OpenShift").withId(netId).withContainers(containers).withLabels(Collections.emptyMap()).withOptions(Collections.emptyMap()).withDriver("default").withIPAM(ipam).withScope("local").withInternal(false).withEnableIPv6(false);
}
use of io.fabric8.kubernetes.api.model.ServiceList 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());
}
Aggregations