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

The following examples show how to use io.fabric8.kubernetes.api.model.LoadBalancerStatus. 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: MockKubernetesServerSupport.java    From kogito-runtimes with Apache License 2.0 6 votes vote down vote up
protected void createMockService(final String serviceName, final String ip, final Map<String, String> labels, final String namespace) {
    final ServiceSpec serviceSpec = new ServiceSpec();
    serviceSpec.setPorts(Collections.singletonList(new ServicePort("http", 0, 8080, "http", new IntOrString(8080))));
    serviceSpec.setClusterIP(ip);
    serviceSpec.setType("ClusterIP");
    serviceSpec.setSessionAffinity("ClientIP");

    final ObjectMeta metadata = new ObjectMeta();
    metadata.setName(serviceName);
    metadata.setNamespace(MOCK_NAMESPACE);
    metadata.setLabels(labels);

    final Service service = new Service("v1", "Service", metadata, serviceSpec, new ServiceStatus(new LoadBalancerStatus()));
    if (namespace != null) {
        this.server.getClient().inNamespace(namespace).services().create(service);
    } else {
        this.server.getClient().services().create(service);
    }

}
 
Example #2
Source File: KubernetesDiscoveredServiceWorkItemHandlerTest.java    From kogito-runtimes with Apache License 2.0 6 votes vote down vote up
@Test
public void testGivenServiceExists() {
    final ServiceSpec serviceSpec = new ServiceSpec();
    serviceSpec.setPorts(Collections.singletonList(new ServicePort("http", 0, 8080, "http", new IntOrString(8080))));
    serviceSpec.setClusterIP("172.30.158.31");
    serviceSpec.setType("ClusterIP");
    serviceSpec.setSessionAffinity("ClientIP");

    final ObjectMeta metadata = new ObjectMeta();
    metadata.setName("test-kieserver");
    metadata.setNamespace(MOCK_NAMESPACE);
    metadata.setLabels(Collections.singletonMap("test-kieserver", "service"));

    final Service service = new Service("v1", "Service", metadata, serviceSpec, new ServiceStatus(new LoadBalancerStatus()));
    getClient().services().create(service);

    final DiscoveredServiceWorkItemHandler handler = new TestDiscoveredServiceWorkItemHandler(this);
    final ServiceInfo serviceInfo = handler.findEndpoint(MOCK_NAMESPACE, "test-kieserver");
    assertThat(serviceInfo, notNullValue());
    assertThat(serviceInfo.getUrl(), is("http://172.30.158.31:8080/test-kieserver"));
}
 
Example #3
Source File: Fabric8FlinkKubeClient.java    From flink with Apache License 2.0 6 votes vote down vote up
private Optional<Endpoint> getRestEndPointFromService(Service service, int restPort) {
	if (service.getStatus() == null) {
		return Optional.empty();
	}

	LoadBalancerStatus loadBalancer = service.getStatus().getLoadBalancer();
	boolean hasExternalIP = service.getSpec() != null &&
		service.getSpec().getExternalIPs() != null && !service.getSpec().getExternalIPs().isEmpty();

	if (loadBalancer != null) {
		return getLoadBalancerRestEndpoint(loadBalancer, restPort);
	} else if (hasExternalIP) {
		final String address = service.getSpec().getExternalIPs().get(0);
		if (address != null && !address.isEmpty()) {
			return Optional.of(new Endpoint(address, restPort));
		}
	}
	return Optional.empty();
}
 
Example #4
Source File: Fabric8FlinkKubeClient.java    From flink with Apache License 2.0 6 votes vote down vote up
private Optional<Endpoint> getLoadBalancerRestEndpoint(LoadBalancerStatus loadBalancer, int restPort) {
	boolean hasIngress = loadBalancer.getIngress() != null && !loadBalancer.getIngress().isEmpty();
	String address;
	if (hasIngress) {
		address = loadBalancer.getIngress().get(0).getIp();
		// Use hostname when the ip address is null
		if (address == null || address.isEmpty()) {
			address = loadBalancer.getIngress().get(0).getHostname();
		}
	} else {
		// Use node port
		address = this.internalClient.getMasterUrl().getHost();
	}
	boolean noAddress = address == null || address.isEmpty();
	return noAddress ? Optional.empty() : Optional.of(new Endpoint(address, restPort));
}
 
Example #5
Source File: KubernetesClientTestBase.java    From flink with Apache License 2.0 6 votes vote down vote up
protected Service buildExternalServiceWithNodePort() {
	final ServicePort servicePort = new ServicePortBuilder()
		.withName(Constants.REST_PORT_NAME)
		.withPort(REST_PORT)
		.withNodePort(NODE_PORT)
		.withNewTargetPort(REST_PORT)
		.build();

	final ServiceStatus serviceStatus = new ServiceStatusBuilder()
		.withLoadBalancer(new LoadBalancerStatus(Collections.emptyList()))
		.build();

	return buildExternalService(
		KubernetesConfigOptions.ServiceExposedType.NodePort,
		servicePort,
		serviceStatus);
}
 
Example #6
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);
}