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

The following examples show how to use io.fabric8.kubernetes.api.model.ServiceStatus. 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: 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 #4
Source File: KubernetesClientTestBase.java    From flink with Apache License 2.0 6 votes vote down vote up
private Service buildExternalService(
		KubernetesConfigOptions.ServiceExposedType serviceExposedType,
		ServicePort servicePort,
		@Nullable ServiceStatus serviceStatus) {
	final ServiceBuilder serviceBuilder = new ServiceBuilder()
		.editOrNewMetadata()
			.withName(ExternalServiceDecorator.getExternalServiceName(CLUSTER_ID))
			.endMetadata()
		.editOrNewSpec()
			.withType(serviceExposedType.name())
			.addNewPortLike(servicePort)
				.endPort()
			.endSpec();

	if (serviceStatus != null) {
		serviceBuilder.withStatus(serviceStatus);
	}

	return serviceBuilder.build();
}
 
Example #5
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);
}