io.fabric8.kubernetes.api.model.LoadBalancerIngress Java Examples

The following examples show how to use io.fabric8.kubernetes.api.model.LoadBalancerIngress. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: KubernetesLoadBalancerWaiter.java    From ephemerals with MIT License 5 votes vote down vote up
@Override
protected boolean isConditionMet() {
    Service service = kubernetesClient.services().withName(deployment.getId()).get();
    List<LoadBalancerIngress> loadBalancerIngress = service.getStatus().getLoadBalancer().getIngress();
    if (loadBalancerIngress!=null && loadBalancerIngress.isEmpty()) {
        return false;
    }
    else {
        return true;
    }
}
 
Example #2
Source File: AbstractKafkaClient.java    From strimzi-kafka-operator with Apache License 2.0 5 votes vote down vote up
/**
 * Get external bootstrap connection
 * @param namespace kafka namespace
 * @param clusterName kafka cluster name
 * @return bootstrap url as string
 */
public static String getExternalBootstrapConnect(String namespace, String clusterName) {
    if (kubeClient(namespace).getClient().isAdaptable(OpenShiftClient.class)) {
        Route route = kubeClient(namespace).getClient().adapt(OpenShiftClient.class).routes().inNamespace(namespace).withName(clusterName + "-kafka-bootstrap").get();
        if (route != null && !route.getStatus().getIngress().isEmpty()) {
            return route.getStatus().getIngress().get(0).getHost() + ":443";
        }
    }

    Service extBootstrapService = kubeClient(namespace).getClient().services()
            .inNamespace(namespace)
            .withName(externalBootstrapServiceName(clusterName))
            .get();

    if (extBootstrapService == null) {
        throw new RuntimeException("Kafka cluster " + clusterName + " doesn't have an external bootstrap service");
    }

    String extBootstrapServiceType = extBootstrapService.getSpec().getType();

    if (extBootstrapServiceType.equals("NodePort")) {
        int port = extBootstrapService.getSpec().getPorts().get(0).getNodePort();
        String externalAddress = kubeClient(namespace).listNodes().get(0).getStatus().getAddresses().get(0).getAddress();
        return externalAddress + ":" + port;
    } else if (extBootstrapServiceType.equals("LoadBalancer")) {
        LoadBalancerIngress loadBalancerIngress = extBootstrapService.getStatus().getLoadBalancer().getIngress().get(0);
        String result = loadBalancerIngress.getHostname();

        if (result == null) {
            result = loadBalancerIngress.getIp();
        }
        return result + ":9094";
    } else {
        throw new RuntimeException("Unexpected external bootstrap service" + extBootstrapServiceType + " for Kafka cluster " + clusterName);
    }
}
 
Example #3
Source File: KubernetesClientTestBase.java    From flink with Apache License 2.0 5 votes vote down vote up
protected Service buildExternalServiceWithLoadBalancer(@Nullable String hostname, @Nullable String ip) {
	final ServicePort servicePort = new ServicePortBuilder()
		.withName(Constants.REST_PORT_NAME)
		.withPort(REST_PORT)
		.withNewTargetPort(REST_PORT)
		.build();
	final ServiceStatus serviceStatus = new ServiceStatusBuilder()
		.withLoadBalancer(new LoadBalancerStatus(Collections.singletonList(new LoadBalancerIngress(hostname, ip))))
		.build();

	return buildExternalService(
		KubernetesConfigOptions.ServiceExposedType.LoadBalancer,
		servicePort,
		serviceStatus);
}